class Paggio::CSS
Attributes
animations[R]
fonts[R]
media[R]
rules[R]
Public Class Methods
new(defer: false, &block)
click to toggle source
# File lib/paggio/css.rb, line 41 def initialize(defer: false, &block) ::Kernel.raise ::ArgumentError, 'no block given' unless block @selector = [] @current = [] @rules = [] @fonts = [] @animations = [] @block = block build! unless defer end
selector(list)
click to toggle source
# File lib/paggio/css.rb, line 21 def self.selector(list) result = '' list.each {|part| if part.start_with?('&') result += part[1 .. -1] else result += " " + part end } if result[0] == " " result[1 .. -1] else result end end
Public Instance Methods
animation(name, *args, &block)
click to toggle source
# File lib/paggio/css.rb, line 102 def animation(name, *args, &block) if block @current << Animation.new(name) block.call @animations << @current.pop else method_missing(:animation, name, *args) end end
build!(force_call: false)
click to toggle source
# File lib/paggio/css.rb, line 55 def build!(force_call: false) if !force_call && @block.arity == 0 instance_exec(&@block) else @block.call(self) end @block = nil end
font(name, *args, &block)
click to toggle source
# File lib/paggio/css.rb, line 92 def font(name, *args, &block) if block @current << Font.new(name) block.call @fonts << @current.pop else method_missing(:font, name, *args) end end
method_missing(*args, &block)
click to toggle source
this is needed because the methods inside the rule blocks are actually called on the CSS
object
# File lib/paggio/css.rb, line 114 def method_missing(*args, &block) @current.last.__send__(*args, &block) end
rule(*names, &block)
click to toggle source
# File lib/paggio/css.rb, line 64 def rule(*names, &block) return unless block if names.any? { |n| n.include? ',' } ::Kernel.raise ::ArgumentError, 'selectors cannot contain commas' end names.each {|name| @selector << name @current << Rule.new(CSS.selector(@selector), @media) block.call @selector.pop @rules << @current.pop } end