Trans
2/16/2007 9:23:00 PM
On Feb 16, 2:06 pm, ara.t.how...@noaa.gov wrote:
> On Sat, 17 Feb 2007, Trans wrote:
>
> >> 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>"
>
> right, but with that approach, or that of markaby, tags like 'p', 'id',
> 'size', et all are clobbered. with builder they've solved this by making the
> user pass the builder to all blocks, but that's a lot of typing!
Well, that's partly true. BuildingBlock removes all but a few methods,
so 'p', 'id', and 'size' are fine. In any case, while the underscore
notation you present is the least clobbering of all of them, in the
end there are always some cases that one must use the special call for
(eg, #_ or #tag!). it's just a matter of little more or a little less,
and a few extra feautres along the way (for example, markaby can
calsses added more easily: h1.big "Hello World"). btw, i think markaby
is built ontop of builder too, oddly enough.
anyway, i'm not trying to be argumentative or anything. i'm just
saying that I think, on the whole, each of these solutions about as
good as any other.
T.