Class: Goat::DOMTools::HTMLBuilder
Defined Under Namespace
Classes: TagBuilder
Constant Summary collapse
- ARRAY_ATTRS =
[:class]
- INTEGER_ATTRS =
[:colspan, :rowspan]
Instance Method Summary collapse
- #array_to_html(ar) ⇒ Object
- #attrs_to_html(attrs) ⇒ Object
- #html ⇒ Object
-
#initialize(input) ⇒ HTMLBuilder
constructor
A new instance of HTMLBuilder.
- #standalone_tags ⇒ Object
Constructor Details
#initialize(input) ⇒ HTMLBuilder
Returns a new instance of HTMLBuilder.
345 346 347 |
# File 'lib/goat/dom.rb', line 345 def initialize(input) @input = input end |
Instance Method Details
#array_to_html(ar) ⇒ Object
325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 |
# File 'lib/goat/dom.rb', line 325 def array_to_html(ar) if ar.first.kind_of?(Symbol) tag = ar[0] have_attrs = ar[1].kind_of?(Hash) attrs = have_attrs ? ar[1] : {} body = ar[(have_attrs ? 2 : 1)..-1] tag, attrs, body = TagBuilder.build(tag, attrs, body) lonely = .include?(tag.to_s) open_tag = "<#{tag}#{attrs.empty? ? '' : (' ' + attrs_to_html(attrs))}>" body_html = body.empty? ? '' : body.map{|x| x.to_html(self)}.join close_tag = (lonely ? '' : "</#{tag}>") "#{open_tag}#{body_html}#{close_tag}" else ar.map{|x| x.to_html(self)}.join end end |
#attrs_to_html(attrs) ⇒ Object
321 322 323 |
# File 'lib/goat/dom.rb', line 321 def attrs_to_html(attrs) attrs.map {|k, v| "#{k}=\"#{v}\""}.join(' ') end |
#html ⇒ Object
349 350 351 |
# File 'lib/goat/dom.rb', line 349 def html @input.to_html(self) end |
#standalone_tags ⇒ Object
317 318 319 |
# File 'lib/goat/dom.rb', line 317 def %w{br img input} end |