Class: Kitchen::Directions::MoveSolutionsFromExerciseSection::V1

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/move_solutions_to_answer_key/move_solutions_from_exercise_section.rb

Instance Method Summary collapse

Instance Method Details

#bake(within:, append_to:, section_class:, title_number:, options:) ⇒ Object



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kitchen/directions/move_solutions_to_answer_key/move_solutions_from_exercise_section.rb', line 17

def bake(within:, append_to:, section_class:, title_number:, options:)
  solutions_clipboard = \
    if within.instance_of?(Kitchen::SectionElement)
      within.solutions.cut
    else
      within.search("section.#{section_class}").solutions.cut
    end

  return if solutions_clipboard.items.empty?

  if options[:add_title]
    title_text = \
      if title_number
        I18n.t(:"eoc.#{section_class}", number: title_number)
      elsif options[:in_appendix]
        I18n.t(:"appendix_sections.#{section_class}")
      else
        I18n.t(:"eoc.#{section_class}")
      end

    title = <<~HTML
      <h3 data-type="title">
        <span class="os-title-label">#{title_text}</span>
      </h3>
    HTML

    append_to.append(child:
      Kitchen::Directions::SolutionAreaSnippet.v1(
        title: title, solutions_clipboard: solutions_clipboard
      )
    )
  else
    append_to.append(child: solutions_clipboard.paste)
  end
end