Class: Plate::ClassNode
- Defined in:
- lib/plate/nodes.rb,
lib/plate/compiler.rb
Instance Attribute Summary collapse
-
#klass ⇒ Object
Returns the value of attribute klass.
Attributes inherited from RichNode
#body, #parent, #scripts, #styles
Instance Method Summary collapse
- #compile(compiler, parent = nil) ⇒ Object
- #compile_class ⇒ Object
- #compile_tag ⇒ Object
-
#initialize(klass, body) ⇒ ClassNode
constructor
A new instance of ClassNode.
- #inspect ⇒ Object
Methods inherited from RichNode
#compile_body, #parent_repeat?, #repeat?
Methods included from Inspector
Constructor Details
#initialize(klass, body) ⇒ ClassNode
Returns a new instance of ClassNode.
57 58 59 60 |
# File 'lib/plate/nodes.rb', line 57 def initialize(klass, body) super(body) self.klass = klass end |
Instance Attribute Details
#klass ⇒ Object
Returns the value of attribute klass.
56 57 58 |
# File 'lib/plate/nodes.rb', line 56 def klass @klass end |
Instance Method Details
#compile(compiler, parent = nil) ⇒ Object
192 193 194 195 196 197 |
# File 'lib/plate/compiler.rb', line 192 def compile(compiler, parent = nil) tag = compile_tag c = compile_class content, style, script = compile_body(compiler, parent) "<#{tag} class=\"#{c}\"#{style}#{script}>#{content}</#{tag}>" end |
#compile_class ⇒ Object
177 178 179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'lib/plate/compiler.rb', line 177 def compile_class klass.split('.').map { |k| case k when 'btn' k + ' btn-default' when 'center' "text-#{k}" when /\A\d\z/ "col-sm-#{k}" else k end }.join(' ') end |
#compile_tag ⇒ Object
168 169 170 171 172 173 174 175 |
# File 'lib/plate/compiler.rb', line 168 def compile_tag case klass when /\A(?:btn)/ 'button' else 'div' end end |
#inspect ⇒ Object
62 63 64 |
# File 'lib/plate/nodes.rb', line 62 def inspect inspect_with([klass]) end |