Class: Plate::ClassNode

Inherits:
RichNode
  • Object
show all
Defined in:
lib/plate/nodes.rb,
lib/plate/compiler.rb

Instance Attribute Summary collapse

Attributes inherited from RichNode

#body, #parent, #scripts, #styles

Instance Method Summary collapse

Methods inherited from RichNode

#compile_body, #parent_repeat?, #repeat?

Methods included from Inspector

#inspect_with

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

#klassObject

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



201
202
203
204
205
206
# File 'lib/plate/compiler.rb', line 201

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_classObject



184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
# File 'lib/plate/compiler.rb', line 184

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}"
    when /\Aoffset\-(\d+)\z/
      "col-sm-offset-#{$1}"
    else
      k
    end
  }.join(' ')
end

#compile_tagObject



175
176
177
178
179
180
181
182
# File 'lib/plate/compiler.rb', line 175

def compile_tag
  case klass
  when /\A(?:btn)/
    'button'
  else
    'div'
  end
end

#inspectObject



62
63
64
# File 'lib/plate/nodes.rb', line 62

def inspect
  inspect_with([klass])
end