GitXplorerGitXplorer
t

hogan.js

public
5141 stars
431 forks
37 issues

Commits

List of commits on branch master.
Verified
c91c0234e0f7418d27d5ccb4698e54360f15809b

set status to unmaintained

wwillnorris committed 3 years ago
Verified
124a59ed8b29e6dbfdb26c1b8b816e06398b0118

Merge pull request #266 from twitter/add_tls_to_urls

aalanbato committed 5 years ago
Unverified
858c9900fd9d48daeb732d2114b651f91d937843

Replace http with https in files

aalanbato committed 5 years ago
Unverified
7e340e9e4dde8faebd1ff34e62abc1c5dd8adb55

Merge pull request #223 from pdehaan/patch-1

ccaniszczyk committed 9 years ago
Unverified
2db2e1f083e49bf5c11e790026c2f60802e63840

Update license attribute

ppdehaan committed 9 years ago
Unverified
9417a6f26ee120525f5b96d26cb68c853911ee5b

Merge pull request #197 from mbacklas/patch-1

ssayrer committed 10 years ago

README

The README file for this repository.

Hogan.js - A mustache compiler.

status: unmaintained 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 require the compiler and the original template source to be present.

Hogan also supports template inheritance, and maintains compatibility with other implementations like mustache.java, mustache.php, and GRMustache

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.

Install

Node.js

npm install hogan.js

component

component install twitter/hogan.js

Compilation options

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

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

There are currently 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/.

Testing

To run the tests you first need to update all git submodules.

$ git submodule init
$ git submodule update

Unit tests are written using QUnit. To run them, open test/index.html in a browser.

Use node to run all tests from the mustache spec.

$ node test/spec.js

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