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.



95
96
97
# File 'lib/html5/treebuilders/hpricot.rb', line 95

def initialize(hpricot)
  @hpricot = hpricot
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(*a, &b) ⇒ Object



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

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

Instance Method Details

#[]=(k, v) ⇒ Object



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

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

#stag_attributes_methodObject



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

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