It was requested by almost all the active members of this forum.
So here it is, after a very intense week. A brand new method:
pure.autoRender(...)
This new method maps automatically the HTML and the JSON based on the
class attribute.
Download it from
http://github.com/pure/pure/downloads/v1.4
Look for the page docs/allExamples.html
The usage of the new method in a classical javascript:
var target = document.getElementById('target1');
var html = document.getElementById('hello');
var data = { "firstName": "Mary" };
target.innerHTML = $p.autoRender( html, data );
The jQuery syntax is as follow:
$('#hello').autoRender({ "firstName": "Mary" });
If either, you want total control over the rendering without any
automation, or if you meet an extremely heavy templates, you can use
pure.render() that will run only with directives.
The autoRender interface is as follow:
$p.autoRender(html, context [,directives]);
html: the html template
context: the JSON data to be transformed
directives: now optional to refine the renderin
And it returns a string with the transformed html.
The jQuery.autoTransform interface is slightly different:
$('#myDiv').autoRender(data);
- merge data and myDiv automatically
- replace myDiv
$('#myDiv').autoRender(data, directives);
- apply the directives
- merge data and myDiv automatically
- replace myDiv
$('#myDiv').autoRender(data, target);
- merge data and myDiv automatically
- replace the target node
$('#myDiv').autoRender(data, directives, target);
- apply the directives
- merge data and myDiv automatically
- replace target
Backward compatibility notes:
- - - - - - - - - - - - - - -
$p.map and $p.compile are now only useful when you want to compile
your template and store them in a js file.
The interface of $p.render(...)has changed, so watch out existing
implementation.
The jQuery.$pRender() has been renamed to a more friendly
jQuery.render()
We'll keep the name of the old method for a while, then delete it.