Class: Hpricot::STag
- Includes:
- Tag
- Defined in:
- lib/hpricot/tag.rb,
lib/hpricot/inspect.rb,
lib/hpricot/modules.rb
Constant Summary
Constants included from Hpricot
ElementContent, ElementExclusions, ElementInclusions, NamedCharacters, NamedCharactersPattern, OmittedAttrName
Instance Attribute Summary
Attributes inherited from BaseEle
Class Method Summary collapse
Instance Method Summary collapse
- #attributes_as_html ⇒ Object
-
#initialize(name, attributes = nil) ⇒ STag
constructor
A new instance of STag.
- #output(out, opts = {}) ⇒ Object
- #pretty_print(q) ⇒ Object
Methods included from Hpricot
XML, build_node, make, scan
Methods inherited from BaseEle
alterable, #altered!, #html_quote, #if_output, #pathname
Constructor Details
#initialize(name, attributes = nil) ⇒ STag
Returns a new instance of STag.
86 87 88 89 90 91 92 |
# File 'lib/hpricot/tag.rb', line 86 def initialize(name, attributes=nil) @name = name.downcase @attributes = {} if attributes @attributes = attributes.inject({}) { |hsh,(k,v)| hsh[k.downcase] = v; hsh } end end |
Class Method Details
Instance Method Details
#attributes_as_html ⇒ Object
94 95 96 97 98 99 100 101 |
# File 'lib/hpricot/tag.rb', line 94 def attributes_as_html if @attributes @attributes.map do |aname, aval| " #{aname}" + (aval ? "=#{html_quote(aval)}" : "") end.join end end |
#output(out, opts = {}) ⇒ Object
102 103 104 105 106 107 108 109 |
# File 'lib/hpricot/tag.rb', line 102 def output(out, opts = {}) out << if_output(opts) do "<#{@name}#{attributes_as_html}" + (opts[:style] == :empty ? " /" : "") + ">" end end |
#pretty_print(q) ⇒ Object
59 60 61 62 63 64 65 66 67 68 69 70 |
# File 'lib/hpricot/inspect.rb', line 59 def pretty_print(q) q.group(1, '<', '>') { q.text @name if @attributes @attributes.each {|n, t| q.breakable q.text "#{n}=\"#{t}\"" } end } end |