Module: Kitchen::Directions::BakeLinkPlaceholders
- Defined in:
- lib/kitchen/directions/bake_link_placeholders.rb
Overview
Bake directions for link placeholders
Class Method Summary collapse
Class Method Details
.v1(book:, cases: false) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/kitchen/directions/bake_link_placeholders.rb', line 8 def self.v1(book:, cases: false) book.search('a').each do |anchor| next unless anchor.text == '[link]' label_case = anchor['cmlnle:case'] || anchor['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 |