Activate your free membership today | Log-in

Monday, September 22nd, 2008

PURE JavaScript Template Library Improves

Category: JavaScript

<p>PURE, the JavaScript template engine, has had a major new release which includes:

  • Auto-rendering: a new PURE method takes your HTML and your JSON data and merges them automatically. The class attribute is used to map the HTML and the data. (Read more about autoRender and its jQuery version on our Wiki).
  • Functions as directive are called by reference and not serialized
  • Change the id of the template root node (as any other attribute)
  • Better string value handling
  • Use of named properties in iteration “obj.prop” as well as “obj['name']“

For a feel of the library check out the documentation which takes you from the simplest render:

JAVASCRIPT:
  1.  
  2. $('#hello').autoRender({ "who": "Mary" });}
  3.  

to more advanced examples such as going back to the server to get data to fill in:

JAVASCRIPT:
  1.  
  2.   button.value = 'loading data...';
  3.   var script = (button.id == 'b4_2') ? 'js/jsonBig.js':'js/jsonSmall.js';
  4.   $.getJSON(script, function(context){
  5.  
  6.   var directive = {
  7.     'tbody tr td[onclick]':'"clickLine(this)"',
  8.     'tbody tr td[onmouseover]': '"swapStyle(this, true);"',
  9.     'tbody tr td[onmouseout]' : '"swapStyle(this, false);"',
  10.     'tbody tr td[style]':''cursor:pointer'',
  11.                
  12.     'tbody tr[class]+':
  13.         function(context, items, pos){
  14.           var oddEven =  (pos % 2 == 0) ? 'even' : 'odd';
  15.           var firstLast = (pos == 0) ? 'first': (pos == items.length -1) ? 'last':'';
  16.           return oddEven + ' ' + firstLast; }}
  17.  
  18.   $('table.players.2').autoRender(context, directive);
  19.  
  20.   button.value = 'Refresh the page to render again';});}
  21.  

Related Content:

  • JQuery 1.4 goes live
    jQuery JavaScript library brings performance and coding improvements. This release represents a significant update to the...
  • Ajax app testing now available in Parasoft WebKing
    Parasoft WebKing 6.0 helps Web developers plug holes in JavaScript through policy creation, strong unit tests and asynchronous HTTP message...
  • JavaScript Library in a Notes database
    Do you need the same JavaScript code in many Notes forms? This tip will shows you how you can maintain JavaScript code in only one...
  • Microsoft works on Ajax JavaScript tools
    In a session at the recent Ajax Experience conference in San Francisco, Matt Gibbs, development manager in the UI Framework and Services team at...
  • JavaScript Learning Guide
    This SearchDomino.com guide introduces you to JavaScript in a Notes/Domino environment, explains best practices and pitfalls to avoid and provides...

Posted by Dion Almaer at 6:21 am
Comment here

+++--
3.1 rating from 31 votes

Comments Here »

Comments feed TrackBack URI

Leave a comment

You must be logged in to post a comment.