Class: Goat::DOMTools::HTMLBuilder
Defined Under Namespace
Classes: TagBuilder
Constant Summary collapse
- ARRAY_ATTRS =
[:class]
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.
260 261 262 |
# File 'lib/goat/html.rb', line 260 def initialize(input) @input = input end |
Instance Method Details
#array_to_html(ar) ⇒ Object
240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/goat/html.rb', line 240 def array_to_html(ar) if ar.first.kind_of?(Symbol) tag = ar[0] have_attrs = ar[1].is_a?(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
236 237 238 |
# File 'lib/goat/html.rb', line 236 def attrs_to_html(attrs) attrs.map {|k, v| "#{k}=\"#{v}\""}.join(' ') end |
#html ⇒ Object
264 265 266 |
# File 'lib/goat/html.rb', line 264 def html @input.to_html(self) end |
#standalone_tags ⇒ Object
232 233 234 |
# File 'lib/goat/html.rb', line 232 def %w{br img input} end |