Class: Kitchen::Directions::BakeChapterReferences::V2

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_chapter_references/v2.rb

Instance Method Summary collapse

Instance Method Details

#bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'references') ⇒ Object



5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/kitchen/directions/bake_chapter_references/v2.rb', line 5

def bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'references')
  chapter.pages.each do |page|
    bake_page_cite(page: page)
    bake_page_references(page: page)
  end

  return if chapter.pages.references.none?

  content = chapter.pages.references.cut.paste

  Kitchen::Directions::CompositePageContainer.v1(
    container_key: klass,
    uuid_key: "#{uuid_prefix}#{klass}",
    metadata_source: ,
    content: content,
    append_to: chapter
  )
end

#bake_page_cite(page:) ⇒ Object



24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/kitchen/directions/bake_chapter_references/v2.rb', line 24

def bake_page_cite(page:)
  page.search('[data-type="cite"]').each do |link|
    link.id = "#{page.id}-endNote#{link.count_in(:chapter)}"

    link.prepend(child:
      <<~HTML
        <sup class="os-end-note-number">#{link.count_in(:chapter)}</sup>
      HTML
    )

    link.search('.delete-me').trash
  end
end

#bake_page_references(page:) ⇒ Object



38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/kitchen/directions/bake_chapter_references/v2.rb', line 38

def bake_page_references(page:)
  page.references.each do |reference|
    Kitchen::Directions::RemoveSectionTitle.v1(section: reference)

    reference.search('a').each do |ref_link|
      ref_link.replace_children(with:
        <<~HTML
          <span>#{ref_link.count_in(:chapter)}.</span>
        HTML
      )
      ref_link.href = "##{page.id}-endNote#{ref_link.count_in(:chapter)}"
    end
  end
end