Sha256: f8b41b3fe67c42bbbe43cdbf553004099d0167043e0b21a6a49674f22263bb8f

Contents?: true

Size: 1.02 KB

Versions: 10

Compression:

Stored size: 1.02 KB

Contents

# frozen_string_literal: true

module Kitchen
  module Directions
    # Bake directions for link placeholders
    #
    module BakeLinkPlaceholders
      def self.v1(book:, cases: false)
        book.search('a').each do |anchor|
          next unless anchor.text == '[link]'

          label_case = anchor['cmlnle:case']
          id = anchor[:href][1..-1]

          if cases
            pantry_name = if anchor.key?('case')
                            "#{label_case}_link_text"
                          else
                            'nominative_link_text'
                          end

            replacement = book.pantry(name: pantry_name).get(id)
          else
            replacement = book.pantry(name: :link_text).get(id)
          end

          if replacement.present?
            anchor.replace_children(with: replacement)
          else
            # TODO: log a warning!
            puts "warning! could not find a replacement for '[link]' on an element with ID '#{id}'"
          end
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
openstax_kitchen-17.0.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-16.0.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-15.0.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-14.0.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-13.0.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-12.2.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-12.1.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-12.0.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-11.2.0 lib/kitchen/directions/bake_link_placeholders.rb
openstax_kitchen-11.1.0 lib/kitchen/directions/bake_link_placeholders.rb