Jam::Hpricot

Parent

Generated with Razzle Dazzle Redfish.
[Validate]

Hpricot Adaptor

Public Class Methods

new(*options) click to toggle source
# File lib/jam/hpricot.rb, line 37
    def initialize(*options)
      @options = options
    end

Public Instance Methods

append(ns, child) click to toggle source
# File lib/jam/hpricot.rb, line 67
    def append(ns, child)
      ns.append(child.to_s)
    end
attribute(ns, att, val) click to toggle source
# File lib/jam/hpricot.rb, line 97
    def attribute(ns, att, val)
      ns.set(att, val)
    end
cleanup(node) click to toggle source

Remove jam nodes that ask for it, and all jam attributes.

# File lib/jam/hpricot.rb, line 103
    def cleanup(node)
      #node = node.root if ::Nokogiri::XML::Document === node
      # remove unwanted tags
      node.search("//*[@jam='erase']").each do |n|
        unwrap(n)
      end
      # remove jam attributes

      #
      node
    end
copy(node) click to toggle source

deep copy # TODO: works?

# File lib/jam/hpricot.rb, line 52
    def copy(node)
      node.dup 
    end
document(source) click to toggle source
# File lib/jam/hpricot.rb, line 42
    def document(source)
      ::Hpricot.parse(source) #, *@options)
    end
each_node(nodes) click to toggle source

Iterate over each node.

# File lib/jam/hpricot.rb, line 125
    def each_node(nodes)
      unless ::Hpricot::Elements === nodes
        nodes = [nodes]
      end
      nodes.each do |node|
        yield(node)
      end
    end
empty(ns) click to toggle source
# File lib/jam/hpricot.rb, line 62
    def empty(ns)
      ns.empty
    end
remove(node) click to toggle source
# File lib/jam/hpricot.rb, line 78
    def remove(node)
      node.remove
    end
remove(node) click to toggle source
# File lib/jam/hpricot.rb, line 57
    def remove(node)
      node.remove
    end
replace(ns, child) click to toggle source
# File lib/jam/hpricot.rb, line 72
    def replace(ns, child)
      empty(ns)
      append(ns, child)
    end
replace_content_with_text(node, text) click to toggle source
# File lib/jam/hpricot.rb, line 83
    def replace_content_with_text(node, text)
      case node
      when ::Hpricot::Elements
        node.inner_html = text
      when ::Array
        node.each do |n|
          n.inner_html = text
        end
      else

      end
    end
search(node, qry) click to toggle source
# File lib/jam/hpricot.rb, line 47
    def search(node, qry)
      node.search(qry)
    end
unwrap(node) click to toggle source

Unwrap a node, such that the outer tag is removed, leaving only it’s own children.

# File lib/jam/hpricot.rb, line 118
    def unwrap(node)
      node.each_child{ |n| node.parent.insert_before(n, node) }
      ::Hpricot::Elements[node].remove
    end

Disabled; run with --debug to generate this.