Sha256: d88b0816662a0beb8dc3707957952979685321bcf094ff36818230fb52b24535

Contents?: true

Size: 1.58 KB

Versions: 7

Compression:

Stored size: 1.58 KB

Contents

# frozen_string_literal: true

module Kitchen
  module Directions
    module BakeNoteExercise
      def self.v1(note:, exercise:, divider: ' ', suppress_solution: false)
        exercise.add_class('unnumbered')
        number = note.first('.os-number').text.gsub(/#/, '')

        # bake problem
        exercise.problem.wrap_children('div', class: 'os-problem-container')
        exercise.search('[data-type="commentary"]').each(&:trash)
        return unless exercise.solution

        # bake solution in place
        if suppress_solution
          exercise.add_class('os-hasSolution')
          exercise.solution.trash
        else
          BakeNumberedExercise.bake_solution_v1(
            exercise: exercise,
            number: number,
            divider: divider
          )
        end
      end

      def self.v2(note:)
        note.exercises.each do |exercise|
          exercise.problem.wrap_children('div', class: 'os-problem-container')

          unless exercise.has_class?('unnumbered')
            exercise.problem.prepend(child:
              <<~HTML
                <span class="os-title-label">#{I18n.t(:"exercises.exercise")} </span>
                <span class="os-number">#{exercise.count_in(:note)}</span>
              HTML
            )
          end

          next unless exercise.solution

          exercise.solution.wrap_children('div', class: 'os-solution-container')

          exercise.solution.prepend(child:
            <<~HTML
              <span class="os-title-label">#{I18n.t(:"exercises.solution")}</span>
            HTML
          )
        end
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
openstax_kitchen-19.0.0 lib/kitchen/directions/bake_notes/bake_note_exercise.rb
openstax_kitchen-18.0.0 lib/kitchen/directions/bake_notes/bake_note_exercise.rb
openstax_kitchen-17.1.0 lib/kitchen/directions/bake_notes/bake_note_exercise.rb
openstax_kitchen-17.0.0 lib/kitchen/directions/bake_notes/bake_note_exercise.rb
openstax_kitchen-16.0.0 lib/kitchen/directions/bake_notes/bake_note_exercise.rb
openstax_kitchen-15.0.0 lib/kitchen/directions/bake_notes/bake_note_exercise.rb
openstax_kitchen-14.0.0 lib/kitchen/directions/bake_notes/bake_note_exercise.rb