Sha256: 8e86a39e70d94f3acacdf5564e368bd0bc634a27b76b2eafa4536565adad8fc8

Contents?: true

Size: 1019 Bytes

Versions: 9

Compression:

Stored size: 1019 Bytes

Contents

# frozen_string_literal: true

module Kitchen::Directions::MoveExercisesToEOC
  class V1
    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

          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

9 entries across 9 versions & 1 rubygems

Version Path
openstax_kitchen-8.0.1 lib/kitchen/directions/move_exercises_to_eoc/v1.rb
openstax_kitchen-8.0.0 lib/kitchen/directions/move_exercises_to_eoc/v1.rb
openstax_kitchen-7.0.0 lib/kitchen/directions/move_exercises_to_eoc/v1.rb
openstax_kitchen-6.1.0 lib/kitchen/directions/move_exercises_to_eoc/v1.rb
openstax_kitchen-6.0.0 lib/kitchen/directions/move_exercises_to_eoc/v1.rb
openstax_kitchen-5.0.0 lib/kitchen/directions/move_exercises_to_eoc/v1.rb
openstax_kitchen-4.1.1 lib/kitchen/directions/move_exercises_to_eoc/v1.rb
openstax_kitchen-4.1.0 lib/kitchen/directions/move_exercises_to_eoc/v1.rb
openstax_kitchen-4.0.0 lib/kitchen/directions/move_exercises_to_eoc/v1.rb