Sha256: 6359bf5f737e17ee3f57dbcd74013c2d27e6bcf254ec2e41da6b980a5a7a9087

Contents?: true

Size: 1.56 KB

Versions: 8

Compression:

Stored size: 1.56 KB

Contents

# frozen_string_literal: true

module Kitchen
  module Directions
    module BakeLearningObjectives
      def self.v1(chapter:)
        chapter.abstracts.each do |abstract|
          abstract.prepend(child: "<h3 data-type='title'>#{I18n.t(:learning_objectives)}</h3>")
        end
      end

      def self.v2(chapter:, add_title: true)
        learning_objectives =
          chapter.abstracts.any? ? chapter.abstracts : chapter.learning_objectives

        learning_objectives.each do |abstract|
          if add_title
            abstract.prepend(child: "<h3 data-type='title'>#{I18n.t(:learning_objectives)}</h3>")
          end

          ul = abstract.first!('ul')
          ul.add_class('os-abstract')
          ul.search('li').each_with_index do |li, index|
            li.replace_children(with:
              <<~HTML
                <span class="os-abstract-token">#{chapter.count_in(:book)}.#{abstract.count_in(:chapter)}.#{index + 1}</span>
                <span class="os-abstract-content">#{li.children}</span>
              HTML
            )
          end
        end
      end

      # Wraps & moves abstract under the corresponding chapter objective in the intro page
      def self.v3(chapter:)
        abstracts = chapter.abstracts.map do |abstract|
          abstract.wrap('<div class="learning-objective">')
          abstract.parent
        end

        chapter.introduction_page.search('div.os-chapter-objective') \
               .each_with_index do |objective, index|
          objective.append(child: abstracts[index].cut.paste)
        end
      end
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
openstax_kitchen-19.0.0 lib/kitchen/directions/bake_learning_objectives.rb
openstax_kitchen-18.0.0 lib/kitchen/directions/bake_learning_objectives.rb
openstax_kitchen-17.1.0 lib/kitchen/directions/bake_learning_objectives.rb
openstax_kitchen-17.0.0 lib/kitchen/directions/bake_learning_objectives.rb
openstax_kitchen-16.0.0 lib/kitchen/directions/bake_learning_objectives.rb
openstax_kitchen-15.0.0 lib/kitchen/directions/bake_learning_objectives.rb
openstax_kitchen-14.0.0 lib/kitchen/directions/bake_learning_objectives.rb
openstax_kitchen-13.0.0 lib/kitchen/directions/bake_learning_objectives.rb