Class: Paggio::CSS::Definition
- Inherits:
- BasicObject
- Defined in:
- lib/paggio/css/definition.rb
Defined Under Namespace
Instance Method Summary collapse
- #background(*args) ⇒ Object
- #border(*args) ⇒ Object
- #box(options) ⇒ Object
- #each(&block) ⇒ Object
- #empty? ⇒ Boolean
- #gradient(*args) ⇒ Object
-
#initialize(&block) ⇒ Definition
constructor
A new instance of Definition.
- #method_missing(name, *args, &block) ⇒ Object
- #opacity(value) ⇒ Object
Constructor Details
#initialize(&block) ⇒ Definition
Returns a new instance of Definition.
16 17 18 19 20 21 22 23 24 |
# 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 |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object
133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 |
# File 'lib/paggio/css/definition.rb', line 133 def method_missing(name, *args, &block) name = name.to_s important = name.end_with? ?! name = name[0 .. -2] if important @important = true if important if important && respond_to?(name) __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 |
Instance Method Details
#background(*args) ⇒ Object
42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
# File 'lib/paggio/css/definition.rb', line 42 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) ⇒ Object
62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 |
# File 'lib/paggio/css/definition.rb', line 62 def border(*args) if ::Hash === args.first if args.length == 1 = args.first end .each {|name, value| case name 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) ⇒ Object
103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 |
# File 'lib/paggio/css/definition.rb', line 103 def box() if ::Hash === .each {|name, value| case name when :shadow if ::Array === value value = value.join ', ' end style '-moz-box-shadow', value style '-webkit-box-shadow', value style 'box-shadow', value else style "box-#{name}", value end } else style :box, end end |
#each(&block) ⇒ Object
30 31 32 33 34 35 36 |
# File 'lib/paggio/css/definition.rb', line 30 def each(&block) return enum_for :each unless block @style.each(&block) self end |
#empty? ⇒ Boolean
26 27 28 |
# File 'lib/paggio/css/definition.rb', line 26 def empty? @style.empty? end |
#gradient(*args) ⇒ Object
38 39 40 |
# File 'lib/paggio/css/definition.rb', line 38 def gradient(*args) Gradient.new(*args) end |
#opacity(value) ⇒ Object
125 126 127 128 129 130 131 |
# File 'lib/paggio/css/definition.rb', line 125 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 |