Sha256: 7e52d40c4a561a1535d7f715e5cfecb0bc305b5a3667202de52da19ddc018dd3

Contents?: true

Size: 963 Bytes

Versions: 8

Compression:

Stored size: 963 Bytes

Contents

# frozen_string_literal: true

module Kitchen::Directions::BakeChapterSolutions
  class V1
    def bake(chapter:, metadata_source:, uuid_prefix: '', classes: %w[free-response])
      solutions_clipboard = Kitchen::Clipboard.new

      classes.each do |klass|
        chapter.search("section.#{klass}").each do |question|
          exercises = question.exercises
          # must run AFTER the other sections are baked

          next if exercises.none?

          exercises.each do |exercise|
            solution = exercise.solution
            next unless solution.present?

            solution.cut(to: solutions_clipboard)
          end
        end
      end

      content = solutions_clipboard.paste

      Kitchen::Directions::CompositePageContainer.v1(
        container_key: 'solutions',
        uuid_key: "#{uuid_prefix}solutions",
        metadata_source: metadata_source,
        content: content,
        append_to: chapter
      )
    end
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

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