As we develop richer and richer applications in the client-side logic, we inevitably run into the short-coming of HTML inside of JavaScript.

Edward Benson has created EJS, a port of Ruby’s Erb to the client side.

Example

HTML:

  1.  
  2. [% var title = "Items to buy!"; %]
  3. <h4>[%= title %]</h4>
  4. [% ['cupcake', 'hardware'].each(function(item) { %]
  5. <li>[%= item %]</li>
  6.  
  7. [% }); %]
  8. </ul>
  9.  

Usage

JAVASCRIPT:

  1.  
  2. var compiler = new EjsCompiler(ejs);
  3. compiler.compile();
  4. var compiled = eval(compiler.out);
  5.  

Source: Ajaxian
Original Article: http://ajaxian.com/archives/ejs-embedded-javascript-client-side-preprocessor

Leave a Reply

You must be logged in to post a comment.



Site Navigation