directive not working?

4 views
Skip to first unread message

nightshade427

unread,
Oct 28, 2009, 2:16:35 PM10/28/09
to PURE - JavaScript Templates Engine
I am using Pure2 and trying to do

var dir = {
".quantity@class+": function(arg){return " quantity" + arg.pos},
".selling_price@class+": function(arg){return " selling_price" +
arg.pos},
};
$("#sale_items").render(data, template.compile(dir, data));

The class attribute is not being added to.

This used to work in Pure1

var dir = {
".quantity[class]+": function(arg){return "quantity" + arg.pos},
".selling_price[class]": function(arg){return "selling_price" +
arg.pos},
};
$("#sale_items").autoRender(data, dir, template);

Any ideas?

Mic Cvilic

unread,
Oct 30, 2009, 5:31:36 AM10/30/09
to Pure-Unobtrusive...@googlegroups.com
That should work in V2 too. The example 4 of the examples page is using it.
If not, could you set up an html page with html, json data and directive
that shows the problem.
Is it in one browser or all?
Cheers,

nightshade427

unread,
Oct 30, 2009, 1:25:22 PM10/30/09
to PURE - JavaScript Templates Engine
repo: does not add the class quanitity1, quantity2 etc.. to the items

<html>
<head>
<script src="vendor/javascript/jquery-1.3.2.js"></script>
<script src="vendor/javascript/pure2.js"></script>
<script>
$(function(){
var data = {
item_info: [
{
quantity: "1",
selling_price: "19.99"
},
{
quantity: "2",
selling_price: "0.99"
}
]
};
var template = $("#item_infos").clone();
var dir = {
".quantity@class+": function(arg){return " quantity" +
arg.pos;},
".selling_price@class+": function(arg){return "
selling_price" + arg.pos;}
};
$("#item_infos").render(data, template.compile(dir, data));
});
</script>
</head>
<body>
<table id="item_infos">
<tr class="item_info">
<td>
<span class="quantity"></span>
@
<span class="selling_price"></span>
</td>
</tr>
</table>
</body>
</html>

Mic Cvilic

unread,
Oct 30, 2009, 3:31:30 PM10/30/09
to pure-unobtrusive...@googlegroups.com
You'll have to go in manual mode on this one.
Like:

//compile
var dir = {
'tr':{
'info<-item_info':{
'.quantity':'info.quantity',
".quantity@class+": function(arg){
return " quantity" + arg.pos;
},
'.selling_price':'info.selling_price',
".selling_price@class+": function(arg){
return " selling_price" + arg.pos;
}
}
}
};
var fn = $("#item_infos").compile(dir);

//at each refresh
var data = {
item_info: [{
quantity: "1",
selling_price: "19.99"
},{
quantity: "2",
selling_price: "0.99"
}]
};
$("#item_infos").render(data, fn);

nightshade427

unread,
Oct 30, 2009, 3:55:27 PM10/30/09
to PURE - JavaScript Templates Engine
Ok will do.

A lot of the problems I have had with switching from v1 to v2 (auto
rendering arrays and some others) seems to be solved by doing it
manually. One of things that attracted me to pure over chains.js was
the simplicity. Is there plans to make v2 simpler again once it
restabalizes? Maybe once I get better at js I can help out as well. I
really like this project and would love to help out :)

On Oct 30, 12:31 pm, Mic Cvilic <tch...@gmail.com> wrote:
> You'll have to go in manual mode on this one.
> Like:
>
> //compile
> var dir = {
>      'tr':{
>          'info<-item_info':{
>              '.quantity':'info.quantity',
>              ".quantity@class+": function(arg){
>                  return " quantity" + arg.pos;
>              },
>              '.selling_price':'info.selling_price',
>              ".selling_price@class+": function(arg){
>                  return " selling_price" + arg.pos;
>              }
>          }
>      }};
>
> var fn = $("#item_infos").compile(dir);
>
> //at each refresh
> var data = {
>      item_info: [{
>          quantity: "1",
>          selling_price: "19.99"
>      },{
>          quantity: "2",
>          selling_price: "0.99"
>      }]};
>
> $("#item_infos").render(data, fn);
>

nightshade427

unread,
Oct 30, 2009, 5:19:27 PM10/30/09
to PURE - JavaScript Templates Engine
That worked like a charm. Binding correctly now. Brilliant,
thanks!! ;)

Mic Cvilic

unread,
Oct 30, 2009, 6:15:26 PM10/30/09
to pure-unobtrusive...@googlegroups.com
You're the most advanced user of autoRender I know, and your feedback is
very interesting.

Unfortunately simplicity for you means complexity for me right now. I
place big hopes in your nascent JS skills ;)
If you feel in a brave mood, all the secret sauce of autoRender is in
the 2 functions: getAutoNodes and checkClass.

A class like "quantity#{item_info.pos}@class+", although cryptic, would
be nice to end up to "quantity0", isn't it?
Cheers,
> --
>
> You received this message because you are subscribed to the Google Groups "PURE - JavaScript Templates Engine" group.
> To post to this group, send email to pure-unobtrusive...@googlegroups.com.
> To unsubscribe from this group, send email to pure-unobtrusive-rende...@googlegroups.com.
> For more options, visit this group at http://groups.google.com/group/pure-unobtrusive-rendering-engine?hl=en.
>
>
>

nightshade427

unread,
Oct 30, 2009, 6:46:25 PM10/30/09
to PURE - JavaScript Templates Engine
Ya definetly, I will check out the source and see if there is anything
I can do to help out. I must admit that once I switched over to manual
directives it cleaned up my HTML a ton. So it is growing on me:).

keep up the great work on this awesome library.

On Oct 30, 3:15 pm, Mic Cvilic <tch...@gmail.com> wrote:
> You're the most advanced user of autoRender I know, and your feedback is
> very interesting.
>
> Unfortunately simplicity for you means complexity for me right now. I
> place big hopes in your nascent JS skills ;)
> If you feel in a brave mood, all the secret sauce of autoRender is in
> the 2 functions: getAutoNodes and checkClass.
>
> A class like "quantity#{item_info.pos}@class+", although cryptic, would
> be nice to end up to "quantity0", isn't it?
> Cheers,
>
Reply all
Reply to author
Forward
0 new messages