Class: HtmlToCss

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

Instance Method Summary collapse

Constructor Details

#initialize(filename = nil) ⇒ HtmlToCss

Returns a new instance of HtmlToCss.



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/html-to-css.rb', line 16

def initialize(filename=nil)

  if filename then

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

  else

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

  @selectors = []
  @nocss = ['head', 'ul li ul', 'p a', 'div div \w+']
  @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;"
  }
end

Instance Method Details

#to_cssObject



53
54
55
56
# File 'lib/html-to-css.rb', line 53

def to_css()
  scan_to_css @doc.root
  @css.join "\n"
end

#to_layoutObject



58
59
60
61
# File 'lib/html-to-css.rb', line 58

def to_layout()
  select_layout_elements()
  to_css()
end