Parent

Class/Module Index [+]

Quicksearch

Builder::CSS

Create a Cascading Style Sheet (CSS) using Ruby.

Example usage:

css = Builder::CSS.new

text_color      = '#7F7F7F'
preferred_fonts = 'Helvetica, Arial, sans_serif'

css.comment! 'This is our stylesheet'
css.body {
  background_color '#FAFAFA'
  font_size        'small'
  font_family      preferred_fonts
  color            text_color
}

css.id!('navbar') {
  width            '500px'
}

css.class!('navitem') {
  color            'red'
}

css.a :hover {
  text_decoration  'underline'
}

css.div(:id => 'menu') {
  background       'green'
}

css.div(:class => 'foo') {
  background       'red'
}

This will yield the following stylesheet:

/* This is our stylesheet */
body {
  background_color: #FAFAFA;
  font_size:        small;
  font_family:      Helvetica, Arial, sans_serif;
  color:            #7F7F7F;
}

#navbar {
  width:            500px;
}

.navitem {
  color:            red;
}

a:hover {
  text_decoration:  underline;
}

div#menu {
  background:       green;
}

div.foo {
  background:       red;
}

Public Class Methods

new(indent=2) click to toggle source

Create a CSS builder.

out

Object receiving the markup.1 out must respond to <<.

indent

Number of spaces used for indentation (0 implies no indentation and no line breaks).

# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 101
def initialize(indent=2)
  @indent      = indent
  @target      = []
  @parts       = []
  @library     = {}
end

Public Instance Methods

+(part) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 108
def +(part)
  _join_with_op! '+'
  self
end
>(part) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 118
def >(part)
  _join_with_op! '>'
  self
end
>>(part) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 113
def >>(part)
  _join_with_op! ''
  self
end
class!(arg, &block) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 145
def class!(arg, &block)
  _start_container('.'+arg.to_s, nil, block_given?)
  _css_block(block) if block
  _unify_block
  self
end
comment!(comment_text) click to toggle source

Create a comment string in the output.

# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 134
def comment!(comment_text)
  @target << "/* #{comment_text} */\n"
end
group!(*args, &block) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 156
def group!(*args, &block)
  args.each do |arg|
    if arg.is_a?(Symbol)
      instance_eval(&@library[arg])
    else
      instance_eval(&arg)
    end
    _text ', ' unless arg == args.last
  end
  if block
    _css_block(block)
    _unify_block
  end
end
id!(arg, &block) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 138
def id!(arg, &block)
  _start_container('#'+arg.to_s, nil, block_given?)
  _css_block(block) if block
  _unify_block
  self
end
method_missing(sym, *args, &block) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 171
def method_missing(sym, *args, &block)
  sym = "#{sym}:#{args.shift}" if args.first.kind_of?(Symbol)
  if block
    _start_container(sym, args.first)
    _css_block(block)
    _unify_block
  elsif @in_block
    _indent
    _css_line(sym, *args)
    _newline
    return self
  else
    _start_container(sym, args.first, false)
    _unify_block
  end
  self
end
nil?() click to toggle source

"Cargo culted" from Jim who also "cargo culted" it. See xmlbase.rb.

# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 190
def nil?
  false
end
store!(sym, &block) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 152
def store!(sym, &block)
  @library[sym] = block.to_proc
end
target!() click to toggle source

Return the target of the builder

# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 129
def target!
  @target * ''
end
|(part) click to toggle source
# File lib/active_support/vendor/builder-2.1.2/builder/css.rb, line 123
def |(part)
  _join_with_op! ','
  self
end

[Validate]

Generated with the Darkfish Rdoc Generator 2.