Question about Amrita

Hi,

I have a question about amrita.
(amrita is a XML/HTML based template engine,
see
http://www.brain-tokyo.jp/research/amrita/index.html
)

I’m now trying amrita and create a sample program.

···

require 'amrita/template’
include Amrita

t = TemplateText.new <<END

END

links = [
{ :lang=>a(:href=>‘http://www.ruby-lang.org’){“ruby”} },
{ :lang=>a(:href=>‘http://www.python.org’) {“python”} },
{ :lang=>a(:href=>‘http://www.perl.org’) {“perl”} },
]
data = { :links=>links }
t.expand(STDOUT, data)

This works fine. Here is output.

ruby
python
perl
----------------------------------------

And, I want to generate a colored row table, like this:

ruby
python
perl
----------------------------------------

But I don’t know how to write an amrita code :-<

In other words, what I want to do is to add an attribute
’class’ to ‘

’.
I can add attributes to ‘’ with a() method,
but cannot add to ‘’.

If you are an amrita user, please give me an advice.

regards
makotz kuwata

sample/tour/proc.rb in the Amrita distribution does what you want, setting
element attributes explicitly. See section entitled “proc” at:
http://www.brain-tokyo.jp/research/amrita/rdocs/files/docs/Tour.html

sample/hello/conditional.rb shows another way to achieve different HTML for
odd/even rows, although in this case you’ll probably end up with an extra

around each table row. It relies on the fact that if a particular id is missing (or points to nil or false) it is removed.

links = [
{ :odd=> {:lang=>a(:href=>‘http://www.ruby-lang.org’) {“ruby”} } },
{ :even=>{:lang=>a(:href=>‘http://www.python.org’) {“python”} } },
{ :odd=> {:lang=>a(:href=>‘http://www.perl.org’) {“perl”} } },
]

Regards,

Brian.

···

On Mon, Mar 17, 2003 at 02:39:25AM +0900, makotz wrote:

And, I want to generate a colored row table, like this:

ruby
python
perl
----------------------------------------

But I don’t know how to write an amrita code :-<

In other words, what I want to do is to add an attribute
‘class’ to ‘’.
I can add attributes to ‘’ with a() method,
but cannot add to ‘’.

In other words, what I want to do is to add an attribute
I can add attributes to ‘’ with a() method,
but cannot add to ‘’.

Actually you can. Try this in your original code:

links = [
a(:class=>‘odd’) { {:lang=>a(:href=>‘
http://www.ruby-lang.org’) {“ruby”} }},
a(:class=>‘even’) { {:lang=>a(:href=>‘http://www.python.org’) {“python”}}},
a(:class=>‘odd’) { {:lang=>a(:href=>‘http://www.perl.org’) {“perl”} }},
]

The method ‘a’ doesn’t refer to the (anchor) tag, it refers to an
AttrArray object.

Cheers,

Brian.

Brian Candler B.Candler@pobox.com wrote in message news:20030316193632.GA58317@uk.tiscali.com

links = [
a(:class=>‘odd’) { {:lang=>a(:href=>‘http://www.ruby-lang.org’) {“ruby”} }},
a(:class=>‘even’) { {:lang=>a(:href=>‘http://www.python.org’) {“python”}}},
a(:class=>‘odd’) { {:lang=>a(:href=>‘http://www.perl.org’) {“perl”} }},
]

Great! This is what I want!
Thank you very much.

and this code is OK in amrita 1.0.2 but NG in 1.8.0.

sample/tour/proc.rb in the Amrita distribution does what you want, setting
element attributes explicitly. See section entitled “proc” at:
http://www.brain-tokyo.jp/research/amrita/rdocs/files/docs/Tour.html

I have read it. It is hard for me to understand.

···

t = TemplateText.new <<END

END

links = [
Proc.new {|elem| elem[:class]=“odd”; …what to do?..; elem },
Proc.new {|elem| elem[:class]=“even”; …what to do?..; elem },
Proc.new {|elem| elem[:class]=“odd”; …what to do?..; elem },
]

regards
makotz

links = [
{:lang=>proc {|elem| elem[:class] = “odd”; elem.set_text(“ruby”); elem } },
{:lang=>proc {|elem| elem[:class] = “even”; elem.set_text(“python”); elem } },
{:lang=>proc {|elem| elem[:class] = “odd”; elem.set_text(“perl”); elem } },
]

Regards,

Brian.

···

On Mon, Mar 17, 2003 at 01:20:38PM +0900, makotz wrote:

sample/tour/proc.rb in the Amrita distribution does what you want, setting
element attributes explicitly. See section entitled “proc” at:
http://www.brain-tokyo.jp/research/amrita/rdocs/files/docs/Tour.html

I have read it. It is hard for me to understand.


t = TemplateText.new <<END

END

links = [
Proc.new {|elem| elem[:class]=“odd”; …what to do?..; elem },
Proc.new {|elem| elem[:class]=“even”; …what to do?..; elem },
Proc.new {|elem| elem[:class]=“odd”; …what to do?..; elem },

This is a bug of amrita 1.8.0 and I fixed it. The next release will be
OK with this code.

And amrita V2.0 provides a new feature called ‘Amulet’. With Amulet,
you can do the same thing keeping clean seperation of model and view.

···

At Mon, 17 Mar 2003 13:20:38 +0900, makotz wrote:

Brian Candler B.Candler@pobox.com wrote in message news:20030316193632.GA58317@uk.tiscali.com

links = [
a(:class=>‘odd’) { {:lang=>a(:href=>‘http://www.ruby-lang.org’) {“ruby”} }},
a(:class=>‘even’) { {:lang=>a(:href=>‘http://www.python.org’) {“python”}}},
a(:class=>‘odd’) { {:lang=>a(:href=>‘http://www.perl.org’) {“perl”} }},
]

Great! This is what I want!
Thank you very much.

and this code is OK in amrita 1.0.2 but NG in 1.8.0.


require ‘amrita/template’
include Amrita

t = TemplateText.new <<END

dummy data
dummy data
END

t.define_amulet(:row, :row2)

links = [
t[:row][{:lang=>a(:href=>‘http://www.ruby-lang.org’){“ruby”} }],
t[:row2][{:lang=>a(:href=>‘http://www.python.org’) {“python”} }],
t[:row][{:lang=>a(:href=>‘http://www.perl.org’) {“perl”}}],
]

t.expand(STDOUT, :row=>links)

This code makes same result and you can adjust the color or any
appearance of each row touching only the template without running
or modifying the code.

I wrote some pages to amrita-Wiki from this thread.

http://www.walrus-ruby.org/aswiki/aswiki.cgi?c=v;p=EvenOddRow
http://www.walrus-ruby.org/aswiki/aswiki.cgi?c=v;p=Amulet

For detail of Amulet, see them.

Thank you for a useful question.


Taku Nakajima
http://www.walrus-ruby.org/amrita/