From: Carl Youngblood Date: 2003-12-20T03:26:54+09:00 Subject: Re: amrita question I am trying to find a nice template solution in Ruby, and amrita looks kind of good, but I'm also worried that it is moving further in a direction that is against my interests. I noticed, for example, that in the latest RELEASENOTE, under MergeTemplate, it says "not supported. use Amulet instead." And yet the amulet examples that it does show don't seem to accomplish quite the same things as merging two templates together. (It would help if there actually was documentation for amulet, but that is another story). The problem, as I see it, is that the new examples that are shown have a strong coupling between ruby code and templates. In the parts template, for example, you are actually creating ruby classes for different HTML elements. What I really want is to have template files that don't have an ounce of ruby code inside of them, that I can give to a blockhead graphic designer and just tell him that they are HTML snippets and that he can change them all he wants as long as he doesn't get rid of the amrita ids. The templates have to be nestable, however, because I don't want to have to duplicate code from one page to the next. So, I really appreciate your time, but the first example, which is acceptable to my usage model, I couldn't get working, and the other example(s) really aren't going to work with the way I want to develop my site. Any other ideas? Thanks, Carl Ara.T.Howard wrote: > 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