From: "Ara.T.Howard" Date: 2003-12-19T15:51:57+09:00 Subject: Re: amrita question On Fri, 19 Dec 2003, Carl Youngblood wrote: > I am trying to nest one amrita template inside another. The problem I'm > having is that the one that gets nested gets sanitized so that all HTML tags > appear as literals. I thought one approach might be to turn off sanitizing > when I nest templates, but I figured there must be a better way of doing > this. What's the "amrita way" of doing it? Here is some sample code: > > # inner template > t = TemplateText.new <<-EOS >

List of messages

> > EOS > d = Hash.new > d[:list] = Array.new > messages_array.each do |msg| > d[:list] << { :msg => msg } > end > t.expand(msglist, d) > data[:msglist] = msglist > > # main template > tmpl.expand(STDOUT, data) how about: ~/eg/ruby > cat amrita0.rb require 'amrita' include Amrita # inner template it = TemplateText.new <<-html

List of messages

html # outer template ot = TemplateText.new <<-html html # build msglist data = Hash.new{|h,k| h[k] = []} messages = %w(one two three) messages.inject(data){|data, msg| data[:list] << {:msg => msg}; data} msglist = it.expand('', data) # build main page data = Hash.new data[:msglist] = noescape{ msglist } ot.expand(STDOUT, data) ~/eg/ruby > ruby amrita0.rb

List of messages

or: ~/eg/ruby > cat amrita1.rb require 'amrita' require 'amrita/parts' include Amrita module View class MsgList TEMPLATE = TemplateText.new <<-html

List of messages

html attr :list def initialize; @list = []; end def << msg; @list << {:msg => msg}; self; end end MsgList::TEMPLATE.install_parts_to self end msglist = View::MsgList.new msglist << 'one' << 'two' << 'three' t = TemplateText.new <<-html html t.expand STDOUT, {:msglist => msglist} ~/eg/ruby > ruby amrita1.rb apparently the second is 'experimental'. cool though. cheers. -a -- ATTN: please update your address books with address below! =============================================================================== | EMAIL :: Ara [dot] T [dot] Howard [at] noaa [dot] gov | PHONE :: 303.497.6469 | ADDRESS :: E/GC2 325 Broadway, Boulder, CO 80305-3328 | STP :: http://www.ngdc.noaa.gov/stp/ | NGDC :: http://www.ngdc.noaa.gov/ | NESDIS :: http://www.nesdis.noaa.gov/ | NOAA :: http://www.noaa.gov/ | US DOC :: http://www.commerce.gov/ | | The difference between art and science is that science is what we | understand well enough to explain to a computer. | Art is everything else. | -- Donald Knuth, "Discover" | | /bin/sh -c 'for l in ruby perl;do $l -e "print \"\x3a\x2d\x29\x0a\"";done' ===============================================================================