Sha256: afc9b3846e0d92a479d9d1eeb300350eb3262a7e77277b46875442fdfbd2d82d

Contents?: true

Size: 1.18 KB

Versions: 5

Compression:

Stored size: 1.18 KB

Contents

# frozen_string_literal: true

module Kitchen
  module Directions
    # Bake directions for eoc summary
    #
    module BakeChapterSummary
      def self.v1(chapter:, metadata_source:, klass: 'summary', uuid_prefix: '.')
        V1.new.bake(
          chapter: chapter,
          metadata_source: metadata_source,
          uuid_prefix: uuid_prefix,
          klass: klass
        )
      end

      class V1
        def bake(chapter:, metadata_source:, uuid_prefix: '.', klass: 'summary')
          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: metadata_source,
            content: summaries.paste,
            append_to: chapter
          )
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
openstax_kitchen-17.0.0 lib/kitchen/directions/bake_chapter_summary.rb
openstax_kitchen-16.0.0 lib/kitchen/directions/bake_chapter_summary.rb
openstax_kitchen-15.0.0 lib/kitchen/directions/bake_chapter_summary.rb
openstax_kitchen-14.0.0 lib/kitchen/directions/bake_chapter_summary.rb
openstax_kitchen-13.0.0 lib/kitchen/directions/bake_chapter_summary.rb