npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

requirejs-hogan-plugin

v0.3.1

Published

A requirejs wrapper for the mustache compiler.

Downloads

32

Readme

RequireJS mustache / hogan.js plugin

Load mustache / hogan.js templates dynamically during development and compile them during build to achieve greater performance.

Basic Usage

Define an external template like foo.mustache:

<div class="foo">
    <h1>{{title}}</h1>
    <ul>
        {{#names}}
        <li>{{.}}</li>
        {{/names}}
    </ul>
</div>

Load it with the hgn plugin:

// this will load the "foo.mustache" file
require(['hgn!foo'], function(foo){
    // the plugin will return the `render()` method of the `Hogan.Template`
    var markup = foo({
        title : 'Hello!',
        names : ['world', 'foo bar', 'lorem ipsum', 'nurse']
    });
    console.log(markup);
});

During development the template file will be loaded using the RequireJS text plugin and template will be compiled automatically. During optimization it will pre-compile the template and store it as pure JavaScript for better performance:

define("hgn!foo", ["hogan"], function(hogan){  var tmpl = new hogan.Template(function(c,p,i){var _=this;_.b(i=i||"");_.b("<div class=\"foo\">\r");_.b("\n" + i);_.b("    <h1>");_.b(_.v(_.f("title",c,p,0)));_.b("</h1>\r");_.b("\n" + i);_.b("    <ul>\r");_.b("\n" + i);if(_.s(_.f("names",c,p,1),c,p,0,71,105,"{{ }}")){_.rs(c,p,function(c,p,_){_.b("        <li>");_.b(_.v(_.d(".",c,p,0)));_.b("</li>\r");_.b("\n");});c.pop();}_.b("    </ul>\r");_.b("\n" + i);_.b("</div>\r");_.b("\n");return _.fl();;}, "", hogan);  return function(){ return tmpl.render.apply(tmpl, arguments); };});;

The plugin code is only required for dynamic load so you can use the r.js setting stubModules to remove the text! and hgn! plugins during build, see test/build.js for example.

Example

Example files are inside the test folder, to test build run:

cd test
node build

It will update the test/scripts/main_built.js file.

Changelog

v0.3.1 (2013/09/26)

  • update text plugin to 2.0.10 fixing bug related to node-webkit.

v0.3.0 (2013/06/11)

  • update Hogan to v3.0

v0.2.1 (2013/02/08)

  • add template property to the compiled template.
  • fix in case config.hgn isn't defined.

v0.2.0 (2012/06/29)

  • add compilationOptions support.
  • add pragmas to remove compiler during build.
  • return Template#render method instead of the Hogan.template object.

v0.1.0 (2012/06/18)

  • initial release.

License

Released under the MIT license.

Other plugins

You should also check the awesome RequireJS Handlebars Plugin created by Alex Sexton and the list of plugins on RequireJS wiki.