amrita question

C

Carl Youngblood

I'm having a weird problem with amrita. I need to have the contents of
a tag attribute be dynamically generated. So, if my template file has:

<form method="post" action="<DYNAMIC CONTENT NEEDS TO BE PLACED HERE>">
...
</form>

How do I do that? I tried:

<form method="post" action="<span id="formaction"></span>">
...
</form>

And amrita croaks during the parsing process. Here is what I get:

/var/www/html/pt.fcgi:13
/usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:473:in `each_cgi'
/usr/local/lib/ruby/site_ruby/1.8/fcgi.rb:473:in `each'
/var/www/html/pt.fcgi:13:in `each_cgi'
/var/www/html/pt.fcgi:15
/var/www/pennytracker/include/controller.rb:31:in `process_request'
/var/www/pennytracker/include/authentication.rb:54:in
`authenticate_if_needed'
/var/www/pennytracker/include/view.rb:42:in `display'
/usr/local/lib/ruby/site_ruby/1.8/amrita/template.rb:402:in `expand'
/usr/local/lib/ruby/site_ruby/1.8/amrita/template.rb:138:in `expand'
/usr/local/lib/ruby/site_ruby/1.8/amrita/template.rb:144:in `setup'
/usr/local/lib/ruby/site_ruby/1.8/amrita/template.rb:179:in `setup_template'
/usr/local/lib/ruby/site_ruby/1.8/amrita/template.rb:396:in `load_template'
/usr/local/lib/ruby/site_ruby/1.8/amrita/parser.rb:279:in `parse_file'
/usr/local/lib/ruby/site_ruby/1.8/amrita/parser.rb:279:in `open'
/usr/local/lib/ruby/site_ruby/1.8/amrita/parser.rb:280:in `parse_file'
/usr/local/lib/ruby/site_ruby/1.8/amrita/parser.rb:275:in `parse_io'
/usr/local/lib/ruby/site_ruby/1.8/amrita/parser.rb:301:in `parse'
error hapend in /var/www/pennytracker/templates/login.html:0(can't happen)
==>">">

Can somebody please explain how I can accomplish what I'm trying to do
with amrita? One way I know I can do it is to generate the whole <form>
tag dynamically, but that seems kind of kludgy. It would be better to
have a way of inserting only a specific piece of text anywhere I wanted.

Thanks,

Carl Youngblood
 
D

Don-Duong Quach

You can use attribute expansion by placing an "@" in front of the word
you want to replace.

Example:

require 'amrita/template'
include Amrita

temp = TemplateText.new <<END
<form method="post" action="@action"></form>
END

temp.expand(STDOUT, :action=>"foo.cgi")

Output:
<form action="foo.cgi" method="post"></form>

Don Quach
 
A

Ara.T.Howard

Date: Wed, 24 Dec 2003 05:17:38 GMT
From: Carl Youngblood <[email protected]>
Newsgroups: comp.lang.ruby
Subject: amrita question

I'm having a weird problem with amrita. I need to have the contents of
a tag attribute be dynamically generated. So, if my template file has:

<form method="post" action="<DYNAMIC CONTENT NEEDS TO BE PLACED HERE>">
...
</form>
<snip>

amrita is very smart, if you do not specify new content it does not delete
what's already there. combine that with the ability to replace attributes and
you can do exactly what you want:

~ > cat /tmp/foo.rb
require 'amrita/template'
include Amrita

t = TemplateText.new <<-html
<form method=post action=DYNAMIC_CONTENT_NEEDS_TO_BE_PLACED_HERE id=form>
<input type=text name=foobar>
</form>
html

t.expand STDOUT, :form => a:)action => 'myform.cgi')


~ > ruby /tmp/foo.rb
<form method="post" action="myform.cgi">
<input type="text" name="foobar">
</form>

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'
===============================================================================
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top