Sha256: d393d1e4a0fb1059634e6bec45a10f100eb36fd262c139ffdad57f763ce3767d

Contents?: true

Size: 1.36 KB

Versions: 12

Compression:

Stored size: 1.36 KB

Contents

# frozen_string_literal: true

module Kitchen::Directions::BakeChapterIntroductions
  class BakeChapterObjectives
    def bake(chapter:, strategy:)
      case strategy
      when :default
        bake_as_note(chapter: chapter)
      when :add_objectives
        add_chapter_objectives(chapter: chapter)
      when :none
        ''
      else
        raise 'No such strategy'
      end
    end

    def bake_as_note(chapter:)
      chapter_objectives_note = chapter.notes('$.chapter-objectives').first

      return unless chapter_objectives_note.present?

      # trash existing title
      chapter_objectives_note.titles.first&.trash
      Kitchen::Directions::BakeAutotitledNotes.v1(
        book: chapter,
        classes: %w[chapter-objectives],
        bake_subtitle: false
      )

      chapter_objectives_note.cut.paste
    end

    def add_chapter_objectives(chapter:)
      chapter.non_introduction_pages.map do |page|
        <<~HTML
          <div class="os-chapter-objective">
            <a class="os-chapter-objective" href="##{page.title[:id]}">
              <span class="os-number">#{chapter.count_in(:book)}.#{page.count_in(:chapter)}</span>
              <span class="os-divider"> </span>
              <span data-type="" itemprop="" class="os-text">#{page.title.children[0].text}</span>
            </a>
          </div>
        HTML
      end.join('')
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
openstax_kitchen-19.0.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-18.0.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-17.1.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-17.0.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-16.0.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-15.0.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-14.0.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-13.0.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-12.2.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-12.1.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-12.0.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb
openstax_kitchen-11.2.0 lib/kitchen/directions/bake_chapter_introductions/bake_chapter_objectives.rb