[lnkForumImage]
TotalShareware - Download Free Software

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


 

Forums >

comp.lang.ruby

[ANN] tagz-4.2.0 - giraffe slayer

ara.t.howard

5/8/2008 6:38:00 PM


NAME

tagz.rb

SYNOPSIS

require Tagz

include Tagz.globally

a_(:href => "/foo"){ "bar" } #=> <a href="/foo">bar</a>

DESCRIPTION

tagz.rb is generates html, xml, or any sgml variant like a small
ninja
running across the backs of a herd of giraffes swatting of heads
like a
mark-up weedwacker. weighing in at less than 200 lines of code
tagz.rb adds
an html syntax to ruby that is both unobtrusive, safe, and available
globally to objects without the need for any builder or superfluous
objects.
tagz.rb is designed for applications that generate html to be able
to do so
easily in any context without heavyweight syntax or scoping issues,
like a
ninja sword through butter.

INSTALL

gem install tagz

HISTORY

4.2.0
- general lib cleanup
- introduction of dual-mixin technique (Tagz.globally)
- few small bug fixes
- ninja tales
- fixed div_{ false }

SAMPLES

<========< samples/a.rb >========>

~ > cat samples/a.rb

#
# in the simplest case tagz generates html using a syntax which
safely mixes
# in to any object
#

require 'tagz'
include Tagz.globally

class GiraffeModel
def link
a_(:href => "/giraffe/neck/42"){ "whack!" }
end
end

puts GiraffeModel.new.link

~ > ruby samples/a.rb

<a href="/giraffe/neck/42">whack!</a>


<========< samples/b.rb >========>

~ > cat samples/b.rb

#
# tagz.rb mixes quite easily with your favourite templating
engine, avoiding
# the need for '<% rows.each do |row| %> ... <% row.each do |
cell| %> '
# madness and other types of logic to be coded in the templating
language,
# leaving templating to template engines and logic and looping to
ruby -
# unencumbered by extra funky syntax
#

require 'tagz'
include Tagz.globally

require 'erb'

rows = %w( a b c ), %w( 1 2 3 )

template = ERB.new <<-ERB
<html>
<body>
<%=

if rows

table_{
rows.each do |row|
tr_{
row.each do |cell|
td_{ cell }
end
}
end
}

end

%>
</body>
</html>
ERB

puts template.result(binding)


~ > ruby samples/b.rb

<html>
<body>
<table><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>1</
td><td>2</td><td>3</td></tr></table>
</body>
</html>


<========< samples/c.rb >========>

~ > cat samples/c.rb

#
# once you've learned to generate html using tagz you're primed
to generate
# xml too
#

require 'tagz'
include Tagz.globally

doc =
xml_{
giraffe_{ 'large' }
ninja_{ 'small' }
}

puts doc

~ > ruby samples/c.rb

<xml><giraffe>large</giraffe><ninja>small</ninja></xml>


<========< samples/d.rb >========>

~ > cat samples/d.rb

#
# tagz.rb doesn't cramp your style, allowing even invalid html to
be
# generated. note the use of the 'tagz' method, which can be
used both to
# capture output and to append content to the top of the stack.
#

require 'tagz'
include Tagz.globally

def header
tagz{
html_
body_(:class => 'ninja-like', :id => 'giraffe-slayer')

tagz << "\n<!-- this is the header -->\n"
}
end

def footer
tagz{
tagz << "\n<!-- this is the footer -->\n"

body_
html_
}
end

puts header, footer

~ > ruby samples/d.rb

<html><body class="ninja-like" id="giraffe-slayer">
<!-- this is the header -->

<!-- this is the footer -->
<body><html>


<========< samples/e.rb >========>

~ > cat samples/e.rb

#
# tagz.rb allows a safer method of mixin which requires any tagz
methods to be
# inside a tagz block - tagz generating methods outside a tagz
block will
# raise an error if tagz is included this way. also notice that
the error is
# reported from where it was raised - not from the bowels of the
the tagz.rb
# lib.
#

require 'tagz'
include Tagz

puts tagz{
html_{ 'works only in here' }
}

begin
html_{ 'not out here' }
rescue Object => e
p :backtrace => e.backtrace
end


~ > ruby samples/e.rb

<html>works only in here</html>
{:backtrace=>["samples/e.rb:17"]}


<========< samples/f.rb >========>

~ > cat samples/f.rb

#
# tagz.rb can generate really compact html. this is great to
save bandwidth
# but can sometimes make reading the generated html a bit rough.
of course
# using tidy or the dom inspector in firebug obviates the issue;
nevertheless
# it's sometime nice to break things up a little. you can use
'tagz << "\n"'
# or the special shorthand '__' to accomplish this
#

require 'tagz'
include Tagz.globally

p div_{
span_{ true }
__
span_{ false } # hey ryan, i fixed this ;-)
__
}

~ > ruby samples/f.rb

"<div><span>true</span>\n<span>false</span>\n</div>"



enjoy.


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




9 Answers

Adam Shelly

5/8/2008 7:46:00 PM

0

On 5/8/08, ara howard <ara.t.howard@gmail.com> wrote:
> DESCRIPTION
>
> tagz.rb is generates html, xml, or any sgml variant like a small ninja
> running across the backs of a herd of giraffes swatting of heads like a
> mark-up weedwacker. weighing in at less than 200 lines of code tagz.rb
> [...]
> like a ninja sword through butter.

It appears Ara has been visited by _why's Muse.

ara.t.howard

5/8/2008 8:06:00 PM

0


On May 8, 2008, at 1:46 PM, Adam Shelly wrote:
> It appears Ara has been visited by _why's Muse.

more like a small 1 year old girl, awake at 1 am, depriving dad of
sleep. the effect is the same though ;-)

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




matt

5/8/2008 11:27:00 PM

0

ara howard <ara.t.howard@gmail.com> wrote:

> NAME
>
> tagz.rb

Has the gem been updated?

Thx - m.

--
matt neuburg, phd = matt@tidbits.com, http://www.tidbits...
Leopard - http://www.takecontrolbooks.com/leopard-custom...
AppleScript - http://www.amazon.com/gp/product/...
Read TidBITS! It's free and smart. http://www.t...

ara.t.howard

5/8/2008 11:49:00 PM

0


On May 8, 2008, at 5:30 PM, matt neuburg wrote:
> Has the gem been updated?

hmm. it has, but didn't get pushed up. i'll do that now - should be
on rubyforge (but not mirrors) in a few minutes...

thanks for the heads up!

a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




ara.t.howard

5/8/2008 11:55:00 PM

0


On May 8, 2008, at 5:30 PM, matt neuburg wrote:
> Has the gem been updated?

cfp:~/src/ruby/tagz/tagz-4.2.0 > curl -s 'http://rubyforge.org/frs/?group_id=1024&release_id=...
|grep tagz|grep 4.2

<a href="/frs/download.php/36812/tagz-4.2.0.gem">tagz-4.2.0.gem</a></
td><td align="right" >9 KB</td><td align="right" >0</td><td >Any</
td><td >.gem (RubyGem)</td></tr>

<a href="/frs/download.php/36794/tagz-4.2.0.tgz">tagz-4.2.0.tgz</a></
td><td align="right" >13 KB</td><td align="right" >0</td><td >Any</
td><td >Source .zip</td></tr>


a @ http://codeforp...
--
we can deny everything, except that we have the possibility of being
better. simply reflect on that.
h.h. the 14th dalai lama




Tim Pease

5/9/2008 2:21:00 AM

0

On May 8, 2008, at 12:37 PM, ara howard wrote:
>
>
> HISTORY
>
> 4.2.0
> - general lib cleanup
> - introduction of dual-mixin technique (Tagz.globally)
> - few small bug fixes
> - ninja tales
> - fixed div_{ false }
>

Love the version number, Ara! I fee like my life has meaning now.

Blessings,
TwP

M. Edward (Ed) Borasky

5/9/2008 2:50:00 AM

0

ara howard wrote:
>
> NAME
>
> tagz.rb
>
> SYNOPSIS
>
> require Tagz
>
> include Tagz.globally
>
> a_(:href => "/foo"){ "bar" } #=> <a href="/foo">bar</a>
>
> DESCRIPTION
>
> tagz.rb is generates html, xml, or any sgml variant like a small ninja
> running across the backs of a herd of giraffes swatting of heads like a
> mark-up weedwacker. weighing in at less than 200 lines of code
> tagz.rb adds
> an html syntax to ruby that is both unobtrusive, safe, and available
> globally to objects without the need for any builder or superfluous
> objects.
> tagz.rb is designed for applications that generate html to be able to
> do so
> easily in any context without heavyweight syntax or scoping issues,
> like a
> ninja sword through butter.
>
> INSTALL
>
> gem install tagz
>
> HISTORY
>
> 4.2.0
> - general lib cleanup
> - introduction of dual-mixin technique (Tagz.globally)
> - few small bug fixes
> - ninja tales
> - fixed div_{ false }
>
> SAMPLES
>
> <========< samples/a.rb >========>
>
> ~ > cat samples/a.rb
>
> #
> # in the simplest case tagz generates html using a syntax which
> safely mixes
> # in to any object
> #
>
> require 'tagz'
> include Tagz.globally
>
> class GiraffeModel
> def link
> a_(:href => "/giraffe/neck/42"){ "whack!" }
> end
> end
>
> puts GiraffeModel.new.link
>
> ~ > ruby samples/a.rb
>
> <a href="/giraffe/neck/42">whack!</a>
>
>
> <========< samples/b.rb >========>
>
> ~ > cat samples/b.rb
>
> #
> # tagz.rb mixes quite easily with your favourite templating engine,
> avoiding
> # the need for '<% rows.each do |row| %> ... <% row.each do |cell| %> '
> # madness and other types of logic to be coded in the templating
> language,
> # leaving templating to template engines and logic and looping to
> ruby -
> # unencumbered by extra funky syntax
> #
>
> require 'tagz'
> include Tagz.globally
>
> require 'erb'
>
> rows = %w( a b c ), %w( 1 2 3 )
>
> template = ERB.new <<-ERB
> <html>
> <body>
> <%=
>
> if rows
>
> table_{
> rows.each do |row|
> tr_{
> row.each do |cell|
> td_{ cell }
> end
> }
> end
> }
>
> end
>
> %>
> </body>
> </html>
> ERB
>
> puts template.result(binding)
>
>
> ~ > ruby samples/b.rb
>
> <html>
> <body>
>
> <table><tr><td>a</td><td>b</td><td>c</td></tr><tr><td>1</td><td>2</td><td>3</td></tr></table>
>
> </body>
> </html>
>
>
> <========< samples/c.rb >========>
>
> ~ > cat samples/c.rb
>
> #
> # once you've learned to generate html using tagz you're primed to
> generate
> # xml too
> #
>
> require 'tagz'
> include Tagz.globally
>
> doc =
> xml_{
> giraffe_{ 'large' }
> ninja_{ 'small' }
> }
>
> puts doc
>
> ~ > ruby samples/c.rb
>
> <xml><giraffe>large</giraffe><ninja>small</ninja></xml>
>
>
> <========< samples/d.rb >========>
>
> ~ > cat samples/d.rb
>
> #
> # tagz.rb doesn't cramp your style, allowing even invalid html to be
> # generated. note the use of the 'tagz' method, which can be used
> both to
> # capture output and to append content to the top of the stack.
> #
>
> require 'tagz'
> include Tagz.globally
>
> def header
> tagz{
> html_
> body_(:class => 'ninja-like', :id => 'giraffe-slayer')
>
> tagz << "\n<!-- this is the header -->\n"
> }
> end
>
> def footer
> tagz{
> tagz << "\n<!-- this is the footer -->\n"
>
> body_
> html_
> }
> end
>
> puts header, footer
>
> ~ > ruby samples/d.rb
>
> <html><body class="ninja-like" id="giraffe-slayer">
> <!-- this is the header -->
>
> <!-- this is the footer -->
> <body><html>
>
>
> <========< samples/e.rb >========>
>
> ~ > cat samples/e.rb
>
> #
> # tagz.rb allows a safer method of mixin which requires any tagz
> methods to be
> # inside a tagz block - tagz generating methods outside a tagz block
> will
> # raise an error if tagz is included this way. also notice that the
> error is
> # reported from where it was raised - not from the bowels of the the
> tagz.rb
> # lib.
> #
>
> require 'tagz'
> include Tagz
>
> puts tagz{
> html_{ 'works only in here' }
> }
>
> begin
> html_{ 'not out here' }
> rescue Object => e
> p :backtrace => e.backtrace
> end
>
>
> ~ > ruby samples/e.rb
>
> <html>works only in here</html>
> {:backtrace=>["samples/e.rb:17"]}
>
>
> <========< samples/f.rb >========>
>
> ~ > cat samples/f.rb
>
> #
> # tagz.rb can generate really compact html. this is great to save
> bandwidth
> # but can sometimes make reading the generated html a bit rough. of
> course
> # using tidy or the dom inspector in firebug obviates the issue;
> nevertheless
> # it's sometime nice to break things up a little. you can use 'tagz
> << "\n"'
> # or the special shorthand '__' to accomplish this
> #
>
> require 'tagz'
> include Tagz.globally
>
> p div_{
> span_{ true }
> __
> span_{ false } # hey ryan, i fixed this ;-)
> __
> }
>
> ~ > ruby samples/f.rb
>
> "<div><span>true</span>\n<span>false</span>\n</div>"
>
>
>
> enjoy.
>
>
> a @ http://codeforp...
> --
> we can deny everything, except that we have the possibility of being
> better. simply reflect on that.
> h.h. the 14th dalai lama
>
>
>
>
>

Well ... if giraffes weren't endangered before, they are now. :)

P.S.: My WindowMaker desktop theme is called "Giraffe".

Phillip Gawlowski

5/9/2008 7:44:00 AM

0

-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

M. Edward (Ed) Borasky wrote:

|
| Well ... if giraffes weren't endangered before, they are now. :)
|
| P.S.: My WindowMaker desktop theme is called "Giraffe".

You obviously need its fork, WidowMaker. ;P

- --
Phillip Gawlowski
Twitter: twitter.com/cynicalryan
Blog: http://justarubyist.bl...

~ "I suppose the secret to happiness is learning to appreciate the
moment."
- -Calvin
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.8 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail....

iEYEARECAAYFAkgkAJ8ACgkQbtAgaoJTgL/ZggCgpkjaphImjgCyLhO/y0IAlkUj
EeIAnRgZNZlYcj6QWbyWj4EXWX+kXBe0
=4zhw
-----END PGP SIGNATURE-----

Phlip

5/9/2008 2:09:00 PM

0

Adam Shelly wrote:

> It appears Ara has been visited by _why's Muse.

http://whytheluckystiff.net/clog/wander/soYouWantToShootAGiraffeInTheFor...