
  2002.09.16
    - HTML::Template.new()¤ËÊ¸»úÎó¡¤¥Ï¥Ã¥·¥å°Ê³°¤òÍ¿¤¨¤¿¤È¤­¤Ï¡¤¥¨¥é¡¼¤È¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
    - HTML::Template#html=()¤òºï½ü¡£set_html()¤¬¤¢¤ë¡£
    - ÃÖ´¹¥¿¥°¤¬¸«¤Ä¤«¤é¤Ê¤¤¤È¤­¤Ï¡¤¥¨¥é¡¼¤È¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£

  2002.11.11 (-q2)
    - ÊÄ¤¸¤é¤ì¤Æ¤¤¤Ê¤¤¥Î¡¼¥É¤Ï¡¤¥¨¥é¡¼¤È¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
    - »Ò¥Î¡¼¥É¤ÎÃÖ´¹¥¿¥°¤¬¸«¤Ä¤«¤é¤Ê¤¤¤È¤­¤â¡¤¥¨¥é¡¼¤È¤¹¤ë¤è¤¦¤Ë¤·¤¿¡£
    - HTML::Template#expand(), HTML::TemplateNode#expand()¤Ï¡¤self¤òÊÖ¤¹¤è¤¦¤Ë¤·¤¿¡£

  2002.11.17 (-q3)
    - set_html()¤Ï¡¤self¤òÊÖ¤¹¤è¤¦¤Ë¤·¤¿¡£

  2003.05.10 (-q4)
    - param()¤È¤¤¤¦Ì¾Á°¤ÏÉÔÌÀ¤Ê¤Î¤Ç¡¢alias¤Î°ì¤Ä¤À¤Ã¤¿expand()¤ËÊÑ¹¹¤·¤¿¡£
    - ¥Æ¥¹¥È¥¹¥¯¥ê¥×¥È¤òÄÉ²Ã¤·¤¿¡£

  2004.07.11 (-q5)
    - ÃÖ´¹¥¿¥°¤¬¸«¤Ä¤«¤é¤Ê¤¤¤È¤­¥¨¥é¡¼¤Ë¤¹¤ë¡Êq1¤Ç¤Î½¤Àµ¡Ë¤ò¸µ¤ËÌá¤·¤¿¡£


diff -Naur html-template-0.16.orig/lib/html/template.rb html-template-0.16-cur/lib/html/template.rb
--- html-template-0.16.orig/lib/html/template.rb	2002-01-05 03:32:05.000000000 +0900
+++ html-template-0.16-cur/lib/html/template.rb	2004-07-11 13:49:28.851462280 +0900
@@ -6,6 +6,9 @@
 
   class Template
     def initialize(param = nil)
+      raise TypeError if !param.is_a?(Hash) && !param.is_a?(String) &&
+                         !param.is_a?(NilClass)
+
       @path = ['.','']
       @html
       file = nil
@@ -43,14 +46,15 @@
     def set_html(html)
       @html = html
       parse
+      return self
     end
 
-    attr_accessor :html
+    attr_reader :html
     attr_accessor :path
 
     ##
     # set params
-    def param(key = {},*val)
+    def expand(key = {}, *val)
       hash = if key.is_a?(String)
 	       {key => val}
 	     else
@@ -59,14 +63,15 @@
       hash.each do |k,v|
 	if v.is_a?(Array)
 	  v.each do |h|
-	    node(k).param(h)
+            node(k).expand(h)
 	  end
 	elsif v.is_a?(Hash)
-	  node(k).param(v)
+          node(k).expand(v)
 	else
-	  @html.gsub!(/<!var:#{k}>/i,escape_re(v.to_s))
+          @html.gsub!(/<!var:#{k}>/i, escape_re(v.to_s))
 	end
       end
+      return self
     end
 
     ##
@@ -75,7 +80,7 @@
       if @node[name] != nil
 	return @node[name]
       else
-	raise ArgumentError,"node #{name} not found\n"
+	raise ArgumentError,"node '#{name}' not found"
       end
     end
 
@@ -91,7 +96,6 @@
     end
 
     ## aliases
-    alias expand param
     alias loop node
     alias cond node
     alias to_s output
@@ -137,6 +141,9 @@
 	@node[name] = HTML::TemplateNode.new(self,name,body)
 	"<!node:#{name}>"
       end
+      if @html =~ /<!begin:([\w\-\.]+)>(.*?)/
+        raise ArgumentError, "block without end-tag: '#{$1}'"
+      end
     end
   end
 
@@ -152,34 +159,15 @@
 
     attr_accessor :body
 
-    def param(key = {},*val)
-      hash = if key.is_a?(String)
-	       {key => val}
-	     else
-	       key
-	     end
-      hash.each do |k,v|
-	if v.is_a?(Array)
-	  v.each do |h|
-	    node(k).param(h)
-	  end
-	elsif v.is_a?(Hash)
-	  node(k).param(v)
-	else
-	  @html.gsub!(/<!var:#{k}>/i,escape_re(v.to_s))
-	end
-      end
+    def expand(key = {}, *val)
+      super
       html = @html.dup
       @parent.html.gsub!(/(<!node:#{@name}>)/) do 
 	"#{html}#{$1}"
       end
       @html = @original.dup
+      return self
     end
-
-    alias expand param
-    alias add param
-    alias loop node
-    alias cond node
   end
 end
 
diff -Naur html-template-0.16.orig/test/test.rb html-template-0.16-cur/test/test.rb
--- html-template-0.16.orig/test/test.rb	1970-01-01 09:00:00.000000000 +0900
+++ html-template-0.16-cur/test/test.rb	2004-07-11 13:48:33.259913480 +0900
@@ -0,0 +1,96 @@
+
+require "html/template"
+require "runit/testcase"
+require "runit/cui/testrunner"
+
+class Test1 < RUNIT::TestCase
+  # ÊÑ¿ôÌ¾¤¬¸«¤Ä¤«¤é¤Ê¤¤¤È¥¨¥é¡¼
+  def test10
+    tmpl = HTML::Template.new
+    tmpl.set_html "<html></html>"
+    assert_exception(ArgumentError) {
+      tmpl.expand({"hogevar" => "foo"})
+    }
+  end
+
+  # ¥Î¡¼¥É¤ÎÃæ¤ÇÊÑ¿ôÌ¾¤¬¸«¤Ä¤«¤é¤Ê¤¤¤È¥¨¥é¡¼
+  def test11
+    tmpl = HTML::Template.new
+    tmpl.set_html "<!begin:t><!end:t>"
+    assert_exception(ArgumentError) {
+      tmpl.node("t").expand({"hogevar" => "foo"})
+    }
+    assert_exception(ArgumentError) {
+      tmpl.expand({"t" => {"hogevar" => "foo"}})
+    }
+  end
+
+  # ÊÄ¤¸¤Æ¤¤¤Ê¤¤¥Î¡¼¥É¤Ï¥¨¥é¡¼
+  def test2
+    tmpl = HTML::Template.new
+    assert_exception(ArgumentError) {
+      tmpl.set_html "<!begin:t><!end:e>"
+    }
+  end
+
+  # ¥Î¡¼¥ÉÌ¾¤¬¸«¤Ä¤«¤é¤Ê¤¤¤È¥¨¥é¡¼
+  def test3
+    tmpl = HTML::Template.new
+    tmpl.set_html "<!begin:t><!end:t>"
+    assert_exception(ArgumentError) {
+      tmpl.node("hogenode")
+    }
+    assert_exception(ArgumentError) {
+      tmpl.expand({"hogenode" => {}})
+    }
+  end
+
+  # ÊÑ¿ô¤ÎÊÑ´¹
+  def test4
+    tmpl = HTML::Template.new
+    tmpl.set_html("<!var:foo>")
+    assert_equal("bar", tmpl.expand({"foo" => "bar"}).output)
+
+    # ¿ôÃÍ¤Ï¡¢¼«Æ°Åª¤ËÊ¸»úÎó¤ËÊÑ´¹¤¹¤ë
+    assert_equal("20", tmpl.expand({"foo" => 20}).output)
+  end
+
+  def sub_t11
+    tmpl = HTML::Template.new
+    tmpl.set_html(<<EOF)
+<!begin:t><!var:foo><!end:t>
+EOF
+    return tmpl
+  end
+
+  # ¥Î¡¼¥É: node()¤òÄÌ¤¹¤È¡¤¤½¤Î¥Î¡¼¥É¤ÏÅ¸³«¤·¤Ê¤¤
+  def test5
+    tmpl = sub_t11
+    o = tmpl.node("t").expand({"foo" => "bar"}).output
+    assert_equal("", o)
+    o = tmpl.expand({}).output
+    assert_equal("bar\n", o)
+  end
+
+  # expand()¤ÎÃæ¤Ë¥Î¡¼¥É¤ò½ñ¤¯¤È¡¤Ä¾ÀÜ¤½¤Î¥Î¡¼¥É¤òÅ¸³«¤¹¤ë
+  def test6
+    tmpl = sub_t11
+    o = tmpl.expand({"t" => {"foo" => "bar"}}).output
+    assert_equal("bar\n", o)
+  end
+
+  # '<'¤ä'>'¤Ï¥¨¥¹¥±¡¼¥×¤µ¤ì¤Ê¤¤¡£
+  def test7
+    tmpl = HTML::Template.new.set_html("<!var:foo>").expand({"foo" => "<tag>"})
+    assert_equal("<tag>", tmpl.output)
+  end
+
+  # ÃÍ¤È¤·¤Æ±øÀ÷¤µ¤ì¤¿Ê¸»úÎó¤òÅÏ¤·¤Æ¤â¥¨¥é¡¼¤Ë¤Ï¤Ê¤é¤Ê¤¤¡£
+  # ¤³¤ì¤ò¤¤¤Á¤¤¤Á¥¨¥é¡¼¤Ë¤·¤Æ¤¤¤¿¤é¡¢¤«¤¨¤Ã¤Æ¥ß¥¹¤òÍ¶È¯¤·¤½¤¦¡£
+  def test8
+    tmpl = HTML::Template.new.set_html("<!var:foo>")
+    assert_equal("bar", tmpl.expand({"foo" => "bar".taint}).output)
+  end
+end
+
+RUNIT::CUI::TestRunner.run(Test1.suite)
