Sha256: cb9d0191c55a21cd55bb1cbd7978d1e180dff9511f87593d48eec7a390fc6dfa

Contents?: true

Size: 1.3 KB

Versions: 2

Compression:

Stored size: 1.3 KB

Contents

# frozen_string_literal: true

module Kitchen::Directions::BakeChapterReferences
  class V1
    def bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'references')
      chapter.pages.each do |page|
        bake_page_references(page: page)
      end

      content = chapter.pages.references.cut.paste

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

    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
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
openstax_kitchen-11.1.0 lib/kitchen/directions/bake_chapter_references/v1.rb
openstax_kitchen-11.0.0 lib/kitchen/directions/bake_chapter_references/v1.rb