class Paggio::CSS::Definition::Gradient

Public Class Methods

new(*args) click to toggle source

TODO: all of it, seriously

# File lib/paggio/css/definition.rb, line 271
def initialize(*args)
  options = ::Hash === args.last ? args.pop : {}

  @to   = options[:to]
  @from = options[:from]

  if @to && !@from
    @from = other(@to)
  elsif @from && !@to
    @to = other(@from)
  end

  @start = args.shift
  @end   = args.shift
end

Public Instance Methods

each(&block) click to toggle source
# File lib/paggio/css/definition.rb, line 287
def each(&block)
  block.call style("-moz-linear-gradient(#@to, #@start 0%, #@end 100%)")

  if horizontal?
    block.call style("-webkit-gradient(linear, #@from top, #@to top, color-stop(0%, #@start), color-stop(100%, #@end))")
  else
    block.call style("-webkit-gradient(linear, left #@from, left #@to, color-stop(0%, #@start), color-stop(100%, #@end))")
  end

  block.call style("-webkit-linear-gradient(#@to, #@start 0%, #@end 100%)")
  block.call style("-o-linear-gradient(#@to, #@start 0%, #@end 100%)")
  block.call style("-ms-linear-gradient(#@to, #@start 0%, #@end 100%)")
  block.call style("linear-gradient(to #@to, #@start 0%, #@end 100%)")
end
horizontal?() click to toggle source
# File lib/paggio/css/definition.rb, line 302
def horizontal?
  @to == :left || @to == :right
end
vertical?() click to toggle source
# File lib/paggio/css/definition.rb, line 306
def vertical?
  @to == :top || @to == :bottom
end

Private Instance Methods

other(side) click to toggle source
# File lib/paggio/css/definition.rb, line 311
def other(side)
  case side
  when :left   then :right
  when :right  then :left
  when :top    then :bottom
  when :bottom then :top
  end
end
style(*args) click to toggle source

FIXME: use default args

# File lib/paggio/css/definition.rb, line 321
def style(*args)
  if args.length == 1
    Style.new(nil, args.first)
  else
    Style.new(*args)
  end
end