class Remarkably::Engines::CSS

Public Instance Methods

clear!() click to toggle source
Calls superclass method Remarkably::Base::Engine#clear!
# File lib/remarkably/engines/css.rb, line 60
def clear!
  super
  @css_prefix=''
  @css_depth=0
  @css_prefix_rendered=false
  @css_first_use=true
end
css_class(args, hash, &block) click to toggle source
# File lib/remarkably/engines/css.rb, line 44
def css_class args, hash, &block
  css_prefix ".", &block
end
css_id(args, hash, &block) click to toggle source
# File lib/remarkably/engines/css.rb, line 48
def css_id args, hash, &block
  css_prefix "#", &block
end
css_prefix(prefix, &block) click to toggle source
# File lib/remarkably/engines/css.rb, line 37
def css_prefix prefix, &block
  @css_prefix << prefix
  block.call
  @css_prefix.chop!
  self
end
css_pseudo(args, hash, &block) click to toggle source
# File lib/remarkably/engines/css.rb, line 52
def css_pseudo args, hash, &block
  css_prefix ":", &block
end
method!(sym, args, hash, &block) click to toggle source
# File lib/remarkably/engines/css.rb, line 6
def method! sym, args, hash, &block
  sym = sym.to_s.downcase
  sym = "##{sym}".chop if sym[-1].chr == '!'
  sym = ".#{sym}".chop if sym[-1].chr == '?'

  if block_given?
    current_prefix = @css_prefix
    @css_prefix = (@css_prefix+"#{sym}#{args.map{|a|a.to_s}.join} ")
    @css_depth+=1
    @css_prefix_rendered=false
    block.call
    @css_depth-=1
    @css_prefix = current_prefix
  else
    unless @css_prefix_rendered
      unless @css_first_use
        @output.chop!
        @output << "}"
      end
      @output << "\n#{@css_prefix}{"
      @css_prefix_rendered = true
      @css_first_use = false
    end
    # XXX This line below is more complex than it needs to be, for some
    # reason gsub in ruby 1.9.2 throws a method_missing breaking
    # everything :(
    @output << "#{sym.to_s.split('').map{|n|n=='_' ? '-' : n}.join('')}:#{args.map{|a|a.to_s}.join(' ')};"
  end
  self
end
to_s() click to toggle source
# File lib/remarkably/engines/css.rb, line 56
def to_s
  "#{super.chop}}".strip+"\n"
end