class Kitchen::Directions::BakeChapterGlossary::V1

Public Instance Methods

bake(chapter:, metadata_source:, append_to: nil, uuid_prefix: '', has_para: false) click to toggle source
# File lib/kitchen/directions/bake_chapter_glossary/v1.rb, line 24
def bake(chapter:, metadata_source:, append_to: nil, uuid_prefix: '', has_para: false)
  @glossary = []

  # Use for books created by Adaptarr, where dd contains paragraphs
  # More info: https://github.com/openstax/kitchen/issues/284
  if has_para
    chapter.glossaries.search('dd').each do |description|
      description_content = description.first('p').text
      description.replace_children with: description_content
    end
  end

  chapter.glossaries.search('dl').each do |definition_element|
    @glossary.push(Definition.new(definition_element.cut))
  end

  chapter.glossaries.trash

  content = @glossary.sort.map { |definition| definition.element.paste }.join

  Kitchen::Directions::EocCompositePageContainer.v1(
    container_key: 'glossary',
    uuid_key: "#{uuid_prefix}glossary",
    metadata_source: metadata_source,
    content: content,
    append_to: append_to || chapter
  )
end