From: ahoward Date: 2003-06-12T04:55:25+09:00 Subject: Re: amrita question On Thu, 12 Jun 2003, Pierre Baillet wrote: > Hi, > > Using Amrita 1.0.2, I've got a small html snippet: > >
/> > > I'd like to fill the href for the a, the src for the img, and some text > inside the div. > > So far, i've got > > data = { :thumb_pic => a(:src => 'image.png'), :title => name, > :main_elt=> a(:href=> 'http://www.google.com') } > > This doesn't work ; > I only got the href filled up correctly... > > Any clue ? /tmp > cat amrita.rb require 'amrita/template' include Amrita TEMPLATE = <<-html
html model = Hash[ :main_elt => a(:href => 'http://www.google.com') do Hash[ :thumb_pic => a(:src => 'image.png'), :title => 'name', ] end ] (TemplateText.new TEMPLATE).expand STDOUT, model /tmp > ruby amrita.rb
name
Amrita::a() can take a block. if a the calling the block returns a string that string is used to replace body of the tag wholesale, if the block returns a hash, it is used to fill in any nested template - like you have. you could also write the model as: model = { # a hash :main_elt => a(:href => 'http://www.google.com') { # a block # the block returns a hash {:thumb_pic => a(:src => 'image.png'), :title => 'name'} } } -a -- ==================================== | Ara Howard | NOAA Forecast Systems Laboratory | Information and Technology Services | Data Systems Group | R/FST 325 Broadway | Boulder, CO 80305-3328 | Email: ara.t.howard@noaa.gov | Phone: 303-497-7238 | Fax: 303-497-7259 | ~ > ruby -e 'p(%.\x2d\x29..intern)' ====================================