Class: DocTemplate::Tables::Target
- Defined in:
- lib/doc_template/tables/target.rb
Constant Summary collapse
- HEADER_LABEL_PIECE =
'Long-Term Targets Addressed'
- TEMPLATE =
'target-table.html.erb'
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Instance Method Summary collapse
Methods inherited from Base
#collect_and_render_tags, #fetch_materials, #initialize, parse, #parse_in_context, #table_exist?
Constructor Details
This class inherits a constructor from DocTemplate::Tables::Base
Instance Method Details
#parse(fragment, *_args) ⇒ Object
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/doc_template/tables/target.rb', line 9 def parse(fragment, *_args) path = ".//table/*/tr[1]/td[1][case_insensitive_contains(.//*/text(), '#{HEADER_LABEL_PIECE}')]" return unless (element = fragment.at_xpath path, XpathFunctions.new) return unless (table = element.ancestors('table').first) @target_data = fetch table template = File.read DocTemplate::Tags::BaseTag.template_path_for(TEMPLATE) content = ERB.new(template).result(binding).squish content = DocTemplate::Document.parse Nokogiri::HTML.fragment(content) # remove next element if it's empty paragraph # (quick fix before refactoring at https://github.com/learningtapestry/unbounded/issues/780) el_next = table.next_element el_next.remove if el_next&.name == 'p' && el_next.content.blank? table.replace content&.render content end |