Activate your free membership today | Log-in

Thursday, February 14th, 2008

OnionML: Server Side JavaScript Layout Engine

Category: CSS, Framework, JavaScript

<p>Marcello Bastéa-Forte has developed OnionML, a layout template language that uses server side JavaScript with Rhino and E4X on the back end.

The high-level goal of the template engine is to be something with utility not unlike CSS, but for intended layout and composition. The actual functionality is similar to XSLT, but with the design goal of being simple and easily extensible.

Onion ML is an XML template system designed with a bias toward modularity.

Onion ML lets you easily custom XML tags to make modular content design simple and easy to mix with HTML. It is somewhat comparable to XSLT and JSF, but intended to be easier to understand.

You define custom tags either as markup in XML files or as custom JavaScript functions which generate output.

Onion ML also provides several control flow methods necessary for dynamic content. Methods for iterating over data sets and conditionally displaying tags are core to Onion ML's functionality.

You end up building nested tag layouts. For example, you first define a tag:

HTML:
  1.  
  2. <tag :mylayout>
  3.   <title><arg :title/></title>
  4.   <style> ... </style>
  5.  </head>
  6.   <h1><arg :title/></h1>
  7.   <div id="contents"><arg :body/></div>
  8.   <div id="footer"><copyright><arg :year/></copyright></div>
  9.  </body>
  10. </html>
  11. </tag>
  12.  
  13. <tag :copyright>Copyright <arg :all/> All rights reserved</tag>
  14.  

and then you can use it:

HTML:
  1.  
  2. <mylayout>
  3.  <title>Hello world!</title>
  4.  <body>This is my <b>world</b>, too.</body>
  5.  <year>2008</year>
  6. </mylayout>
  7.  

You can also do the work directly in JavaScript:

JAVASCRIPT:
  1.  
  2. var onion = new Onion(
  3.  <onion>
  4.   <tag :mytag>woot, <arg :all/>!</tag>
  5.  </onion>
  6. );
  7.  
  8. onion.add(
  9.  <tag :anothertag>play the <mytag>tuba</mytag></tag>
  10. );
  11.  
  12. onion.add("date", function() {
  13.   return new Date().toString()
  14. });
  15.  

Related Content:

  • Diet Ajax, 100% JavaScript free
    The open source Ajax framework ZK 1.0 has been released with its own markup language along with XUL and XHTML components to get around programming in...
  • Junk JavaScript?
    Should JavaScript and HTML be replaced with "proper" languages that might give more bang for the buck in rich Internet applications (RIAs)? One reader...
  • 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...
  • Google Chrome shifts architects' equations as V8 powers the browser
    The V8 JavaScript engine in Google's Chrome browser offers the enterprise architect new options for moving server-side functionality to the Web...
  • Asynchronous JavaScript and XML
    Ajax (Asynchronous JavaScript and XML) is a method of building interactive applications for the Web that process user requests immediately. Ajax...

Posted by Dion Almaer at 6:27 am
1 Comment

+++--
3.9 rating from 27 votes

1 Comment »

Comments feed TrackBack URI

Thanks for posting this! I am looking to get feedback on the language and suggestions on the open questions: namely how to deal with assigning attributes and data processing.

Comment by Marcello — February 14, 2008

Leave a comment

You must be logged in to post a comment.