Sha256: d5b2b5a0d1ebf26e68b60cf1bed482ab81274de4edfb8340bbff25cbc8b8bcb9

Contents?: true

Size: 1.59 KB

Versions: 5

Compression:

Stored size: 1.59 KB

Contents

# frozen_string_literal: true

module Kitchen::Directions::MoveExercisesToEOC
  # The difference from v1 is the presence of a section title
  # and from v2 the lack of additional "os-section-area" and os-#{@klass} wrappers
  class V3
    renderable

    def bake(chapter:, metadata_source:, klass:, append_to: nil, uuid_prefix: '.')
      @klass = klass
      @metadata = metadata_source.children_to_keep.copy
      @title = I18n.t(:"eoc.#{klass}")
      @uuid_prefix = uuid_prefix

      exercise_clipboard = Kitchen::Clipboard.new

      chapter.non_introduction_pages.each do |page|
        sections = page.search("section.#{@klass}")

        sections.each do |exercise_section|
          exercise_section.first("[data-type='title']")&.trash

          section_title = Kitchen::Directions::EocSectionTitleLinkSnippet.v1(page: page)

          exercise_section.exercises.each do |exercise|
            exercise.document.pantry(name: :link_text).store(
              "#{I18n.t(:exercise_label)} #{chapter.count_in(:book)}.#{exercise.count_in(:chapter)}",
              label: exercise.id
            )
          end

          # Configure section title
          exercise_section.prepend(child: section_title)
          exercise_section.cut(to: exercise_clipboard)
        end
      end

      return if exercise_clipboard.none?

      @content = exercise_clipboard.paste

      append_to_element = append_to || chapter
      @in_composite_chapter = append_to_element.is?(:composite_chapter)

      append_to_element.append(child: render(file:
        '../../templates/eoc_section_title_template.xhtml.erb'))
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
openstax_kitchen-8.0.1 lib/kitchen/directions/move_exercises_to_eoc/v3.rb
openstax_kitchen-8.0.0 lib/kitchen/directions/move_exercises_to_eoc/v3.rb
openstax_kitchen-7.0.0 lib/kitchen/directions/move_exercises_to_eoc/v3.rb
openstax_kitchen-6.1.0 lib/kitchen/directions/move_exercises_to_eoc/v3.rb
openstax_kitchen-6.0.0 lib/kitchen/directions/move_exercises_to_eoc/v3.rb