Class: Kitchen::Directions::BakeChapterIntroductions::BakeChapterObjectives

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb

Instance Method Summary collapse

Instance Method Details

#add_chapter_objectives(chapter:) ⇒ Object



34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb', line 34

def add_chapter_objectives(chapter:)
  chapter.non_introduction_pages.map do |page|
    <<~HTML
      <div class="os-chapter-objective">
        <a class="os-chapter-objective" href="##{page.title[:id]}">
          <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
          <span class="os-divider"> </span>
          <span data-type="" itemprop="" class="os-text">#{page.title.children[0].text}</span>
        </a>
      </div>
    HTML
  end.join('')
end

#bake(chapter:, strategy:) ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb', line 5

def bake(chapter:, strategy:)
  case strategy
  when :default
    bake_as_note(chapter: chapter)
  when :add_objectives
    add_chapter_objectives(chapter: chapter)
  when :none
    ''
  else
    raise 'No such strategy'
  end
end

#bake_as_note(chapter:) ⇒ Object



18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb', line 18

def bake_as_note(chapter:)
  chapter_objectives_note = chapter.notes('$.chapter-objectives').first

  return unless chapter_objectives_note.present?

  # trash existing title
  chapter_objectives_note.titles.first&.trash
  Kitchen::Directions::BakeAutotitledNotes.v1(
    book: chapter,
    classes: %w[chapter-objectives],
    bake_subtitle: false
  )

  chapter_objectives_note.cut.paste
end