Class: Hpricot::CssProxy
- Inherits:
-
BlankSlate
- Object
- BlankSlate
- Hpricot::CssProxy
- Defined in:
- lib/hpricot/builder.rb
Overview
Class used by Markaby::Builder to store element options. Methods called against the CssProxy object are added as element classes or IDs.
See the README for examples.
Instance Method Summary collapse
-
#initialize(builder, sym) ⇒ CssProxy
constructor
Creates a CssProxy object.
-
#method_missing(id_or_class, *args, &block) ⇒ Object
Adds attributes to an element.
Methods inherited from BlankSlate
Constructor Details
#initialize(builder, sym) ⇒ CssProxy
Creates a CssProxy object.
195 196 197 |
# File 'lib/hpricot/builder.rb', line 195 def initialize(builder, sym) @builder, @sym, @attrs = builder, sym, {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(id_or_class, *args, &block) ⇒ Object
Adds attributes to an element. Bang methods set the :id attribute. Other methods add to the :class attribute.
201 202 203 204 205 206 207 208 209 210 211 212 213 214 |
# File 'lib/hpricot/builder.rb', line 201 def method_missing(id_or_class, *args, &block) if (idc = id_or_class.to_s) =~ /!$/ @attrs[:id] = $` else @attrs[:class] = @attrs[:class].nil? ? idc : "#{@attrs[:class]} #{idc}".strip end if block or args.any? args.push(@attrs) return @builder.tag!(@sym, *args, &block) end return self end |