> Programming Languages > Ruby
Various Topics Home | Disclaimer | Report Adult Posts

Various Topics on Ruby



Ruby - "Enabling/disabling HTML with Amrita" in Programming Languages


Old 06-21-2004   #1
.... ..hwar..
 
Default Enabling/disabling HTML with Amrita

I know with Amrita, if you p*** nil as the data for a template
element, it doesn't get printed. What I'm interested in is in
conditional container elements, such as <span> or <tr>, that print
their templated content when enabled. See my test below:

emschwar@wilson:/tmp$ cat bah.templ
<table>
<tr><td id="cell1" />/></tr>
<tr id="row2"><td id="cell2" /></tr>
</table>

emschwar@wilson:/tmp$ cat ./amrita-test
#!/usr/bin/ruby
require 'amrita/template'

data1 = { :cell1 => "Cell 1" }

data2 = { :cell1 => "Cell 1",
:row2 => "testing",
:cell2 => "Cell 2" }

template = Amrita::TemplateFile.new("bah.templ")

template.expand(STDOUT, data1)
puts
template.expand(STDOUT, data2)

emschwar@wilson:/tmp$ ./amrita-test
<table>
<tr><td>Cell 1</td></tr>

</table>

<table>
<tr><td>Cell 1</td></tr>
<tr>testing</tr>
</table>
emschwar@wilson:/tmp$

Obviously, what I'm looking for in the second case is something like
<table>
<tr><td>Cell 1</td></tr>
<tr><td>Cell 2</td></tr>
</table>

I've been resorting to templating tricks like

<tr><td id="cell2" /></tr>

but that leaves an empty table row in there when there's no 'cell2',
which is not always what I want. In the particular application I'm
using it for, it's okay, but it's kinda ugly. How can I get there
from here? Or can I?

-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
 
Old 06-22-2004   #2
..edrid..
 
Default Re: Enabling/disabling HTML with Amrita

On Tue, 2004-06-22 at 06:33 +0900, Eric Schwartz wrote:
> I know with Amrita, if you p*** nil as the data for a template
> element, it doesn't get printed. What I'm interested in is in
> conditional container elements, such as <span> or <tr>, that print
> their templated content when enabled. See my test below:
>
> emschwar@wilson:/tmp$ cat bah.templ
> <table>
> <tr><td id="cell1" />/></tr>
> <tr id="row2"><td id="cell2" /></tr>
> </table>
>
> emschwar@wilson:/tmp$ cat ./amrita-test
> #!/usr/bin/ruby
> require 'amrita/template'
>
> data1 = { :cell1 => "Cell 1" }
>
> data2 = { :cell1 => "Cell 1",
> :row2 => "testing",
> :cell2 => "Cell 2" }
>
> template = Amrita::TemplateFile.new("bah.templ")
>
> template.expand(STDOUT, data1)
> puts
> template.expand(STDOUT, data2)
>
> emschwar@wilson:/tmp$ ./amrita-test
> <table>
> <tr><td>Cell 1</td></tr>
>
> </table>
>
> <table>
> <tr><td>Cell 1</td></tr>
> <tr>testing</tr>
> </table>
> emschwar@wilson:/tmp$
>
> Obviously, what I'm looking for in the second case is something like
> <table>
> <tr><td>Cell 1</td></tr>
> <tr><td>Cell 2</td></tr>
> </table>
>
> I've been resorting to templating tricks like
>
> <tr><td id="cell2" /></tr>
>
> but that leaves an empty table row in there when there's no 'cell2',
> which is not always what I want. In the particular application I'm
> using it for, it's okay, but it's kinda ugly. How can I get there
> from here? Or can I?


<tr><td><span amrita:id='cell2'>Cell 2</span></td></tr>

Ari



 
Old 06-22-2004   #3
.... ..hwar..
 
Default Re: Enabling/disabling HTML with Amrita

Aredridel <aredridel@nbtsc.org> writes:
> <tr><td><span amrita:id='cell2'>Cell 2</span></td></tr>


Right, but that still leaves the extra <tr> in there. I want to have
the <tr> show up when there is content for 'cell2', but not when there
isn't any.

-=Eric
--
Come to think of it, there are already a million monkeys on a million
typewriters, and Usenet is NOTHING like Shakespeare.
-- Blair Houghton.
 
Old 06-22-2004   #4
..v ....
 
Default Re: Enabling/disabling HTML with Amrita

Hello,

On Tue, 22 Jun 2004 06:33:14 +0900, Eric Schwartz <emschwar@pobox.com>
wrote:

> I know with Amrita, if you p*** nil as the data for a template
> element, it doesn't get printed. What I'm interested in is in
> conditional container elements, such as <span> or <tr>, that print
> their templated content when enabled. See my test below:
>
> emschwar@wilson:/tmp$ cat bah.templ
> <table>
> <tr><td id="cell1" />/></tr>
> <tr id="row2"><td id="cell2" /></tr>
> </table>


Notice that cell2 is a child of row2.
Now try using this data hash:


#!/usr/bin/ruby
require 'amrita/template'

data3 = {
:cell1 => "Cell 1",
:row2 => {
:cell2 => "Cell 2"
}
}

template = Amrita::TemplateFile.new("bah.templ")

template.expand(STDOUT, data3)


> Obviously, what I'm looking for in the second case is something like
> <table>
> <tr><td>Cell 1</td></tr>
> <tr><td>Cell 2</td></tr>
> </table>


The result of data3 should be what you want.
I hope this makes sense.

Best,
Zev


 

Thread Tools
Display Modes





Powered by vBulletin®
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0