Class: SpreadsheetBuilder::CssParser

Inherits:
Object
  • Object
show all
Defined in:
lib/spreadsheet_builder/css_parser.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(load_paths = []) ⇒ CssParser

Returns a new instance of CssParser.



28
29
30
31
32
# File 'lib/spreadsheet_builder/css_parser.rb', line 28

def initialize(load_paths = [])
  @load_paths = load_paths

  reset
end

Instance Attribute Details

#cacheObject (readonly)

Returns the value of attribute cache.



25
26
27
# File 'lib/spreadsheet_builder/css_parser.rb', line 25

def cache
  @cache
end

#load_pathsObject

Returns the value of attribute load_paths.



26
27
28
# File 'lib/spreadsheet_builder/css_parser.rb', line 26

def load_paths
  @load_paths
end

#rulesObject (readonly)

Returns the value of attribute rules.



25
26
27
# File 'lib/spreadsheet_builder/css_parser.rb', line 25

def rules
  @rules
end

Class Method Details

.pt_from_input(val, base = :width) ⇒ Object



21
22
23
# File 'lib/spreadsheet_builder/css_parser.rb', line 21

def self.pt_from_input(val, base = :width)
  px_from_input(val, base) * 12 / 16
end

.px_from_input(val, base = :width) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
# File 'lib/spreadsheet_builder/css_parser.rb', line 4

def self.px_from_input(val, base = :width)
  case val
  when /%$/
    val.to_f / 100 * { width: 1024, height: 16 }[base]
  when /px$/
    val.to_f
  when /cm$/
    val.to_f * 37.795275591
  when /em$/
    val.to_f * 16
  when /pt$/
    val.to_f * 16 / 12
  else 
    nil
  end
end

Instance Method Details

#format_from_node(node) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/spreadsheet_builder/css_parser.rb', line 40

def format_from_node(node)
  formats = []
  formats << format_from_klass_tree(klass_tree_from_node(node), node)

  if node.attributes["style"]
    declarations = node.attributes["style"].value.split(';').map { |line| 
      k, v = line.split(':')
      [k, { value: v }]
    }
    formats << format_from_declarations(declarations, node)
  end

  formats.inject(&:merge)
end

#reset(level = :parser) ⇒ Object



34
35
36
37
38
# File 'lib/spreadsheet_builder/css_parser.rb', line 34

def reset(level = :parser)
  method = "reset_#{level}"

  __send__(method)
end