Class: Kitchen::Directions::BakeReferences::V4

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_references/v4.rb

Instance Method Summary collapse

Instance Method Details

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



5
6
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
# File 'lib/kitchen/directions/bake_references/v4.rb', line 5

def bake(book:, metadata_source:, cases: false)
  book.chapters.each do |chapter|

    chapter.references.search('h3').trash

    chapter_references = chapter.pages.references.cut
    chapter_title_text = chapter.title.search('.os-text')
    introduction_page = chapter.introduction_page

    next if chapter_references.items.empty?

    chapter.append(child:
      <<~HTML
        <div class="os-chapter-area">
          <a href="##{introduction_page.id}_titlecreatedbycookbook">
            <h2 data-type="document-title" data-rex-keep="true">
              <span class="os-part-text">#{I18n.t("chapter#{'.nominative' if cases}")} </span>
              <span class="os-number">#{chapter.count_in(:book)}</span>
              <span class="os-divider"> </span>
              #{chapter_title_text}
            </h2>
          </a>
          #{chapter_references.paste}
        </div>
      HTML
    )
  end

  chapter_area_references = book.chapters.search('.os-chapter-area').cut

  Kitchen::Directions::CompositePageContainer.v1(
    container_key: 'references',
    uuid_key: '.references',
    metadata_source: ,
    content: chapter_area_references.paste,
    append_to: book.body
  )
end