Sha256: 807e00170c12abbd8ccfbadbae647f3b5f0d1d34c058b5909d0c499512474710

Contents?: true

Size: 1.32 KB

Versions: 2

Compression:

Stored size: 1.32 KB

Contents

# frozen_string_literal: true

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

        chapter.search('.section-exercises').each do |section|
          section_solutions = section.search('[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('.review-exercises').each do |section|
          section_solutions = section.search('[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

2 entries across 2 versions & 1 rubygems

Version Path
openstax_kitchen-3.2.0 lib/kitchen/directions/bake_chapter_answer_key/strategies/calculus.rb
openstax_kitchen-3.1.0 lib/kitchen/directions/bake_chapter_answer_key/strategies/calculus.rb