senny / sablon

Ruby Document Template Processor based on docx templates and Mail Merge fields.
MIT License
446 stars 128 forks source link

Adding html (un)ordered list raises undefined method exception #125

Closed arvanasse closed 5 years ago

arvanasse commented 5 years ago

I'm attempting to add html content to a document that includes a simple list. The html content looks like this:

<h1>Components</h1>

<h2>Cisco Catalyst 9500 (x2.00)</h2>

<ul>
<li><p>Create base Multicast configuration based on planning and design</p></li>
<li><p>Create base static routing configuration based on planning and design</p></li>
<li><p>Create base QoS configuration based on existing QoS policies</p></li>
<li><p>Create base routing protocol redistribution configuration based on planning and design</p></li>
<li><p>Create base BGP configuration based on planning and design</p></li>
<li><p>Create base QoS configuration based on planning and design</p></li>
<li><p>Create base ACL configuration based on planning and design</p></li>
<li><p>Create base FHRP configuration based on planning and design</p></li>
<li><p>Create base Layer 3 interface configurations based on planning and design</p></li>
<li><p>Create base dynamic routing protocol configuration based on planning and design</p></li>
<li><p>Create base global STP and VLAN configurations based on planning and design</p></li>
<li><p>Create base DAI configuration based on planning and design</p></li>
<li><p>Create base DHCP snooping configuration based on planning and design</p></li>
<li><p>Create base global StackWise Virtual configurations based on planning and design</p></li>
</ul>

<h2>Meraki MS410-16 (x2.00)</h2>

I've tried both ordered lists and unordered lists. Both thrown an exception with the same trace:

sablon (0.3.1) lib/sablon/document_object_model/numbering.rb:15:in `block (2 levels) in extend_model'
sablon (0.3.1) lib/sablon/html/ast.rb:214:in `initialize'
sablon (0.3.1) lib/sablon/html/ast_builder.rb:52:in `new'
sablon (0.3.1) lib/sablon/html/ast_builder.rb:52:in `block in process_nodes'
nokogiri (1.10.1) lib/nokogiri/xml/node_set.rb:238:in `block in each'
nokogiri (1.10.1) lib/nokogiri/xml/node_set.rb:237:in `upto'
nokogiri (1.10.1) lib/nokogiri/xml/node_set.rb:237:in `each'
sablon (0.3.1) lib/sablon/html/ast_builder.rb:38:in `flat_map'
sablon (0.3.1) lib/sablon/html/ast_builder.rb:38:in `process_nodes'
sablon (0.3.1) lib/sablon/html/ast_builder.rb:33:in `initialize'
sablon (0.3.1) lib/sablon/html/ast_builder.rb:8:in `new'
sablon (0.3.1) lib/sablon/html/ast_builder.rb:8:in `html_to_ast'
sablon (0.3.1) lib/sablon/html/ast.rb:140:in `initialize'
sablon (0.3.1) lib/sablon/html/converter.rb:19:in `new'
sablon (0.3.1) lib/sablon/html/converter.rb:19:in `build_ast'
sablon (0.3.1) lib/sablon/html/converter.rb:12:in `processed_ast'
sablon (0.3.1) lib/sablon/html/converter.rb:8:in `process'
sablon (0.3.1) lib/sablon/content.rb:170:in `append_to'
sablon (0.3.1) lib/sablon/parser/mail_merge.rb:35:in `replace_field_display'
sablon (0.3.1) lib/sablon/parser/mail_merge.rb:56:in `replace'
sablon (0.3.1) lib/sablon/operations.rb:7:in `evaluate'
sablon (0.3.1) lib/sablon/processor/document.rb:75:in `block in manipulate'
sablon (0.3.1) lib/sablon/processor/document.rb:74:in `each'
sablon (0.3.1) lib/sablon/processor/document.rb:74:in `manipulate'
sablon (0.3.1) lib/sablon/processor/document.rb:61:in `process'
sablon (0.3.1) lib/sablon/template.rb:75:in `block (2 levels) in process'
sablon (0.3.1) lib/sablon/template.rb:75:in `each'
sablon (0.3.1) lib/sablon/template.rb:75:in `block in process'
sablon (0.3.1) lib/sablon/template.rb:72:in `each'
sablon (0.3.1) lib/sablon/template.rb:72:in `process'
sablon (0.3.1) lib/sablon/template.rb:61:in `render'
sablon (0.3.1) lib/sablon/template.rb:49:in `render_to_string'
sablon (0.3.1) lib/sablon/template.rb:43:in `block in render_to_file'
sablon (0.3.1) lib/sablon/template.rb:42:in `open'
sablon (0.3.1) lib/sablon/template.rb:42:in `render_to_file'

I've done some limited debugging around the line in question:

define_method(:add_list_definition) do |style|
  @dom['word/numbering.xml'].add_list_definition(style)
end

Only to find that @dom is nil.

This has occurred with v0.3.1 of the gem (ruby 2.5.1p57)

arvanasse commented 5 years ago

Just found that this is a duplicate of #102

Amnesthesia commented 2 months ago

@arvanasse did you manage to solve this? I'm getting this when using Sablon.content(:html, ...) if the html contains lists