Class: Goat::DOMTools::HTMLBuilder::TagBuilder

Inherits:
Object
  • Object
show all
Defined in:
lib/goat/html.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(tag, attrs, body) ⇒ TagBuilder

Returns a new instance of TagBuilder.



195
196
197
198
199
200
201
# File 'lib/goat/html.rb', line 195

def initialize(tag, attrs, body)
  @tag = tag
  @attrs = attrs
  @body = body

  rewrite_attrs
end

Class Method Details

.build(tag, attrs, body) ⇒ Object

TODO: gmail trick of only a single onclick() handler



191
192
193
# File 'lib/goat/html.rb', line 191

def self.build(tag, attrs, body)
  self.new(tag, attrs, body).dispatch
end

Instance Method Details

#dispatchObject



221
222
223
224
225
226
227
228
229
# File 'lib/goat/html.rb', line 221

def dispatch
  meth = "#{@tag}_tag".to_sym

  if self.respond_to?(meth)
    self.send(meth)
  else
    identity
  end
end

#identityObject



217
218
219
# File 'lib/goat/html.rb', line 217

def identity
  [@tag, @attrs, @body]
end

#rewrite_attrsObject



203
204
205
206
207
208
209
210
211
212
213
214
215
# File 'lib/goat/html.rb', line 203

def rewrite_attrs
  new = {}

  @attrs.map_to_hash do |k, v|
    if k == :class && v.kind_of?(Array)
      new[:class] = @attrs[:class].join(' ')
    else            
      new[k] = v
    end
  end

  @attrs = new
end