Class: Kitchen::Directions::BakeNumberedNotes::V1

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

Instance Method Summary collapse

Instance Method Details

#bake(book:, classes:, cases: false) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/kitchen/directions/bake_notes/bake_numbered_notes/v1.rb', line 6

def bake(book:, classes:, cases: false)
  classes.each do |klass|
    book.chapters.pages.notes("$.#{klass}").each do |note|
      bake_note(note: note, cases: cases)
      note.exercises.each do |exercise|
        BakeNoteExercise.v1(note: note, exercise: exercise)
      end
      note.injected_questions.each do |question|
        BakeNoteInjectedQuestion.v1(note: note, question: question)
      end
    end
  end
end

#bake_note(note:, cases: false) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
# File 'lib/kitchen/directions/bake_notes/bake_numbered_notes/v1.rb', line 20

def bake_note(note:, cases: false)
  note.wrap_children(class: 'os-note-body')

  chapter_count = note.ancestor(:chapter).count_in(:book)
  note_count = note.count_in(:chapter)
  note.prepend(child:
    <<~HTML
      <h3 class="os-title">
        <span class="os-title-label">#{note.autogenerated_title}</span>
        <span class="os-number">#{chapter_count}.#{note_count}</span>
        <span class="os-divider"> </span>
      </h3>
    HTML
  )

  return unless note['use-subtitle']

  BakeNoteSubtitle.v1(note: note, cases: cases)
end