Class: CssBuilder

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

Instance Method Summary collapse

Constructor Details

#initializeCssBuilder

Returns a new instance of CssBuilder.



3
4
5
# File 'lib/css_builder.rb', line 3

def initialize
  @css = ''
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(m, *args, &block) ⇒ Object

the magic



60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/css_builder.rb', line 60

def method_missing(m, *args, &block)

  if block
    _start_tag(m, *args, &block)
  else
    _indent
    css! _dasherize m
    css! " : #{args.first};"
    _newline
  end
 
  @css
end

Instance Method Details

#class!(*args, &block) ⇒ Object



23
24
25
26
# File 'lib/css_builder.rb', line 23

def class!(*args, &block)
  _start_tag(_class(args[0]), *args[1..-1], &block)
  @css
end

#comment!(comment) ⇒ Object



11
12
13
14
15
16
# File 'lib/css_builder.rb', line 11

def comment!(comment)
  css! "/* #{comment} */"
  _newline
  _newline
  @css
end

#id!(*args, &block) ⇒ Object



18
19
20
21
# File 'lib/css_builder.rb', line 18

def id!(*args, &block)
  _start_tag("##{args[0]}", *args[1..-1], &block)
  @css
end

#mixin!(name, *args, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
# File 'lib/css_builder.rb', line 40

def mixin!(name, *args, &block)
  css! _class(name)
  _args_param_values(args)
  if block
    _open
    _newline 

    self.instance_eval(&block)

    _close
    _newline
  else
    css! ";"
  end
  _newline
  @css
end

#value!Object



7
8
9
# File 'lib/css_builder.rb', line 7

def value!
  @css
end

#variable!(name, value = nil) ⇒ Object

enventaully move all LESS specific stuff to another file



30
31
32
33
34
35
36
37
38
# File 'lib/css_builder.rb', line 30

def variable!(name, value=nil)
  if value
    css! "@#{_dasherize name} : #{value};"
    _newline
  else
    return "@#{_dasherize name}"
  end
  @css
end