Show
Ignore:
Timestamp:
08/31/2007 17:30:41 (15 months ago)
Author:
why
Message:

* lib/hpricot/traverse.rb: Element.make, for building fragments using the same options used to parse the doc. (thanks go to Rick Wargo for talking about this openly.)
* lib/hpricot/: switched almost every use of Hpricot.make with ele.make.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • trunk/lib/hpricot/traverse.rb

    r149 r155  
    2121    def bogusetag?() BogusETag::Trav === self end 
    2222 
     23    # Parses an HTML string, making an HTML fragment based on 
     24    # the options used to create the container document. 
     25    def make(input = nil, &blk) 
     26      if parent and parent.respond_to? :make 
     27        parent.make(input, &blk) 
     28      else 
     29        Hpricot.make(input, &blk) 
     30      end 
     31    end 
     32 
    2333    # Builds an HTML string from this node and its contents. 
    2434    # If you need to write to a stream, try calling <tt>output(io)</tt> 
     
    110120    # Adds elements immediately after this element, contained in the +html+ string. 
    111121    def after(html = nil, &blk) 
    112       parent.insert_after(Hpricot.make(html, &blk), self) 
     122      parent.insert_after(make(html, &blk), self) 
    113123    end 
    114124 
    115125    # Adds elements immediately before this element, contained in the +html+ string. 
    116126    def before(html = nil, &blk) 
    117       parent.insert_before(Hpricot.make(html, &blk), self) 
     127      parent.insert_before(make(html, &blk), self) 
    118128    end 
    119129 
     
    123133    def swap(html = nil, &blk) 
    124134      parent.altered! 
    125       parent.replace_child(self, Hpricot.make(html, &blk)) 
     135      parent.replace_child(self, make(html, &blk)) 
    126136    end 
    127137 
     
    159169          self.children = inner 
    160170        else 
    161           self.children = Hpricot.make(inner, &blk) 
     171          self.children = make(inner, &blk) 
    162172        end 
    163173        reparent self.children