From: "Andrew S. Townley" Date: 2009-03-27T20:16:16+09:00 Subject: Re: [ANN] tagz-5.0.0 On Fri, 2009-03-27 at 02:28 +0900, ara.t.howard wrote: > On Mar 26, 2009, at 5:43 AM, Andrew S. Townley wrote: > if that's the case i might roll something like that into tagz. That would be fantastic. > i'll post any other ideas i have here - really appreciate the feedback! I'm looking at trying to figure out how to do the emit stuff, and I think that the Namespace class should certainly be part of Tagz. New would do something similar to your example, but with also adding the Namespace URI, e.g. (example from http://www.w3schools.com/Xforms/xforms_namespace.asp) include Tagz.globally xhtml = Tagz::Namespace.new(:xhtml => "http://www.w3.org/1999/xhtml") xf = Tagz::Namespace.new(:xf => "http://www.w3.org/2002/xforms") etc. I tried to do this based on the example you provided, but I'm getting an error I don't understand. I'm sure it's due to scoping issues, but I've no idea how to fix it. I also discovered that output of empty elements doesn't behave as I'd expect. If you do empty_element_ you get "" rather than "" I think this can be fixed easily with a check to see if the value of tagz is empty on line 62. Any ideas as to what's going on? excalibur$ cat /tmp/a.rb require 'rubygems' require 'tagz' class Namespace def initialize hash, &block @prefix, @uri = hash.inject([]) { |a, (k, v)| a << k << v } @context = block @self = eval 'self', block end instance_methods.each{|m| undef_method if m[%r/__/]} def emit_ns { "xmlns:#{ @prefix }".to_sym => "#{@uri}" } end def method_missing m, *a, &b if m.to_s[%r/^_|_$/] @self.send("#{ @prefix }:#{ m }", *a, &b) else "#{ @prefix }:#{ m }" end end end include Tagz.globally xhtml = Namespace.new(:xhtml => "http://www.w3.org/1999/xhtml") xf = Namespace.new(:xf => "http://www.w3.org/2002/xforms") puts xhtml.emit_ns.inspect puts xf.emit_ns.inspect # BUG!! puts empty_element_ doc = xhtml.html_(xhmtl.emit_ns, xf.emit_ns) { xhtml.head_{ xhtml.title_ "Important Document" xf.model_{ xf.instance_{ person_{ fname_ lname_ } } } xf.submission(:id => "form1", :method => "get", :action => "doit.jsp") } xhtml.body_{ "..." } } excalibur$ ruby /tmp/a.rb {:"xmlns:xhtml"=>"http://www.w3.org/1999/xhtml"} {:"xmlns:xf"=>"http://www.w3.org/2002/xforms"} /tmp/a.rb:38: undefined local variable or method `xhmtl' for # (NameError) -- Andrew S. Townley http://atownley.org