Class: Sablon::HTMLConverter::Table
Overview
Builds a table from html table tags
Constant Summary collapse
- PROPERTIES =
%w[jc shd tblBorders tblCaption tblCellMar tblCellSpacing tblInd tblLayout tblLook tblOverlap tblpPr tblStyle tblStyleColBandSize tblStyleRowBandSize tblW].freeze
Instance Method Summary collapse
- #accept(visitor) ⇒ Object
-
#initialize(env, node, properties) ⇒ Table
constructor
A new instance of Table.
- #inspect ⇒ Object
- #to_docx ⇒ Object
Methods inherited from Node
convert_style_property, node_name, process_properties, style_conversion
Constructor Details
#initialize(env, node, properties) ⇒ Table
Returns a new instance of Table.
295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 |
# File 'lib/sablon/html/ast.rb', line 295 def initialize(env, node, properties) super # Process properties properties = self.class.process_properties(properties) @properties = NodeProperties.table(properties) trans_props = transferred_properties # Pull out the caption node if it exists and convert it separately. # If multiple caption tags are defined, only the first one is kept. @caption = node.xpath('./caption').remove @caption = nil if @caption.empty? if @caption cap_side_pat = /caption-side: ?(top|bottom)/ @cap_side = @caption.attr('style').to_s.match(cap_side_pat).to_a[1] node.add_previous_sibling @caption @caption = ASTBuilder.html_to_ast(env, @caption, trans_props)[0] end # convert remaining child nodes and pass on transferrable properties @children = ASTBuilder.html_to_ast(env, node.children, trans_props) @children = Collection.new(@children) end |
Instance Method Details
#accept(visitor) ⇒ Object
330 331 332 333 |
# File 'lib/sablon/html/ast.rb', line 330 def accept(visitor) super @children.accept(visitor) end |
#inspect ⇒ Object
335 336 337 338 339 340 341 342 343 |
# File 'lib/sablon/html/ast.rb', line 335 def inspect if @caption && @cap_side == 'bottom' "<Table{#{@properties.inspect}}: #{@children.inspect}, #{@caption.inspect}>" elsif @caption "<Table{#{@properties.inspect}}: #{@caption.inspect}, #{@children.inspect}>" else "<Table{#{@properties.inspect}}: #{@children.inspect}>" end end |
#to_docx ⇒ Object
319 320 321 322 323 324 325 326 327 328 |
# File 'lib/sablon/html/ast.rb', line 319 def to_docx if @caption && @cap_side == 'bottom' super('w:tbl') + @caption.to_docx elsif @caption # caption always goes above table unless explicitly set to "bottom" @caption.to_docx + super('w:tbl') else super('w:tbl') end end |