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:, options:) ⇒ 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
40
41
42
43
44
45
46
# File 'lib/kitchen/directions/bake_notes/bake_numbered_notes/v3.rb', line 7

def bake(book:, classes:, options:)
  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

      # Store label information
      note.target_label(custom_content: "#{note.autogenerated_title} #{os_number}")

      note.exercises.each do |exercise|
        BakeNoteExercise.v1(
          note: note,
          exercise: exercise,
          divider: '. ',
          suppress_solution: options[: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 options[:suppress_solution]
    end
  end
end