Class: Hpricot::STag

Inherits:
BaseEle show all
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

#parent, #raw_string

Class Method Summary collapse

Instance Method Summary collapse

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

.parse(qname, attrs, raw_string, is_stag) ⇒ Object



188
189
190
191
192
# File 'lib/hpricot/parse.rb', line 188

def STag.parse(qname, attrs, raw_string, is_stag)
  result = STag.new(qname, attrs)
  result.raw_string = raw_string
  result
end

Instance Method Details

#attributes_as_htmlObject



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