Class: Kitchen::Directions::BakeChapterSummary::V1

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

Instance Method Summary collapse

Instance Method Details

#bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'summary', append_to: nil) ⇒ Object



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_chapter_summary.rb', line 19

def bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'summary', append_to: nil)
  summaries = Clipboard.new

  chapter.pages.each do |page|
    summary = page.summary

    next if summary.nil?

    summary.first("[data-type='title']")&.trash # get rid of old title if exists
    title = EocSectionTitleLinkSnippet.v1(page: page)
    summary.prepend(child: title)
    summary.cut(to: summaries)
  end

  return if summaries.none?

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