Sha256: 2d0b5d9af9350ac86e243c7c26d6553fc74fdc747444c02c17950059422e4118

Contents?: true

Size: 1.35 KB

Versions: 5

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Kitchen::Directions::MoveSolutionsToAnswerKey
  module Strategies
    class Calculus
      def bake(chapter:, append_to:)
        checkpoint_solutions = chapter.search('div.checkpoint div[data-type="solution"]').cut
        append_solution_area(I18n.t(:checkpoint), checkpoint_solutions, append_to)

        chapter.search('section.section-exercises').each do |section|
          section_solutions = section.search('div[data-type="solution"]').cut
          section_title = I18n.t(
            :section_exercises,
            number: "#{chapter.count_in(:book)}.#{section.count_in(:chapter)}"
          )
          append_solution_area(section_title, section_solutions, append_to)
        end

        chapter.search('section.review-exercises').each do |section|
          section_solutions = section.search('div[data-type="solution"]').cut
          append_solution_area(I18n.t(:review_exercises), section_solutions, append_to)
        end
      end

      protected

      def append_solution_area(title, clipboard, append_to)
        append_to.add_child(
          <<~HTML
            <div class="os-solution-area">
              <h3 data-type="title">
                <span class="os-title-label">#{title}</span>
              </h3>
              #{clipboard.paste}
            </div>
          HTML
        )
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
openstax_kitchen-10.0.0 lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb
openstax_kitchen-9.2.0 lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb
openstax_kitchen-9.1.0 lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb
openstax_kitchen-9.0.0 lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb
openstax_kitchen-8.0.1 lib/kitchen/directions/move_solutions_to_answer_key/strategies/calculus.rb