DailyJS

Mojo Templates

Alex R. Young

Subscribe

@dailyjs

Facebook

Google+

templates view

Mojo Templates

Posted by Alex R. Young on .
Featured

templates view

Mojo Templates

Posted by Alex R. Young on .

Mojo is an interesting project that brings Mustache templates to
JavaScript. Mojo provides a command line tool, mojo for
building Mustache-based templates using JavaScript syntax and data
structures.

A template looks like this:

    { title }


    { title }
    {# articles }

        { title }
        { body }
        {# published }
          { title } is published
        {/ published }

    {/ articles }

And a corresponding template object would look like this:

page = {
    title: 'Articles',
    articles: [
      { title: 'One', body: 'some more one' },
      { title: 'Two', body: 'some more two', published: true }
    ]
}

This could be used with a server-side JavaScript framework for a fast,
reusable and native templating solution.

The author uses the JSpec
testing framework for tests, which is also worth checking out if you
haven't seen it.