Class: HTML5::TreeBuilders::Hpricot::Element::AttributeProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/html5/treebuilders/hpricot.rb

Overview

A call to Hpricot::Elem#raw_attributes is built dynamically, so alterations to the returned value (a hash) will be lost.

AttributeProxy works around this by forwarding :[]= calls to the raw_attributes accessor on the element start tag.

Instance Method Summary collapse

Constructor Details

#initialize(hpricot) ⇒ AttributeProxy

Returns a new instance of AttributeProxy.



98
99
100
# File 'lib/html5/treebuilders/hpricot.rb', line 98

def initialize(hpricot)
  @hpricot = hpricot
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*a, &b) ⇒ Object



111
112
113
# File 'lib/html5/treebuilders/hpricot.rb', line 111

def method_missing(*a, &b)
  @hpricot.attributes.send(*a, &b)
end

Instance Method Details

#[]=(k, v) ⇒ Object



102
103
104
# File 'lib/html5/treebuilders/hpricot.rb', line 102

def []=(k, v)
  @hpricot.stag.send(stag_attributes_method)[k] = v
end

#stag_attributes_methodObject



106
107
108
109
# File 'lib/html5/treebuilders/hpricot.rb', line 106

def stag_attributes_method
  # STag#attributes changed to STag#raw_attributes after Hpricot 0.5
  @hpricot.stag.respond_to?(:raw_attributes) ? :raw_attributes : :attributes
end