Sha256: fd5d4cf15f6c7c49130505510b501842704af1168b0da16f45ca2528912389fa

Contents?: true

Size: 1.67 KB

Versions: 3

Compression:

Stored size: 1.67 KB

Contents

# frozen_string_literal: true

module Kitchen::Directions::MoveSolutionsToAnswerKey
  class V1
    # rubocop:disable Metrics/ParameterLists
    # This direction may need refactoring to simplify parameters
    def bake(chapter:, metadata_source:, strategy:, append_to:, strategy_options: {},
             solutions_plural: true)
      strategy =
        case strategy
        when :calculus
          Strategies::Calculus.new
        when :contemporary_math
          Strategies::ContemporaryMath.new
        when :uphysics
          Strategies::UPhysics.new
        when :precalculus
          Strategies::Precalculus.new
        when :default
          Strategies::Default.new(strategy_options)
        else
          raise 'No such strategy'
        end

      solutions_or_solution = solutions_plural ? 'solutions' : 'solution'
      uuid_key = ".#{solutions_or_solution}#{chapter.count_in(:book)}"
      append_to.append(child:
        <<~HTML
          <div class="os-eob os-#{solutions_or_solution}-container" data-type="composite-page" \
          data-uuid-key="#{uuid_key}">
            <h2 data-type="document-title">
              <span class="os-text">#{I18n.t(:chapter)} #{chapter.count_in(:book)}</span>
            </h2>
            <div data-type="metadata" style="display: none;">
              <h1 data-type="document-title" itemprop="name">#{I18n.t(:chapter)} #{chapter.count_in(:book)}</h1>
              #{metadata_source.children_to_keep.copy.paste}
            </div>
          </div>
        HTML
      )
      strategy.bake(
        chapter: chapter, append_to: append_to.first("div[data-uuid-key='#{uuid_key}']")
      )
    end
    # rubocop:enable Metrics/ParameterLists
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
openstax_kitchen-14.0.0 lib/kitchen/directions/move_solutions_to_answer_key/v1.rb
openstax_kitchen-13.0.0 lib/kitchen/directions/move_solutions_to_answer_key/v1.rb
openstax_kitchen-12.2.0 lib/kitchen/directions/move_solutions_to_answer_key/v1.rb