class Sablon::HTMLConverter::TableCell
Converts html table cells into wordML table cells
Constants
- CHILD_TAGS
Permitted child tags defined by the OpenXML spec
- PROPERTIES
Public Class Methods
new(env, node, properties)
click to toggle source
Calls superclass method
Sablon::HTMLConverter::Node::new
# File lib/sablon/html/ast.rb, line 403 def initialize(env, node, properties) super properties = self.class.process_properties(properties) @properties = NodeProperties.table_cell(properties) # # Nodes are processed first "as is" and then based on the XML # generated wrapped by paragraphs. trans_props = transferred_properties @children = ASTBuilder.html_to_ast(env, node.children, trans_props) @children = wrap_with_paragraphs(env, @children) end
Public Instance Methods
accept(visitor)
click to toggle source
Calls superclass method
Sablon::HTMLConverter::Node#accept
# File lib/sablon/html/ast.rb, line 419 def accept(visitor) super @children.accept(visitor) end
inspect()
click to toggle source
# File lib/sablon/html/ast.rb, line 424 def inspect "<TableCell{#{@properties.inspect}}: #{@children.inspect}>" end
to_docx()
click to toggle source
Calls superclass method
Sablon::HTMLConverter::Node#to_docx
# File lib/sablon/html/ast.rb, line 415 def to_docx super('w:tc') end
Private Instance Methods
children_to_docx()
click to toggle source
# File lib/sablon/html/ast.rb, line 473 def children_to_docx @children.to_docx end
new_paragraph(env)
click to toggle source
Creates a new Paragraph
AST node, with no children
# File lib/sablon/html/ast.rb, line 468 def new_paragraph(env) para = Nokogiri::HTML.fragment('<p></p>').first_element_child ASTBuilder.html_to_ast(env, [para], transferred_properties).first end
wrap_with_paragraphs(env, nodes)
click to toggle source
Wraps nodes in Paragraph
AST nodes if needed to produced a valid document
# File lib/sablon/html/ast.rb, line 432 def wrap_with_paragraphs(env, nodes) # convert all nodes to live xml, and use first node to determine # if that AST node should be wrapped in a paragraph nodes_xml = nodes.map { |n| Nokogiri::XML.fragment(n.to_docx) } # para = nil new_nodes = [] nodes_xml.each_with_index do |n, i| next unless n.children.first # add all nodes that need wrapped to a paragraph sequentially. # New paragraphs are created when something that doesn't need # wrapped is encountered to retain proper content ordering. first_node_name = n.children.first.node_name if wrapped_by_paragraph.include? first_node_name if para.nil? para = new_paragraph(env) new_nodes << para end para.runs << nodes[i] else new_nodes << nodes[i] para = nil end end # Ensure the table cell has an empty paragraph if nothing else new_nodes << new_paragraph(env) if new_nodes.empty? # filter nils and return Collection.new(new_nodes.compact) end
wrapped_by_paragraph()
click to toggle source
Returns a list of child tags that need to be wrapped in a paragraph
# File lib/sablon/html/ast.rb, line 463 def wrapped_by_paragraph Paragraph::CHILD_TAGS - self.class::CHILD_TAGS end