[Nitro] [PATCH/RFC] Make element ids unique

Arne Brasseur arne at arnebrasseur.net
Tue Nov 27 00:42:00 EST 2007

Hi devs,

The template compiler for elements automatically sets the instance 
variable @id based on either an explicit id attribute in the html or the 
name of the class.

class LoginBox
def render
%~<div id="@id">...</div>~

<LoginBox />
<LoginBox />
<LoginBox />
<LoginBox id="my_id"/>
<LoginBox id="my_id"/>

This will result in
<div id="login_box">...</div>
<div id="login_box">...</div>
<div id="login_box">...</div>
<div id="my_id">...</div>
<div id="my_id">...</div>

Also, when nesting elements the children are kept in a Dictionary and 
the @id is used as lookup key, so in the above example only the third 
and the fifth box would be visible for the parent.

The attached patch changes the element compiler to make ids unique by 
adding a number where necessary, so the above example would become

<div id="login_box">...</div>
<div id="login_box_1">...</div>
<div id="login_box_2">...</div>
<div id="my_id">...</div>
<div id="my_id_1">...</div>

Are there any objections to this being applied?

Thank you!

Arne Brasseur
arne at arnebrasseur.net

-------------- next part --------------
A non-text attachment was scrubbed...
Name: ab_20071127_unique_element_id.patch
Type: text/x-patch
Size: 5082 bytes
Desc: not available
Url : http://rubyforge.org/pipermail/nitro-general/attachments/20071127/723d524e/attachment.bin 

More information about the Nitro-general mailing list