Class: Kitchen::Directions::BakeNumberedNotes::V3

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_notes/bake_numbered_notes/v3.rb

Instance Method Summary collapse

Instance Method Details

#bake(book:, classes:, suppress_solution: true) ⇒ Object

for the try it notes, must be called AFTER bake_exercises



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/kitchen/directions/bake_notes/bake_numbered_notes/v3.rb', line 7

def bake(book:, classes:, suppress_solution: true)
  classes.each do |klass|
    book.chapters.pages.notes("$.#{klass}").each do |note|
      note.wrap_children(class: 'os-note-body')
      previous_example = note.previous
      until previous_example.nil? || previous_example[:'data-type'] == 'example'
        previous_example = previous_example.previous
      end
      os_number = previous_example&.first('.os-number')&.children&.to_s

      note.prepend(child:
        <<~HTML
          <h3 class="os-title">
            <span class="os-title-label">#{note.autogenerated_title}</span>
            <span class="os-number">#{os_number}</span>
          </h3>
        HTML
      )

      note.title&.trash
      note.exercises.each do |exercise|
        BakeNoteExercise.v1(
          note: note, exercise: exercise, divider: '. ', suppress_solution: suppress_solution
        )
      end
      note.injected_questions.each do |question|
        BakeNoteInjectedQuestion.v1(note: note, question: question)
      end

      note.search("div[data-type='solution']").each&.trash if suppress_solution
    end
  end
end