Class: Goat::DOMTools::HTMLBuilder::TagBuilder
- Defined in:
- lib/goat/html.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.
202 203 204 205 206 207 208 |
# File 'lib/goat/html.rb', line 202 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
198 199 200 |
# File 'lib/goat/html.rb', line 198 def self.build(tag, attrs, body) self.new(tag, attrs, body).dispatch end |
Instance Method Details
#a_tag ⇒ Object
228 229 230 231 232 233 234 |
# File 'lib/goat/html.rb', line 228 def a_tag unless @attrs.include?(:href) @attrs[:href] = 'javascript:void(0)' end build_node end |
#build_node ⇒ Object
224 225 226 |
# File 'lib/goat/html.rb', line 224 def build_node [@tag, @attrs, @body] end |
#dispatch ⇒ Object
253 254 255 256 257 258 259 260 261 |
# File 'lib/goat/html.rb', line 253 def dispatch meth = "#{@tag}_tag".to_sym if self.respond_to?(meth) self.send(meth) else build_node end end |
#input_tag ⇒ Object
236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 |
# File 'lib/goat/html.rb', line 236 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 |