[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

Amrita and programmatically-generated JavaScript

Carl Youngblood

11/4/2003 5:27:00 PM

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?

Thanks,
Carl

2 Answers

Ara.T.Howard

11/4/2003 6:03:00 PM

0

Carl Youngblood

11/5/2003 4:47:00 AM

0

That's right. I remembered as soon as you said it that it wasn't id
tags but id attributes. Thanks for the clarification. I thought it
left all tags in and placed dynamic content inside of them, but
apparently it is very flexible. Thanks Ara.

Ara.T.Howard wrote:
> On Tue, 4 Nov 2003, Carl Youngblood wrote:
>
>
>>Date: Tue, 04 Nov 2003 17:26:50 GMT
>>From: Carl Youngblood <carl@ycs.biz>
>>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