Coder Social home page Coder Social logo

daub's Introduction

Daub Build Status

A templating engine with Mustache-like syntax based on Whiskers.

Installation

Using component:

$ component install daub/daub

Using npm for server-side use or for browserify:

$ npm install daub

Example

Templates are rendered as follows, where "template" is a string and "context" is an object:

var daub = require('daub');

var template = 'Hello, {place}!',
    context  = { place: 'Region' };

daub.render(template, context); // Hello, Region!

A template might look something like this:

<article>
  {if tags}
    <ul id="tags">
      {for tag in tags}
      <li>{tag}</li>
      {/for}
    </ul>
  {else}
    <p>No tags!</p>
  {/if}
  <div>{content}</div>
  {!<p>this paragraph is 
    commented out</p>!}
</article>

With the following context:

{
  title: 'My life',
  author: 'Bars Thorman',
  tags: [
    'real',
    'vivid'
  ],
  content: 'I grew up into a fine willow.'
}

It would be rendered as this:

<article>
  <ul id="tags">
    <li>real</li>
    <li>vivid</li>
  </ul>
  <div>I grew up into a fine willow.</div>
</article>

Partials

Daub's partials are being loaded compile-time, like includes in EJS, so are not available for front-end usage.

You can specify partials using local files, using relative path to target template in statement. If specified path is a directory, it'll resolve corresponding index.html if exists.

<body>
  {>./common/header.html}
</body>

Or you can use npm or component packages, in which case template.html file or the one specified in manifest as template will be loaded.

<body>
  {>component/tip}
</body>

NOTE: By default npm is used to resolve packages. If you want to use component, set { component: true } in options argument.

Test

Run unit tests:

$ make test

Best practices

Use Whiskers.js instead, it's ~3x faster (could get even faster because of internal caching).

Forebears

License

The MIT License.

daub's People

Contributors

gsf avatar antaranian avatar mdb avatar mendezcode avatar ryan-sandy avatar tlhunter avatar tuurdutoit avatar

Watchers

 avatar James Cloos avatar Armen Darabyan avatar Andranik avatar

Forkers

omnitaint

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.