Class: Paggio::CSS::Definition
- Inherits:
- BasicObject
- Defined in:
- lib/paggio/css/definition.rb
Defined Under Namespace
Instance Method Summary collapse
- #animation(*args) ⇒ Object
- #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
- #style(name, value = nil, important = @important) ⇒ Object
- #style!(name, value = nil) ⇒ Object
- #transition(*args) ⇒ Object
- #url(arg) ⇒ 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
148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 |
# File 'lib/paggio/css/definition.rb', line 148 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
#animation(*args) ⇒ Object
137 138 139 140 |
# File 'lib/paggio/css/definition.rb', line 137 def animation(*args) style 'animation', args style '-webkit-animation', args end |
#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 124 125 126 127 |
# File 'lib/paggio/css/definition.rb', line 103 def box() if ::Hash === .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, end end |
#each(&block) ⇒ Object
30 31 32 |
# File 'lib/paggio/css/definition.rb', line 30 def each(&block) @style.each(&block) end |
#empty? ⇒ Boolean
26 27 28 |
# File 'lib/paggio/css/definition.rb', line 26 def empty? @style.empty? end |
#gradient(*args) ⇒ Object
34 35 36 |
# File 'lib/paggio/css/definition.rb', line 34 def gradient(*args) Gradient.new(*args) end |
#opacity(value) ⇒ Object
129 130 131 132 133 134 135 |
# File 'lib/paggio/css/definition.rb', line 129 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 |
#style(name, value = nil, important = @important) ⇒ Object
181 182 183 184 185 186 187 188 189 190 191 |
# File 'lib/paggio/css/definition.rb', line 181 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) ⇒ Object
193 194 195 |
# File 'lib/paggio/css/definition.rb', line 193 def style!(name, value = nil) style(name, value, true) end |
#transition(*args) ⇒ Object
142 143 144 145 146 |
# File 'lib/paggio/css/definition.rb', line 142 def transition(*args) style 'transition', args style '-webkit-transition', args style '-moz-transition', args end |
#url(arg) ⇒ Object
38 39 40 |
# File 'lib/paggio/css/definition.rb', line 38 def url(arg) "url(#{arg.inspect})" end |