[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

[ANN] xx-2.0.0

Ara.T.Howard

2/16/2007 8:12:00 AM

10 Answers

Tim Pease

2/16/2007 4:54:00 PM

0

On 2/16/07, ara.t.howard@noaa.gov <ara.t.howard@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

Tim Becker

2/16/2007 5:12:00 PM

0

Sort of reminds me of Markaby:
http://markaby.ruby...

Ara.T.Howard

2/16/2007 5:16:00 PM

0

James Gray

2/16/2007 5:21:00 PM

0

On Feb 16, 2007, at 11:11 AM, Tim Becker wrote:

> Sort of reminds me of Markaby:
> http://markaby.ruby...

Or Builder:

http://raa.ruby-lang.org/projec...

James Edward Gray II

Ara.T.Howard

2/16/2007 5:25:00 PM

0

Tim Pease

2/16/2007 5:35:00 PM

0

On 2/16/07, ara.t.howard@noaa.gov <ara.t.howard@noaa.gov> wrote:
> On Sat, 17 Feb 2007, Tim Pease wrote:
>
> > On 2/16/07, ara.t.howard@noaa.gov <ara.t.howard@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.

Thanks Ara. Thanks Dan.

TwP

Trans

2/16/2007 6:56:00 PM

0



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.


Ara.T.Howard

2/16/2007 7:07:00 PM

0

Trans

2/16/2007 9:23:00 PM

0



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.


Ara.T.Howard

2/16/2007 9:37:00 PM

0