Class: Kitchen::Directions::BakeFreeResponse::V1

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_free_response/v1.rb

Instance Method Summary collapse

Instance Method Details

#bake(chapter:, metadata_source:, append_to:) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/kitchen/directions/bake_free_response/v1.rb', line 7

def bake(chapter:, metadata_source:, append_to:)
  @metadata_elements = .children_to_keep.copy

  @free_response_clipboard = Kitchen::Clipboard.new
  chapter.pages.each do |page|
    free_response_questions = page.free_response
    next if free_response_questions.none?

    free_response_questions.search('h3')&.first&.trash
    title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
    free_response_questions.each do |free_response_question|
      free_response_question.prepend(child: title)
      free_response_question.cut(to: @free_response_clipboard)
    end
  end

  return if @free_response_clipboard.none?

  append_to_element = append_to || chapter
  @title_tag = append_to ? 'h3' : 'h2'

  append_to_element.append(child: render(file: 'free_response.xhtml.erb'))
end