diff -Naur amrita-1.0.2.orig/lib/amrita/amx.rb amrita-1.0.2-cur/lib/amrita/amx.rb
--- amrita-1.0.2.orig/lib/amrita/amx.rb 2002-08-23 14:39:30.000000000 +0900
+++ amrita-1.0.2-cur/lib/amrita/amx.rb 2005-04-16 19:06:14.000000000 +0900
@@ -56,7 +56,7 @@
raise "unknown param #{f.type}"
end
- doc = REXML::Document.new(REXML::File.new(path))
+ doc = REXML::Document.new(File.open(path))
root = doc.elements['amx']
req = root.attributes['require']
require(req) if req
diff -Naur amrita-1.0.2.orig/lib/amrita/compiler.rb amrita-1.0.2-cur/lib/amrita/compiler.rb
--- amrita-1.0.2.orig/lib/amrita/compiler.rb 2003-01-05 16:54:44.000000000 +0900
+++ amrita-1.0.2-cur/lib/amrita/compiler.rb 2005-04-16 19:09:14.000000000 +0900
@@ -1,3 +1,6 @@
+
+if nil
+
require 'amrita/format'
@@ -599,7 +602,7 @@
e2.delete_attr!(:id)
end
- if e.no_child? and @static_formatter.can_be_single?(e)
+ if @static_formatter.empty_tag?(e)
self << @static_formatter.format_single_tag(e)
return
end
@@ -652,7 +655,7 @@
end
end
- _if("e.no_child? and #{dynamic_formatter_var_name}.can_be_single?(e)") do
+ _if("#{dynamic_formatter_var_name}.empty_tag?(e)") do
put_src "#{@dynamic_formatter_var_name} << #{@dynamic_formatter_var_name}.format_single_tag(e)"
_else do
if block_given?
@@ -725,7 +728,7 @@
else
e.body.compile(self)
end
- unless e.no_child? and @static_formatter.can_be_single?(e)
+ unless @static_formatter.empty_tag?(e)
self << @static_formatter.format_end_tag(e)
end
true
@@ -852,3 +855,5 @@
end
end
end
+
+end
diff -Naur amrita-1.0.2.orig/lib/amrita/format.rb amrita-1.0.2-cur/lib/amrita/format.rb
--- amrita-1.0.2.orig/lib/amrita/format.rb 2003-01-05 16:54:44.000000000 +0900
+++ amrita-1.0.2-cur/lib/amrita/format.rb 2005-04-29 18:43:36.000000000 +0900
@@ -136,9 +136,14 @@
# If set, text will be escaped by Sanitizer#sanitize_text
# Default is true.
attr_accessor :escape
+
+ # 真のとき、XMLモード。
+ # 偽のとき、HTMLモード。
+ attr_accessor :xml
# If set, single tag like
will be printed as
# Default is false
+ # xmlが真のときは、常にXMLスタイルで出力する。(asxml属性は無視される。)
attr_accessor :asxml
# If set, with no attribute will be deleted.
@@ -153,7 +158,7 @@
# All output is done by << method.
def initialize(stream="", tagdict=DefaultHtmlTagInfo, &element_filter)
@stream = stream
- @tagdict = tagdict
+ @tagdict = tagdict # validator
@escape = true
@asxml = false
@delete_span = true
@@ -202,14 +207,15 @@
self
end
- def format_attrs(attrarray, taginfo=nil) #:nodoc:
- return nil if attrarray.size == 0
- array = attrarray.collect do |a|
- flag = taginfo ? taginfo.url_attr?(a.key) : false
- format_attr(a, flag)
+ def format_attrs(element)
+ return nil if element.attrs.size == 0
+ array = element.attrs.collect do |a|
+ url_attr = !xml && @tagdict.url_attr?(element, a)
+ format_attr(a, url_attr)
end
array.join(" ")
end
+ private :format_attrs
def format_attr_default(a, flag) #:nodoc:
attrval = a.value
@@ -250,8 +256,7 @@
def format_start_tag(e) #:nodoc:
e = @element_filter.call(e) if @element_filter
- taginfo = @tagdict.get_tag_info(e.tagname_symbol)
- a = format_attrs(e.attrs, taginfo)
+ a = format_attrs(e)
if a
%Q[<#{e.tagname} #{a}>]
else
@@ -265,8 +270,8 @@
def format_single_tag(e) #:nodoc:
e = @element_filter.call(e) if @element_filter
- a = format_element_attrs(e)
- if asxml
+ a = format_attrs(e)
+ if xml || asxml
if a
%Q[<#{e.tagname} #{a} />]
else
@@ -287,30 +292,13 @@
@stream << text
text
end
-
- def can_be_single?(element) #:nodoc:
- taginfo_of_element(element).can_be_empty
- end
-
- def format_attr_of_element(attr, element)
- taginfo = taginfo_of_element(element)
- format_attr(attr, taginfo && taginfo.url_attr?(attr.key))
- end
-
- def format_element_attrs(element)
- format_attrs(element.attrs, taginfo_of_element(element))
- end
-
- def taginfo_of_element(element)
- @tagdict.get_tag_info(element.tagname_symbol)
- end
end
# This Formatter print out template with no change.
class AsIsFormatter < Formatter
def format_element(element, stream=nil, &block) #:nodoc:
with_stream(stream) do
- if element.no_child? and can_be_single?(element)
+ if !xml && @tagdict.empty_tag?(element) || xml && element.no_child?
@stream << format_single_tag(element)
else
@stream << format_start_tag(element)
@@ -339,7 +327,7 @@
def format_element(element, stream=nil, &block) #:nodoc:
with_stream(stream) do
- if element.no_child? and can_be_single?(element)
+ if !xml && @tagdict.empty_tag?(element) || xml && element.no_child?
@stream << format_single_tag(element)
else
@stream << format_start_tag(element)
@@ -377,7 +365,11 @@
with_stream(stream) do
body = element.body
pptype = @tagdict.get_tag_info(element.tagname_symbol).pptype
- unless element.no_child? and can_be_single?(element)
+ if !xml && @tagdict.empty_tag?(element) || xml && element.no_child?
+ s = format_single_tag(element)
+ put(s)
+ new_line unless pptype == 3
+ else
first = format_start_tag(element)
last = format_end_tag(element)
@@ -388,11 +380,6 @@
body.format(self)
end
end
-
- else
- s = format_single_tag(element)
- put(s)
- new_line unless pptype == 3
end
end
end
@@ -484,7 +471,7 @@
when String
@result_str << x
when NodeArray
- x.array.each do |n|
+ x.each do |n|
n.pre_format1(self)
end
when Node
diff -Naur amrita-1.0.2.orig/lib/amrita/node.rb amrita-1.0.2-cur/lib/amrita/node.rb
--- amrita-1.0.2.orig/lib/amrita/node.rb 2002-12-28 16:45:50.000000000 +0900
+++ amrita-1.0.2-cur/lib/amrita/node.rb 2005-04-16 18:36:31.000000000 +0900
@@ -118,7 +118,7 @@
# AttrArray#== concerns the order of Attr
def ==(x)
- return true if id == x.id
+ return true if object_id == x.object_id
return false unless x.kind_of?(AttrArray)
each_with_index do |a, n|
return false unless a == x[n]
@@ -376,7 +376,7 @@
# doesn't concern the order of attributes
def ==(x)
return false unless x.kind_of?(Element)
- return true if x.id == id
+ return true if x.object_id == object_id
return false unless x.tagname_symbol == @tagname
return false unless x.attrs.size == @attrs.size
@attrs.each do |a|
@@ -581,11 +581,10 @@
# represents an Array of Node. It is a Node also.
class NodeArray
include Node
- attr_reader :array
+
def initialize(*elements)
if elements.size() == 1 and elements[0].kind_of?(NodeArray)
- a = elements[0]
- @array = a.array.collect { |n| n.clone }
+ @array = elements[0].to_a.collect {|n| n.clone}
else
@array = elements.collect do |a|
#raise "can't be a parent of me!" if a.id == self.id # no recusive check because it costs too much
@@ -595,7 +594,6 @@
end
def ==(x)
- return false unless x.kind_of?(NodeArray)
case x
when NodeArray, Array
return false unless x.size() == @array.size()
@@ -620,6 +618,14 @@
@array.empty?
end
+ def each
+ @array.each {|e| yield e}
+ end
+
+ def to_a
+ @array.dup
+ end
+
def clone
NodeArray.new(self)
end
@@ -668,14 +674,14 @@
# end tag
def etag
case @tag
- when '%=', '%'
- '%'
when '!'
''
when '!--'
'--'
when '?'
'?'
+ when '![CDATA['
+ ']]'
else
@tag
end
diff -Naur amrita-1.0.2.orig/lib/amrita/node_expand.rb amrita-1.0.2-cur/lib/amrita/node_expand.rb
--- amrita-1.0.2.orig/lib/amrita/node_expand.rb 2002-10-23 22:38:08.000000000 +0900
+++ amrita-1.0.2-cur/lib/amrita/node_expand.rb 2005-04-16 18:40:44.000000000 +0900
@@ -64,7 +64,12 @@
class String #:nodoc:
def amrita_expand_element(e, context)
ret = e.clone { Amrita::Node::to_node(self) }
- context.filter_element(ret)
+ if context.expand_attr
+ context.filter_element(ret)
+ else
+ new_elem = context.filter_element(ret, false)
+ new_elem.expand_attr!({}, context)
+ end
end
def amrita_expand_node(n, context)
@@ -86,16 +91,22 @@
end
def amrita_expand_node(n, context)
- raise Amrita::ModelMisMatch(type, n.type)
+ raise Amrita::ModelMisMatch(type, n.class)
end
end
module Amrita
module DictionaryData #:nodoc:
+ # ヘラチヌ、ナクウォ、ケ、。」
+ # e Element・、・・ケ・ソ・・ケ
def amrita_expand_element(e, context)
hid = e.hid
new_elem = context.filter_element(e.clone, false)
- new_elem.expand_attr!(self, context) if context.expand_attr
+ if context.expand_attr
+ new_elem.expand_attr!(self, context)
+ else
+ new_elem.expand_attr!(self, context) if !hid
+ end
if hid =~ /^\w+$/
d = amrita_get_data(hid.intern, e, context)
new_elem.expand1(d, context)
@@ -107,16 +118,8 @@
end
end
- def amrita_expand_attr(e, context) #:nodoc:
- e.attrs.each do |attr|
- next if attr.key_symbol == :id
- next unless attr.value
- if attr.value[0] == ?@
- e[attr.key_symbol] = amrita_get_data(attr.value[1..-1].intern, e, context)
- end
- end
- end
-
+ # ヘラチヌーハウー、ナクウォ、ケ、
+ # n Elementーハウー、ホNode・オ・ヨ・ッ・鬣ケ・、・・ケ・ソ・・ケ
def amrita_expand_node(n, context)
n.apply_to_children do |child|
child.expand1(self, context)
@@ -128,6 +131,8 @@
class Hash #:nodoc:
include Amrita::DictionaryData
+ # key idツータュテヘ、ホ・キ・・ワ・
+ # element Element・ェ・ヨ・ク・ァ・ッ・ネ
def amrita_get_data(key, element, context)
if context.hash_key_is_string
self[key.to_s] or self[key]
@@ -256,7 +261,7 @@
end
def amrita_expand_node(n, context)
- raise Amrita::ModelMisMatch(type, n.type)
+ raise Amrita::ModelMisMatch(type, n.class)
end
end
@@ -273,7 +278,7 @@
when DictionaryData
expand1(data, context)
else
- raise "Amrita::Node#expand accepts only Hash or ExpandByMember as model data (#{data.type} was passed)"
+ raise "Amrita::Node#expand accepts only Hash or ExpandByMember as model data (#{data.class} was passed)"
end
end
@@ -331,6 +336,7 @@
self[attr.key_symbol] = data.amrita_get_data(attr.value[1..-1].intern, self, context)
end
end
+ self
end
def apply_to_children(&block)
diff -Naur amrita-1.0.2.orig/lib/amrita/parser.rb amrita-1.0.2-cur/lib/amrita/parser.rb
--- amrita-1.0.2.orig/lib/amrita/parser.rb 2002-10-15 16:48:04.000000000 +0900
+++ amrita-1.0.2-cur/lib/amrita/parser.rb 2005-04-10 14:03:35.000000000 +0900
@@ -1,4 +1,6 @@
+# -*- encoding:euc-jp -*-
+
require 'strscan'
require "amrita/node"
require "amrita/tag"
@@ -67,6 +69,8 @@
[:tag, ret]
end
+ NAME_RE = /([A-Za-z:_][\w.:-]*)/
+
def state_text
t = @sc.scan(/\A[^<]*/m)
if t
@@ -92,7 +96,7 @@
raise "can't happen" unless l == 1
@sc.skip(/\A\s+/m)
- if t = @sc.scan(/\A[\/\w]+/)
+ if t = @sc.scan(/\A\/?#{NAME_RE}/)
@state = method(:state_space)
@tagname = t
nil
@@ -116,7 +120,7 @@
if @sc.scan(/\A>|\/>/)
@state = method(:state_text)
generate_tag
- elsif t = @sc.scan(/\A[\w-]+/m)
+ elsif t = @sc.scan(/\A#{NAME_RE}/m)
@attrname = t
@state = method(:state_attrname)
nil
@@ -127,7 +131,7 @@
def state_attrname
@sc.skip(/\A\s*/m)
- if t = @sc.scan(/\A[\w-]+/m)
+ if t = @sc.scan(/\A#{NAME_RE}/m)
@attrname = t
@state = method(:state_before_equal)
nil
@@ -152,7 +156,7 @@
@attrs << [@attrname, nil]
@state = method(:state_text)
generate_tag
- elsif t = @sc.scan(/\A\w+/)
+ elsif t = @sc.scan(/\A#{NAME_RE}/)
@attrs << [@attrname, nil]
@attrvalue = ""
@attrname = t
diff -Naur amrita-1.0.2.orig/lib/amrita/parts.rb amrita-1.0.2-cur/lib/amrita/parts.rb
--- amrita-1.0.2.orig/lib/amrita/parts.rb 2002-10-24 14:23:25.000000000 +0900
+++ amrita-1.0.2-cur/lib/amrita/parts.rb 2005-04-29 19:27:07.000000000 +0900
@@ -75,8 +75,8 @@
parts_mod.module_eval {
include Amrita
include PartsTemplate
- include HtmlCompiler::RuntimeRoutines
- extend HtmlCompiler::RuntimeRoutines
+ #include HtmlCompiler::RuntimeRoutines
+ #extend HtmlCompiler::RuntimeRoutines
}
compile_partstemplate(parts_mod, e, cls_name)
end
diff -Naur amrita-1.0.2.orig/lib/amrita/tag.rb amrita-1.0.2-cur/lib/amrita/tag.rb
--- amrita-1.0.2.orig/lib/amrita/tag.rb 2002-10-22 17:10:31.000000000 +0900
+++ amrita-1.0.2-cur/lib/amrita/tag.rb 2005-04-29 19:20:15.000000000 +0900
@@ -65,12 +65,12 @@
# If true, it will be printed
xxxxx
', ret) end @@ -196,33 +196,33 @@ tmpl = HtmlParser.parse_text "xxxx
" f = AsIsFormatter.new(nil) r = tmpl.pre_format(f).result - assert_equal(Element, r.type) + assert_equal(Element, r.class) assert_equal('e(:p,a(:id, "x")) { "xxxx" }', r.to_ruby) tmpl = HtmlParser.parse_text "xxxx
yyyy
" f = AsIsFormatter.new(nil) r = tmpl.pre_format(f).result - assert_equal(Array, r.type) + assert_equal(Array, r.class) assert_equal('xxxx
', r[0]) assert_equal('e(:p,a(:id, "x")) { "yyyy" }', r[1].to_ruby) tmpl = HtmlParser.parse_text "xxxx
yyyy
" f = AsIsFormatter.new(nil) r = tmpl.pre_format(f).result - assert_equal(Array, r.type) + assert_equal(Array, r.class) assert_equal('e(:p,a(:id, "x")) { "xxxx" }', r[0].to_ruby) assert_equal('yyyy
', r[1]) tmpl = HtmlParser.parse_text "xxxyyyzzz" f = AsIsFormatter.new(nil) r = tmpl.pre_format(f).result - assert_equal(Amrita::SanitizedString, r.type) + assert_equal(Amrita::SanitizedString, r.class) assert_equal('xxxyyyzzz', r) tmpl = HtmlParser.parse_text "xxxyyyzzz
" f = AsIsFormatter.new(nil) r = tmpl.pre_format(f).result - assert_equal(Element, r.type) + assert_equal(Element, r.class) assert_equal('xxxyyyzzz', r.body.to_s) end @@ -273,15 +273,15 @@ tmpl = HtmlParser.parse_text 'yyy' pre = tmpl.pre_format(f).result - assert_equal(Amrita::SanitizedString, pre.type) + assert_equal(Amrita::SanitizedString, pre.class) assert_equal('yyy', pre) pre = tmpl.pre_format(f, true).result - assert_equal(Amrita::Element, pre.type) + assert_equal(Amrita::Element, pre.class) assert_equal(e(:a,a(:href, "@xxx")) { "yyy" }, pre) data = { :xxx=>"http://www.ruby-lang.org/" } - assert_equal(e(:a,a(:href, "@xxx")) { "yyy" }, pre.expand(data)) + assert_equal(e(:a,a(:href, "http://www.ruby-lang.org/")) { "yyy" }, pre.expand(data)) assert_equal(tmpl.expand(data), pre.expand(data)) context = Amrita::ExpandContext.new diff -Naur amrita-1.0.2.orig/test/testformat2.rb amrita-1.0.2-cur/test/testformat2.rb --- amrita-1.0.2.orig/test/testformat2.rb 2002-08-02 16:27:34.000000000 +0900 +++ amrita-1.0.2-cur/test/testformat2.rb 2005-04-16 18:27:30.000000000 +0900 @@ -186,7 +186,7 @@sample_text
' @@ -39,7 +39,7 @@ t.use_compiler = true result = "" data = { :list => [1, 2, 3] } - t.set_hint(HashData[:list=>ArrayData[ScalarData]]) + #t.set_hint(HashData[:list=>ArrayData[ScalarData]]) t.expand(result, data) assert_equal('aaa
", result) + assert_equal("aaa
\n", result) ensure File::unlink(tempfile) end @@ -133,7 +133,7 @@ assert_equal('aaa
', result) result = "" - t.set_hint(HashData[:a=>ScalarData]) + #t.set_hint(HashData[:a=>ScalarData]) t.expand(result, { :a=>"aaa" }) #puts t.src assert_equal('aaa
', result) @@ -149,7 +149,7 @@ assert_equal('aaa
', result) result = "" - t.set_hint(HashData[:a=>ScalarData]) + #t.set_hint(HashData[:a=>ScalarData]) t.expand(result, { :a=>"aaa" }) #puts t.src assert_equal('aaa
', result) @@ -165,7 +165,7 @@ assert_equal('aaa
', result) result = "" - t.set_hint(HashData[:a=>ScalarData]) + #t.set_hint(HashData[:a=>ScalarData]) t.expand(result, { :a=>"aaa" }) #puts t.src assert_equal('aaa
', result) @@ -181,7 +181,7 @@ assert_equal('aaa
yyy', result) result = "" - t.set_hint(HashData[:a=>ScalarData]) + #t.set_hint(HashData[:a=>ScalarData]) t.expand(result, { :a=>"aaa" }) #puts t.src assert_equal('aaa
yyy', result) @@ -245,7 +245,7 @@ t = TemplateFileWithCache.new(tempfile) - assert_equal(SourceCache, t.cache_manager.type) + assert_equal(SourceCache, t.cache_manager.class) t.use_compiler = true assert_equal(true, t.need_update?) result = "" diff -Naur amrita-1.0.2.orig/test/testxml.rb amrita-1.0.2-cur/test/testxml.rb --- amrita-1.0.2.orig/test/testxml.rb 2002-10-22 17:10:31.000000000 +0900 +++ amrita-1.0.2-cur/test/testxml.rb 2005-04-16 19:07:23.000000000 +0900 @@ -39,7 +39,17 @@