Class: ODFWriter::Parser::Default

Inherits:
Object
  • Object
show all
Defined in:
lib/odf_writer/parser/default.rb

Overview

Default: html parser and code translator

Constant Summary collapse

INLINE =

constants

%w(     a      span      strong      b      em      i      ins      u      del      strike      sub      sup     code)
TEXTINLINE =
%w(text:a text:span text:strong text:b text:em text:i text:ins text:u text:del text:strike text:sub text:sup text:code)
UNSAFETAGS =

SAFETAGS = %w(h1 h2 h3 h4 h5 h6 p a br div span strong b em i ins u del strike sub sup code li ul ol th td tr tbody thead tfoot table )

%w(script style)
TABLECLASSES =

table: blank (white) cells, no borders, bold face,

thrifty blank (white) cells, no borders, normal face,

tiny blank (white) cells, no borders, tiny face,

listmedium blank (white) cells, header rows bottom borders, medium face , footer rows top-borders

list: blank (white) cells, header rows bottom borders, normal face, , footer rows top-borders boxes: blank (white) cells, all borders, normal face invoice: blank (white) cells, header rows bottom borders, header rows bold face, footer rows top-borders caption: blank (white) cells, bold face

tc: column width tcs: first column width and last column width

%w(table thrifty tiny list listmedium boxes invoice caption)
TABLESTYLES =
{:table        => {:thead => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]} }, 
                  :tbody => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]} }, 
                  :tfoot => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]} }, 
                  
                  :tcs => ["tc", "tc", "tc"]
                 },
                 
:thrifty      => {:thead => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]} }, 
                  :tbody => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]} }, 
                  :tfoot => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["p", "p", "p"]} }, 
                  
                  :tcs => ["tc", "tc", "tc"]
                 },
                 
:tiny         => {:thead => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["small", "small", "small"],    :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["small", "small", "small"],    :ps => ["p", "p", "p"]} }, 
                  :tbody => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["small", "small", "small"],    :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["small", "small", "small"],    :ps => ["p", "p", "p"]} }, 
                  :tfoot => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["small", "small", "small"],    :ps => ["p", "p", "p"]},                            :tds => {:tds => ["td", "td", "td"],             :fs => ["small", "small", "small"],    :ps => ["p", "p", "p"]} }, 
                  
                  :tcs => ["tc", "tc", "tc"]
                 },
                 
:list         => {:thead => {:tr => "tr", :ths =>{:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["", "", ""],                   :ps => ["monoright", "mono", "mono"]},              :tds => {:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["", "", ""],                   :ps => ["right", "p", "p"]} }, 
                  :tbody => {:tr => "tr", :ths =>{:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["", "", ""],                   :ps => ["monoright", "mono", "mono"]},              :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["right", "p", "p"]} }, 
                  :tfoot => {:tr => "tr", :ths =>{:tds => ["tdfoot", "tdfoot", "tdfoot"], :fs => ["", "", ""],                   :ps => ["monoright", "mono", "mono"]},              :tds => {:tds => ["tdfoot", "tdfoot", "tdfoot"], :fs => ["", "", ""],                   :ps => ["right", "p", "p"]} }, 
                                
                  :tcs => ["tcnarrow", "tcfixed", "tcfixed"]
                 },
                 
:listmedium   => {:thead => {:tr => "tr", :ths =>{:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["medium", "medium", "medium"], :ps => ["monoright", "mono", "mono"]},              :tds => {:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["medium", "medium", "medium"], :ps => ["right", "p", "p"]} }, 
                  :tbody => {:tr => "tr", :ths =>{:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["medium", "medium", "medium"], :ps => ["monoright", "mono", "mono"]},              :tds => {:tds => ["td", "td", "td"],             :fs => ["medium", "medium", "medium"], :ps => ["right", "p", "p"]} }, 
                  :tfoot => {:tr => "tr", :ths =>{:tds => ["tdfoot", "tdfoot", "tdfoot"], :fs => ["medium", "medium", "medium"], :ps => ["monoright", "mono", "mono"]},              :tds => {:tds => ["tdfoot", "tdfoot", "tdfoot"], :fs => ["medium", "medium", "medium"], :ps => ["right", "p", "p"]} }, 
                                
                  :tcs => ["tcnarrow", "tcfixed", "tcfixed"]
                 },
                 
:boxes        => {:thead => {:tr => "tr", :ths =>{:tds => ["tdbox", "tdbox", "tdbox"],    :fs => ["", "", ""],                   :ps => ["monocenter", "monocenter", "monocenter"]}, :tds => {:tds => ["tdbox", "tdbox", "tdbox"],    :fs => ["", "", ""],                   :ps => ["center", "center", "center"]} }, 
                  :tbody => {:tr => "tr", :ths =>{:tds => ["tdbox", "tdbox", "tdbox"],    :fs => ["", "", ""],                   :ps => ["monocenter", "monocenter", "monocenter"]}, :tds => {:tds => ["tdbox", "tdbox", "tdbox"],    :fs => ["", "", ""],                   :ps => ["center", "center", "center"]} }, 
                  :tfoot => {:tr => "tr", :ths =>{:tds => ["tdbox", "tdbox", "tdbox"],    :fs => ["", "", ""],                   :ps => ["monocenter", "monocenter", "monocenter"]}, :tds => {:tds => ["tdbox", "tdbox", "tdbox"],    :fs => ["", "", ""],                   :ps => ["center", "center", "center"]} }, 
                  
                  :tcs => ["tc", "tc", "tc"]
                 },
                 
:invoice      => {:thead => {:tr => "tr", :ths =>{:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["medium", "medium", "medium"], :ps => ["mono",    "monoright", "monoright" ]},     :tds => {:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["medium", "medium", "medium"], :ps => ["p", "right", "right" ]} }, 
                  :tbody => {:tr => "tr", :ths =>{:tds => ["tdhead", "tdhead", "tdhead"], :fs => ["medium", "medium", "medium"], :ps => ["mono",    "monoright", "monoright" ]},     :tds => {:tds => ["td", "td", "td"],             :fs => ["medium", "medium", "medium"], :ps => ["p", "right", "right" ]} }, 
                  :tfoot => {:tr => "tr", :ths =>{:tds => ["tdfoot", "tdfoot", "tdfoot"], :fs => ["medium", "medium", "medium"], :ps => ["mono",    "monoright", "monoright" ]},     :tds => {:tds => ["tdfoot", "tdfoot", "tdfoot"], :fs => ["medium", "medium", "medium"], :ps => ["p", "right", "right" ]} }, 
                  
                  :tcs => ["tcwide", "tcnarrow", "tcnarrow"]
                 },
                 
:caption      => {:thead => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["mono", "mono", "mono"]},                   :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["mono", "mono", "mono"]} }, 
                  :tbody => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["mono", "mono", "mono"]},                   :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["mono", "mono", "mono"]} }, 
                  :tfoot => {:tr => "tr", :ths =>{:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["mono", "mono", "mono"]},                   :tds => {:tds => ["td", "td", "td"],             :fs => ["", "", ""],                   :ps => ["mono", "mono", "mono"]} }, 
                  
                  :tcs => ["tcnarrow", "tcwide", "tcwide"]
                 }
}

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(text, node, opts = {}) ⇒ Default

initialize



121
122
123
124
125
126
127
128
129
130
131
132
133
# File 'lib/odf_writer/parser/default.rb', line 121

def initialize(text, node, opts={})
  @text                = text
  @paragraphs          = []
  @template_node       = node
  @doc                 = opts[:doc]
  @remove_classes      = opts[:remove_classes]
  @remove_class_prefix = opts[:remove_class_prefix]
  @remove_class_suffix = opts[:remove_class_suffix]
  
  @styles              = opts[:styles]
  
  parse
end

Instance Attribute Details

#paragraphsObject

Returns the value of attribute paragraphs.



32
33
34
# File 'lib/odf_writer/parser/default.rb', line 32

def paragraphs
  @paragraphs
end

Instance Method Details

#parseObject

parse



140
141
142
143
144
145
146
147
# File 'lib/odf_writer/parser/default.rb', line 140

def parse

  #xml = @template_node.parse("<html>#{@text}</html>")
  xml = "<html>#{@text}</html>"
  odf = parse_formatting(xml).css("html").inner_html
  @paragraphs << odf
  return
end