Changeset 7714b02d25b8c8852538264cec4a37577d682068

Show
Ignore:
Timestamp:
08/05/07 23:41:01 (17 months ago)
Author:
Mark Guzman <segfault@…>
Parents:
44461b23e49dc856ad7b26ea70d01c4b23c56e1f
Children:
353e95b8dce9775aee6b01ec373cb939d4d76baf
git-committer:
Mark Guzman <segfault@hasno.info> / 2007-08-06T03:41:01Z+0000
Message:

starting to add hpricot-like features ala (node/"xpath") and FastXml?("my doc info")

git-svn-id: svn://hasno.info/fastxml/trunk@24 b3082176-f867-4bde-be85-e3c57d66f029

Files:
2 modified

Legend:

Unmodified
Added
Removed
  • ext/fastxml.c

    r44461b r7714b0  
    7575    xmlXPathInit(); 
    7676    VALUE rb_mFastXml = rb_define_module( "FastXml" ); 
    77     rb_define_const( rb_mFastXml, "VERSION", rb_str_new2( "0.1" ) ); 
     77    //rb_define_const( rb_mFastXml, "VERSION", rb_str_new2( "0.1" ) ); 
    7878    rb_cFastXmlDoc = rb_define_class_under( rb_mFastXml, "Doc", rb_cObject );         
    7979    rb_cFastXmlNode = rb_define_class_under( rb_mFastXml, "Node", rb_cObject ); 
    8080 
    8181    /* Doc */ 
    82     rb_include_module( rb_cFastXmlDoc, rb_mEnumerable ); 
     82    //rb_include_module( rb_cFastXmlDoc, rb_mEnumerable ); 
    8383    rb_define_method( rb_cFastXmlDoc, "initialize", fastxml_doc_initialize, 1 ); 
    8484    rb_define_method( rb_cFastXmlDoc, "search", fastxml_doc_search, 1 ); 
     
    9191     
    9292    /* Node */ 
    93     rb_include_module( rb_cFastXmlNode, rb_mEnumerable ); 
     93    //rb_include_module( rb_cFastXmlNode, rb_mEnumerable ); 
    9494    rb_define_method( rb_cFastXmlNode, "initialize", fastxml_node_initialize, 0 ); 
    9595    rb_define_method( rb_cFastXmlNode, "search", fastxml_node_search, 1 ); 
     
    105105        rb_define_method( rb_cFastXmlNode, "prev", fastxml_node_prev, 0 );       
    106106        rb_define_method( rb_cFastXmlNode, "parent", fastxml_node_parent, 0 );   
     107         
     108        rb_require( "lib/fastxml_lib" ); 
    107109} 
    108110 
  • lib/fastxml_lib.rb

    r79be80 r7714b0  
    33  VERSION = "0.1.%s" % "$Rev$".gsub(/\$Rev:\s+/, '').gsub(/\s*\$$/, '') 
    44end 
     5 
     6module FastXml::Common 
     7  def children_of_type(type) 
     8    self.search( "//#{type}" ) 
     9  end 
     10   
     11  def each_child(&blk) 
     12    self.children.each { |chld| yield chld } 
     13  end 
     14   
     15  def /(xpath) 
     16    self.search( "/#{xpath.to_s}" ) 
     17  end 
     18   
     19  alias :to_s :display 
     20end 
     21 
     22class FastXml::Doc 
     23  include FastXml::Common 
     24   
     25  def doc? 
     26    true 
     27  end 
     28   
     29  def doctype? 
     30    nil 
     31  end 
     32end 
     33 
     34class FastXml::Node 
     35  include FastXml::Common 
     36  def doc? 
     37    false 
     38  end 
     39end 
     40 
     41 
     42def FastXml(data=nil, opts = {}, &blk) 
     43  FastXml::Doc.new data 
     44end