GithubHelp home page GithubHelp logo

nvdnkpr / hogan.js Goto Github PK

View Code? Open in Web Editor NEW

This project forked from twitter/hogan.js

1.0 1.0 0.0 313 KB

A compiler for the Mustache templating language

Home Page: http://twitter.github.com/hogan.js

License: Apache License 2.0

hogan.js's Introduction

Hogan.js - A mustache compiler. Build Status

Hogan.js is a compiler for the Mustache templating language. For information on Mustache, see the manpage and the spec.

Basics

Hogan compiles templates to HoganTemplate objects, which have a render method.

var data = {
  screenName: "dhg",
};

var template = Hogan.compile("Follow @{{screenName}}.");
var output = template.render(data);

// prints "Follow @dhg."
console.log(output);

Features

Hogan is fast--try it on your workload.

Hogan has separate scanning, parsing and code generation phases. This way it's possible to add new features without touching the scanner at all, and many different code generation techniques can be tried without changing the parser.

Hogan exposes scan and parse methods. These can be useful for pre-processing templates on the server.

var text = "{{^check}}{{#i18n}}No{{/i18n}}{{/check}}";
text +=  "{{#check}}{{#i18n}}Yes{{/i18n}}{{/check}}";
var tree = Hogan.parse(Hogan.scan(text));

// outputs "# check"
console.log(tree[0].tag + " " + tree[0].name);

// outputs "Yes"
console.log(tree[1].nodes[0].nodes[0]);

It's also possible to use HoganTemplate objects without the Hogan compiler present. That means you can pre-compile your templates on the server, and avoid shipping the compiler. However, the optional lambda features from the Mustache spec do require the compiler to be present.

Why Hogan.js?

Why another templating library?

Hogan.js was written to meet three templating library requirements: good performance, standalone template objects, and a parser API.

Compilation options

The second argument to Hogan.compile is an options hash.

var text = "my <%example%> template."
Hogan.compile(text, {delimiters: '<% %>'});

There are current four valid options.

asString: return the compiled template as a string. This feature is used by hulk to produce strings containing pre-compiled templates.

sectionTags: allow custom tags that require opening and closing tags, and treat them as though they were section tags.

var text = "my {{_foo}}example{{/foo}} template."
Hogan.compile(text, { sectionTags: [{o: '_foo', c: 'foo'}]});

The value is an array of object with o and c fields that indicate names for custom section tags. The example above allows parsing of {{_foo}}{{/foo}}.

delimiters: A string that overrides the default delimiters. Example: "<% %>".

disableLambda: disables the higher-order sections / lambda-replace features of Mustache.

Issues

Have a bug? Please create an issue here on GitHub!

https://github.com/twitter/hogan.js/issues

Versioning

For transparency and insight into our release cycle, releases will be numbered with the follow format:

<major>.<minor>.<patch>

And constructed with the following guidelines:

  • Breaking backwards compatibility bumps the major
  • New additions without breaking backwards compatibility bumps the minor
  • Bug fixes and misc changes bump the patch

For more information on semantic versioning, please visit http://semver.org/.

Authors

Robert Sayre

Jacob Thornton

License

Copyright 2011 Twitter, Inc.

Licensed under the Apache License, Version 2.0: http://www.apache.org/licenses/LICENSE-2.0

hogan.js's People

Contributors

sayrer avatar fat avatar mattrobenolt avatar bradwright avatar akaspin avatar speier avatar braddunbar avatar chadhietala avatar treygriffith avatar ayoung avatar neonstalwart avatar caniszczyk avatar kaezarrex avatar kasperp avatar mjackson avatar mikefrey avatar plecong avatar bobbydavid avatar scumbag-pull-request avatar pthrasher avatar

Stargazers

Navid Nikpour avatar

Watchers

 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.