Class: Kitchen::Directions::BakeChapterReferences::V1

Inherits:
Object
  • Object
show all
Defined in:
lib/kitchen/directions/bake_chapter_references/v1.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
# File 'lib/kitchen/directions/bake_chapter_references/v1.rb', line 5

def bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'references')
  chapter.pages.each do |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_references(page:) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/kitchen/directions/bake_chapter_references/v1.rb', line 23

def bake_page_references(page:)
  return if page.nil?

  references = page.references
  return if references.none?

  title = if page.is_introduction?
            <<~HTML
              <a href="##{page.title.id}">
                <h3 data-type="document-title" id="#{page.title.copied_id}">
                  <span class="os-text" data-type="" itemprop="">#{page.title_text}</span>
                </h3>
              </a>
            HTML
          else
            Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)
          end

  references.each do |reference|
    Kitchen::Directions::RemoveSectionTitle.v1(section: reference)
    reference.prepend(child: title)
  end
end