Git Product home page Git Product logo

musdash.js's Introduction

musdash.js - Stupidly quick logic-less {{mustache}} templates for JavaScript

musdash.js is an implementation of the Mustache template system for JavaScript.

musdash.js was designed to be extremely fast at compiling and parsing {{mustache}} templates and is almost completely compatible with mustache.js except for a few little things.

Usage

Here is an example of how to use musdash.js:

var view = {
	data: [ 
		{ first: "Jane", last: "Doe" }, 
		{ first: "Joe", last: "Blogs" }
	],
	bold: function( render, text )
	{
		return '<b>' + render( text ) + '</b>';
	}
};

var template = Musdash.compile( '<ul>{{#data}}<li>{{#bold}}{{first}}{{/bold}} {{last}}</li>{{/data}}</ul>' );
var output = template.parse( view /*, optional partials parameter */ );

// `template` can be used as many times as necessary to avoid re-compiling (even though compiling is super fast anyway)

Links

Comparison of speed against mustache.js

Test cases

Features

musdash.js currently supports all mustache features except the 'Set Delimiter' feature.

See the mustache manual for more information.

musdash.js adds some utility variables which can be used within arrays, '_i' refers to the current index of the array (it is 1-indexed for convenience i.e. 1,2,3 not 0,1,2) and '_c' refers to the total number of items in the array

var view = {
	data: [ 
		{ first: "Jane", last: "Doe" }, 
		{ first: "Joe", last: "Blogs" }
	],
	separator: function()
	{
		return (this._i != this._c) ? ", " : "";
	}
};

var template = Musdash.compile( '{{#data}}{{_i}}. {{first}} {{last}}{{separator}}{{/data}}' );
var output = template.parse( view );

// Outputs "1. Jane Doe, 2. Joe Blogs";

mustache.js Compatibility

musdash.js has slightly different syntax to mustache.js see demos for example.

Building

mustdash.js comes with an ant build script, which at the moment simply compresses the source with YUI Compressor.

Simple run the 'ant' command in the project directory and the minified version will be placed in 'build'.

Note

musdash.js is still an infant and care should be taken using it in a production environment.

musdash.js's People

Contributors

kanewallmann avatar

Stargazers

Hicham Abdelkaoui avatar

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.