class Paggio::CSS::Definition

Constants

Style

Public Class Methods

new(&block) click to toggle source
# File lib/paggio/css/definition.rb, line 16
def initialize(&block)
  @style = []

  if block.arity == 0
    instance_exec(&block)
  else
    block.call(self)
  end if block
end

Public Instance Methods

animation(*args) click to toggle source
# File lib/paggio/css/definition.rb, line 176
def animation(*args)
  if Hash === args.first
    if args.length == 1
      options = args.first
    end

    options.each {|name, value|
      style "-webkit-animation-#{name}", value
      style "animation-#{name}", value
    }
  else
    style 'animation', args
    style '-webkit-animation', args
  end
end
background(*args) click to toggle source
# File lib/paggio/css/definition.rb, line 72
def background(*args)
  if Gradient === args.first
    if args.length > 1
      raise NotImplementedError, "multiple gradients not implemented yet"
    end

    args.first.each {|s|
      style s.name || 'background-image', s.value
    }
  else
    if ::Hash === args.first
      args.first.each {|sub, value|
        style "background-#{sub}", value
      }
    else
      style :background, args
    end
  end
end
border(*args) click to toggle source
# File lib/paggio/css/definition.rb, line 92
def border(*args)
  if ::Hash === args.first
    if args.length == 1
      options = args.first
    end

    options.each {|name, value|
      case name
      when :top, :bottom, :left, :right
        if ::Hash === value
          value.each {|n, v|
            style "border-#{name}-#{n}", v
          }
        else
          style "border-#{name}", value
        end

      when :radius
        if ::Hash === value
          value.each {|horizontal, value|
            value.each {|vertical, value|
              style "-moz-border-radius-#{horizontal}#{vertical}", value
              style "-webkit-border-#{horizontal}-#{vertical}-radius", value
              style "border-#{horizontal}-#{vertical}-radius", value
            }
          }
        else
          style '-moz-border-radius', value
          style '-webkit-border-radius', value
          style 'border-radius', value
        end

      when :color
        if ::Hash === value
          value.each {|name, value|
            style "border-#{name}-color", value
          }
        else
          style 'border-color', value
        end

      else
        style "border-#{name}", value
      end
    }
  else
    style :border, args
  end
end
box(options) click to toggle source
# File lib/paggio/css/definition.rb, line 142
def box(options)
  if ::Hash === options
    options.each {|name, value|
      case name
      when :shadow
        if ::Array === value
          if ::Array === value[0]
            value = value.map { |v| v.join ' ' }.join(', ')
          else
            value = value.join ' '
          end
        end

        style '-moz-box-shadow', value
        style '-webkit-box-shadow', value
        style 'box-shadow', value

      else
        style "box-#{name}", value
      end
    }
  else
    style :box, options
  end
end
each(&block) click to toggle source
# File lib/paggio/css/definition.rb, line 30
def each(&block)
  @style.each(&block)
end
empty?() click to toggle source
# File lib/paggio/css/definition.rb, line 26
def empty?
  @style.empty?
end
filter(*args) click to toggle source
# File lib/paggio/css/definition.rb, line 213
def filter(*args)
  style 'filter', args
  style '-webkit-filter', args
  style '-moz-filter', args
  style '-ms-filter', args
  style '-o-filter', args
end
gradient(*args) click to toggle source
# File lib/paggio/css/definition.rb, line 34
def gradient(*args)
  Gradient.new(*args)
end
method_missing(name, *args, &block) click to toggle source
# File lib/paggio/css/definition.rb, line 221
def method_missing(name, *args, &block)
  name = name.to_s

  if name.end_with? ?!
    name = name[0 .. -2]

    @important = true
    __send__ name, *args, &block
    @important = false

    return
  end

  if args.length == 1
    argument = args.first

    if ::Hash === argument
      argument.each {|sub, value|
        style "#{name}-#{sub}", value
      }
    else
      style name, argument
    end
  else
    style name, args.join(' ')
  end

  @important = false

  self
end
opacity(value) click to toggle source
# File lib/paggio/css/definition.rb, line 168
def opacity(value)
  style 'opacity', value
  style '-moz-opacity', value

  style '-ms-filter', %Q{"progid:DXImageTransform.Microsoft.Alpha(Opacity=#{(value * 100).to_i})"}
  style 'filter', "alpha(opacity=#{(value * 100).to_i})"
end
rgb(r, g, b) click to toggle source
# File lib/paggio/css/definition.rb, line 48
def rgb(r, g, b)
  "rgb(#{r}, #{g}, #{b}, #{a})"
end
rgba(r, g, b, a) click to toggle source
# File lib/paggio/css/definition.rb, line 52
def rgba(r, g, b, a)
  "rgba(#{r}, #{g}, #{b}, #{a})"
end
style(name, value = nil, important = @important) click to toggle source
# File lib/paggio/css/definition.rb, line 253
def style(name, value = nil, important = @important)
  if ::Array === value
    value = value.join ' '
  end

  if Style === name
    @style << name
  else
    @style << Style.new(name, value, important)
  end
end
style!(name, value = nil) click to toggle source
# File lib/paggio/css/definition.rb, line 265
def style!(name, value = nil)
  style(name, value, true)
end
transform(*args) click to toggle source
# File lib/paggio/css/definition.rb, line 205
def transform(*args)
  style 'transform', args
  style '-webkit-transform', args
  style '-moz-transform', args
  style '-ms-transform', args
  style '-o-transform', args
end
transition(*args) click to toggle source
# File lib/paggio/css/definition.rb, line 192
def transition(*args)
  style 'transition', args
  style '-webkit-transition', args
  style '-moz-transition', args
end
url(value) click to toggle source
# File lib/paggio/css/definition.rb, line 38
def url(value)
  "url(#{value.to_s.inspect})"
end
user_select(*args) click to toggle source
# File lib/paggio/css/definition.rb, line 198
def user_select(*args)
  style 'user-select', args
  style '-webkit-user-select', args
  style '-moz-user-select', args
  style '-ms-user-select', args
end