Skip to content

Latest commit

 

History

History
45 lines (34 loc) · 1.55 KB

README.md

File metadata and controls

45 lines (34 loc) · 1.55 KB

This is a Grails plugin than enables the easy inclusion of eco templates into a Grails appplication. It requires the well established resources plugin.

Background

Eco is yet another Javascript templating tool. Eco is written by PrototypeJs author Sam Stephenson.

It uses Mozilla's Rhino engine to execute the original eco compiler written in javascript.

Usage

To add eco template files to your grails project:

  • Install the plugin (adding to your BuildConfig is best)
  • Actually add the eco tempalte files to your project. I placed mine adjacent to the js folder in eco.
  • Reference your eco files in your ApplicationResources file (or where ever your defining your resources)

Example

  eco {
    resource url: 'eco/dir.eco'
    resource url: 'eco/entry.eco'
    resource url: 'eco/category.eco'
  }  

The above example will create a resource you can include in pages or have another resource depend on. The templates are converted into javascript objects in the Global name space. The naming of these js objects follows the pattern "eco.$fileName" where the filename does not include the extension.

Example eco tempate people.eco

  <ul>
    <% for person in @people: %>
      <li> <%= person.name %></li>      
    <% end %>
  </ul>

which could be referenced in your javascript code like this:

  $("li").html( eco.people( { people: [{ name: 'John' }, { name: 'Mary'}] } ) );