Date: Tue, 04 Nov 2003 17:26:50 GMT
From: Carl Youngblood <
[email protected]>
Newsgroups: comp.lang.ruby
Subject: Amrita and programmatically-generated JavaScript
I'm still in the middle of porting my PHP-based web thinking into a ruby
frame of mind. I'm looking into amrita for my templating engine but I am
concerned about some of its apparent limitations. It seems that it is
necessary to put all dynamically-generated pieces of a template in
<id>{stuff}</id> tags. I want to create a form class that automatically
adds JavaScript form validation based on validation regexp patterns and
error messages that I have set in my class. This means that I need to have
sections of the template containing JavaScript be dynamically generated. If
I have to surround all template variables with <id> tags, this will not
work. Anybody have any ideas?
not <id> tags - id _attributes_. additionally, certain tags with id
attributes (like span) are stripped after expansion if they contain no other
attributes (other than 'id')
examples:
~ > cat foo.rb
require 'amrita/template'
# spans are removed
t = Amrita::TemplateText.new '<span id=key></span>'
t.expand STDOUT, :key => "this is all that's left\n"
~ > ruby foo.rb
this is all that's left
---
~ > cat bar.rb
require 'amrita/template'
formvaidator = 'function validateForm(theForm) { /*stuff*/ }'
t = Amrita::TemplateText.new <<-html
<script id=script></script>
<form id=form><input type='text' name=name><input type="submit></form>
html
data = Hash.new
# amrita lets you modify attributes and text - of a named tag
data[:script] = Amrita::a
language => 'javascript'){formvaidator}
# or you can modify only attributes
data[:form] = Amrita::a
onsubmit => 'return validateForm(this)')
t.expand STDOUT, data
~ > ruby bar.rb
<script language="javascript">function validateForm(theForm) { /*stuff*/ }</script>
<form onsubmit="return validateForm(this)"><input type="text" name="name"></form>~ >
does that help? amrita is really quite powerful - there is a bit of a
learning curve though.
-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'
===============================================================================