Sha256: b0ba0e6c4fc69a9984c58352650ff766813c37be4da91756bee4f893a8565ea3

Contents?: true

Size: 837 Bytes

Versions: 30

Compression:

Stored size: 837 Bytes

Contents

# frozen_string_literal: true

@solution2 = Kitchen::BookRecipe.new do |doc|
  book = doc.book

  # Solution 1 treats figures and tables almost identically and ends up duplicating
  # a lot of code.  To DRY up that code, pull out the parts that change (the search
  # enumerator and the label):

  enumerators_to_labels_map = {
    book.tables => 'Table',
    book.figures => 'Figure'
  }

  enumerators_to_labels_map.each do |enumerator, label|
    enumerator.each do |element|
      name = "#{label} #{element.count_in(:book)}"
      element.prepend(child: "<div class='caption'>#{name}</div>")
      doc.pantry(name: :link_text).store name, label: element.id
    end
  end

  book.search('a.needs-label').each do |anchor|
    id = anchor[:href][1..-1]
    anchor.replace_children(with: doc.pantry(name: :link_text).get(id))
  end
end

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
openstax_kitchen-19.0.0 tutorials/04/solution2.rb
openstax_kitchen-18.0.0 tutorials/04/solution2.rb
openstax_kitchen-17.1.0 tutorials/04/solution2.rb
openstax_kitchen-17.0.0 tutorials/04/solution2.rb
openstax_kitchen-16.0.0 tutorials/04/solution2.rb
openstax_kitchen-15.0.0 tutorials/04/solution2.rb
openstax_kitchen-14.0.0 tutorials/04/solution2.rb
openstax_kitchen-13.0.0 tutorials/04/solution2.rb
openstax_kitchen-12.2.0 tutorials/04/solution2.rb
openstax_kitchen-12.1.0 tutorials/04/solution2.rb
openstax_kitchen-12.0.0 tutorials/04/solution2.rb
openstax_kitchen-11.2.0 tutorials/04/solution2.rb
openstax_kitchen-11.1.0 tutorials/04/solution2.rb
openstax_kitchen-11.0.0 tutorials/04/solution2.rb
openstax_kitchen-10.0.0 tutorials/04/solution2.rb
openstax_kitchen-9.2.0 tutorials/04/solution2.rb
openstax_kitchen-9.1.0 tutorials/04/solution2.rb
openstax_kitchen-9.0.0 tutorials/04/solution2.rb
openstax_kitchen-8.0.1 tutorials/04/solution2.rb
openstax_kitchen-8.0.0 tutorials/04/solution2.rb