Sha256: 18857837f6e3ad3eb1615a182ebae7d3ca9f78afbc6d18508d3cff69e9932a7a

Contents?: true

Size: 1.04 KB

Versions: 12

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module Kitchen
  module Directions
    module BakeEquations
      def self.v1(book:, number_decorator: :none)
        book.chapters.search('div[data-type="equation"]:not(.unnumbered)').each do |eq|
          chapter = eq.ancestor(:chapter)
          number = "#{chapter.count_in(:book)}.#{eq.count_in(:chapter)}"

          # Store label information
          equation_label = "#{I18n.t(:equation)} #{number}"
          book.pantry(name: :link_text).store equation_label, label: eq.id

          decorated_number =
            case number_decorator
            when :none
              number
            when :parentheses
              "(#{number})"
            else
              raise "Unsupported number_decorator '#{number_decorator}'"
            end

          # Bake the equation
          eq.append(child:
            <<~HTML
              <div class="os-equation-number">
                <span class="os-number">#{decorated_number}</span>
              </div>
            HTML
          )
        end
      end
    end
  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
openstax_kitchen-11.0.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-10.0.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-9.2.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-9.1.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-9.0.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-8.0.1 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-8.0.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-7.0.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-6.1.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-6.0.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-5.0.0 lib/kitchen/directions/bake_equations.rb
openstax_kitchen-4.1.1 lib/kitchen/directions/bake_equations.rb