# Copyright (C) 2003-2006 Kouichirou Eto, All rights reserved. # This is free software with ABSOLUTELY NO WARRANTY. # You can redistribute it and/or modify it under the terms of the GNU GPL 2. $LOAD_PATH << 'compat' unless $LOAD_PATH.include? 'compat' #require 'htree' $LOAD_PATH.unshift '..' unless $LOAD_PATH.include? '..' module HTree class Doc def to_wabisabi return children.map {|child| child.to_wabisabi } end end class XMLDecl def to_wabisabi w = [:'?xml'] w << @version w << @encoding if @encoding w << @standalone ? 'yes' : 'no' if @standalone return w end end class DocType def to_wabisabi w = [:'!DOCTYPE'] w << root_element_name w << 'PUBLIC' w << public_identifier w << system_identifier return w end end module Node def to_wabisabi ar = [] element_name = name.sub('{http://www.w3.org/1999/xhtml}', '').intern ar << element_name if 0 < attributes.length h = {} attributes.each {|k, v| h[k.to_s.intern] = v.to_s } ar << h end children.each {|h| case h when Elem, Text, Comment, BogusETag ar << h.to_wabisabi else p 'what?', h end } return ar end end class Text def to_wabisabi return to_s end end class Comment def to_wabisabi return [:'!--', @content] end end class BogusETag def to_wabisabi return '' end end end if $0 == __FILE__ require 'qwik/testunit' $test = true end if defined?($test) && $test class TestHTreeToWabisabi < Test::Unit::TestCase def ok_ht(e, str) ok_eq(e, HTree(str).to_wabisabi) end def ok(e, htree) ok_eq(e, htree.to_wabisabi) end def test_doc ok([[:'!DOCTYPE', 'html', 'PUBLIC', '-//W3C//DTD html 4.01 Transitional//EN', 'http://www.w3.org/TR/html4/loose.dtd'], [:html, [:head, [:title, 't']], [:body, [:p, 'b']]]], HTree('
b
')) e = HTree::Elem.new('a') doc = HTree::Doc.new(e) ok_eq('#t
')) ok([[:p, 't'], ''], HTree('t
')) end end end