Class: HtmlToCss

Inherits:
Object
  • Object
show all
Defined in:
lib/html-to-css.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(s = nil, rand_color: true, file: nil) ⇒ HtmlToCss

Returns a new instance of HtmlToCss.



33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
# File 'lib/html-to-css.rb', line 33

def initialize(s=nil, rand_color: true, file: nil)

  @rand_color = rand_color

  if s then
    @doc = Rexle.new s
  elsif file

    @doc = Rexle.new File.read(file)

  else

    a = Dir.glob("*.html")
    @doc = Rexle.new File.read(a.pop)
    a.each {|f| merge(@doc, Rexle.new(File.read(f)).root ) }
  end

  @selectors = []
  @nocss = i(head script)
  @nolayoutcss = ['ul>li>a', 'ul>li>ul', 'p>a', 'div>div>\w+', 'article']
  @css = []

  @elements = {
    a:    "background-color: :color; ",
    body: "background-color: :color;
           align: center;",
    div:  "background-color: :color;",
    h1:   "background-color: :color; 
           color: #fff;
           font-family: Verdana, Arial, Helvetica, sans-serif; 
           font-size: 1.3em;",
    h2:   "background-color: :color; 
           color: #fff;
           font-family: Verdana, Arial, Helvetica, sans-serif; 
           font-size: 1.3em;",
    html: "background-color: :color;",
    li:   "background-color: :color;",
    p:    "background-color: :color;",
    ul:   "background-color: :color;",
    article: "background-color: :color;",
    section: "background-color: :color;",
    footer:  "background-color: :color;"
  }
  
end

Instance Attribute Details

#elementsObject

Returns the value of attribute elements.



31
32
33
# File 'lib/html-to-css.rb', line 31

def elements
  @elements
end

Instance Method Details

#to_cssObject



79
80
81
# File 'lib/html-to-css.rb', line 79

def to_css()
  apply_css
end

#to_layoutObject



83
84
85
86
87
88
# File 'lib/html-to-css.rb', line 83

def to_layout()

  css = apply_css(:layout) {|doc| select_layout_elements(doc) }
  @layout_selectors = @selectors.clone
  css
end

#to_styleObject



90
91
92
# File 'lib/html-to-css.rb', line 90

def to_style()
  apply_css :style
end