Professional Web Applications Themes

amrita-nuby question: generate "id=" - Ruby

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, ...

  1. #1

    Default 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
    Harry Guest

  2. #2

    Default Re: amrita-nuby question: generate "id="

    On 26 Jan 2004, Harry wrote:
     

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

    Ara.T.Howard Guest

  3. #3

    Default Re: amrita-nuby question: generate "id="

    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"]}
     



    Samuel Guest

Similar Threads

  1. SMTP: "to" or/and "recipient" question.
    By Serguei.Goumeniouk@cibc.ca in forum PERL Modules
    Replies: 1
    Last Post: November 11th, 06:31 PM
  2. Question about "Public Sub" vs "Private Sub" vs "Sub"
    By michaaal in forum ASP Database
    Replies: 1
    Last Post: October 18th, 07:15 PM
  3. Replies: 3
    Last Post: September 4th, 04:05 PM
  4. Getting error "Unable to generate code for a value of type"
    By xyz in forum ASP.NET Building Controls
    Replies: 0
    Last Post: July 3rd, 06:01 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139