Class: Goat::DOMTools::HTMLBuilder::TagBuilder
- Defined in:
- lib/goat/dom.rb
Class Method Summary collapse
-
.build(tag, attrs, body) ⇒ Object
TODO: gmail trick of only a single onclick() handler.
Instance Method Summary collapse
- #a_tag ⇒ Object
- #build_node ⇒ Object
- #dispatch ⇒ Object
-
#initialize(tag, attrs, body) ⇒ TagBuilder
constructor
A new instance of TagBuilder.
- #input_tag ⇒ Object
- #rewrite_attrs ⇒ Object
Constructor Details
#initialize(tag, attrs, body) ⇒ TagBuilder
Returns a new instance of TagBuilder.
255 256 257 258 259 260 261 |
# File 'lib/goat/dom.rb', line 255 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
251 252 253 |
# File 'lib/goat/dom.rb', line 251 def self.build(tag, attrs, body) self.new(tag, attrs, body).dispatch end |
Instance Method Details
#a_tag ⇒ Object
281 282 283 284 285 286 287 |
# File 'lib/goat/dom.rb', line 281 def a_tag unless @attrs.include?(:href) @attrs[:href] = 'javascript:void(0)' end build_node end |
#build_node ⇒ Object
277 278 279 |
# File 'lib/goat/dom.rb', line 277 def build_node [@tag, @attrs, @body] end |
#dispatch ⇒ Object
306 307 308 309 310 311 312 313 314 |
# File 'lib/goat/dom.rb', line 306 def dispatch meth = "#{@tag}_tag".to_sym if self.respond_to?(meth) self.send(meth) else build_node end end |
#input_tag ⇒ Object
289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 |
# File 'lib/goat/dom.rb', line 289 def input_tag unless @attrs.include?(:name) $stderr.puts "Warning: no name for <#{@tag} #{@attrs.inspect}>#{@body.inspect}</#{@tag}>" # this is somewhat ungainly: we generate a name automatically by hashing the values of the # other attrs. this may conflict - ideally would track per-page state for these. # purpose is to have name-less inputs preserve their values when user goes back to page. # webkit in safari 5 gets confused when inputs are nameless. unless (vals = @attrs.values{|k, v| v.kind_of?(String)}).empty? $stderr.puts "Generating a name automatically..." @attrs[:name] = vals.join.md5[0..10] end end build_node end |