amrita-nuby question: generate "id="

H

Harry

Hi,
i'm using Amrita to generate static website pages, and having fun with
it! Now I'd like to have a navigationlist, a list where the items are
urls; all fine, but I'd like to designate one particular list-item as
"active", which is defined as id selector in the css-stylesheet for
the pages.

So the generated html-code should look something like this:

<div id="navigation">
<ul id="navlist">
<li><a href="home.html">home</a></li>
<li id="active"><a href="photos.html">photos</a></li>
<li><a href="info.html">info</a></li>
</ul>
</div>

However, I cannot find a way to have Amrita generate the value
"active" for the id attribute in a list-item. I did manage, as a
side-test, to use a css class instead of an id selector, and had it
generated by Amrita, but cannot get it working with the id-selector.
In my template, I set amrita_id to 'amrita_id'.

So my question is, how to generate a '<<some_tag> id="<some_value>"
....>' with Amrita?

thxia,
Harry
 
A

Ara.T.Howard

Date: 26 Jan 2004 09:33:48 -0800
From: Harry <[email protected]>
Newsgroups: comp.lang.ruby
Subject: amrita-nuby question: generate "id="

Hi,
i'm using Amrita to generate static website pages, and having fun with
it! Now I'd like to have a navigationlist, a list where the items are
urls; all fine, but I'd like to designate one particular list-item as
"active", which is defined as id selector in the css-stylesheet for
the pages.

So the generated html-code should look something like this:

<div id="navigation">
<ul id="navlist">
<li><a href="home.html">home</a></li>
<li id="active"><a href="photos.html">photos</a></li>
<li><a href="info.html">info</a></li>
</ul>
</div>

However, I cannot find a way to have Amrita generate the value
"active" for the id attribute in a list-item. I did manage, as a
side-test, to use a css class instead of an id selector, and had it
generated by Amrita, but cannot get it working with the id-selector.
In my template, I set amrita_id to 'amrita_id'.

So my question is, how to generate a '<<some_tag> id="<some_value>"
...>' with Amrita?

thxia,
Harry

you need to pass an array of procs, one for each link, so you have the
opportunity to edit the <li> manually:


~/eg/ruby > cat a.rb
require 'amrita'
include Amrita

template = TemplateText.new <<-html
<ul><li id="list"></li></ul>
html

links =
e:)a, :href => 'home.html'){'home'},
e:)a, :href => 'photos.html'){'photos'},
e:)a, :href => 'info.html'){'info'}

active = links[1]

data = {
:list => links.map do |link|
lambda do |li|
li[:id] = 'active' if link == active
li.init_body { link }
li
end
end
}

template.prettyprint = true
template.expand STDOUT, data

~/eg/ruby > ruby a.rb

<ul>
<li><a href="home.html">home</a></li>
<li id="active"><a href="photos.html">photos</a></li>
<li><a href="info.html">info</a></li>
</ul>


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

Samuel Kvarnbrink

Since the "id" attribute has a special meaning for Amrita itself, you
have to use a workaround. If you need to define id attributes (that is,
id attributes that are to be present in Amrita's output), you can
insert an "__id__" attribute. During Amrita's processing, all "__id__"
attributes are renamed to "id" attributes. Something like this should
do the trick:

tmpl = TemplateText.new <<END
<div __id__="navigation">
<ul __id__="navlist">
<li id="links"></li>
</ul>
</div>
END

data = {:links => ["item 1",
a:)__id__ => "active"){"item 2 (active)"},
"item 3"]}
 

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,744
Messages
2,569,482
Members
44,901
Latest member
Noble71S45

Latest Threads

Top