On Feb 16, 12:34 pm, "Tim Pease" <tim.pe... / gmail.com> wrote: > On 2/16/07, ara.t.how... / noaa.gov <ara.t.how... / noaa.gov> wrote: > > > > > On Sat, 17 Feb 2007, Tim Pease wrote: > > > > On 2/16/07, ara.t.how... / noaa.gov <ara.t.how... / noaa.gov> wrote: > > > >> NAME > > > >> xx > > > > For some reason I want a Mexican beer at lunch now ;) > > > > Clever use of method missing, though. Can this package generate XML > > > tags that contain a dash '-' character? > > > > TwP > > > harp:~ > cat a.rb > > require "xx" > > include XX::XML > > > legs = 1,2,3,4 > > > doc = xml_{ > > _('furniture:table'){ > > legs.each do |leg| > > _ "furniture:leg-#{ leg }", leg > > end > > } > > } > > > puts doc.pretty > > > harp:~ > ruby a.rb > > <?xml version='1.0'?> > > <furniture:table> > > <furniture:leg-1>1</furniture:leg-1> > > <furniture:leg-2>2</furniture:leg-2> > > <furniture:leg-3>3</furniture:leg-3> > > <furniture:leg-4>4</furniture:leg-4> > > </furniture:table> > > > cheers. > > So simple! The XML namespace example should have clued me in -- need > more coffee. > > As Tim Becker mentioned, this is a lot like Markaby, but it fixes some > of Markaby's shortcomings -- mainly support for valid XML tag > characters not currently allowed in method_missing and/or symbols. markaby has #tag! which is same as #_ however (AFAICT) markaby does html, not xml. the builder pattern is pretty common now. Facets has a class one can use to build any kind you'd like called BuildingBlock. you simply apply a helper object for specially defined "tags" and the method to use as the default. Very basic example: require 'facets/more/buildingblock' module BasicXMLMarkup extend self def element( tag, body=nil, atts={} ) atts = atts.collect{ |k,v| %{ #{k}="#{v}"} }.join('') if body "<#{tag}#{atts}>#{body}</#{tag}>" else "<#{tag}#{atts} />" end end end builder = BuildingBlock.new(BasicXMLMarkup, :element) builder.html do h1 "Hello World", :class=>"big" end produces "<html><h1 class=\"big\">Hello World</h1></html>" BuildingBlock is not limited to XML type markups. you can use BuildingBlock to make other types of builders too. an Outline bulder for instance should be pretty easy (you can use the to_roman method ;) T.