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

handlebars-jst

v0.0.4

Published

Pre-compiled jQuery Templates

Downloads

8

Readme

JST for Handlebars

handlebars-jst: Pre-compiled Handlebars with Node.js

Install with NPM

The best / easiest way to start using handlebars-jst is to install it with npm, which looks something like this: npm install handlebars-jst

Be sure to use the --global option if you'd like to use the command line tool.

Basic usage

Incant handlebars-jst into your application with a require statement, and jquery-tmpl-just will expose 2 functions: build and process

var tmpl = require('handlebars-jst');

// Builds a template string
tmpl.build( 'path/to/my/templates', function( output ){

  // Creates a file called templates.js
  tmpl.process( output, 'path/to/output/dir' );
});

Build creates a string of executable javascript from a directory of templates. It accepts the location of your templates and a callback function.

Process creates a file called templates.js in the specified target directory. It accepts a template string and a the target location.

CLI usage

handlebars-jst also comes with a command line tool, which you can use like this:

$ tmpl path/to/templates path/to/save

This creates the file templates.js to the target directory. If no arguments are passed, the current path will be used instead.

Using as a Cakefile

Since this is really meant to be used as a build tool, a Cakefile is included as well, but keep in mind that coffee-script must be included as a dependency in order to use the Cakefile.

Modify the Cakefile's targetDir and templateDir variables to point to you desired build location and the location of your templates, respectively.

Run cake build or cake watch from the root of your project to generate the compiled templates. cake watch will listen for changes in your templates directory and run the build process on demand.

JST Output

To start using the compiled templates, just include templates.js. Keep in mind that these are just your templates, so you'll also need jQuery and jQuery-tmpl in there too.

templates.js creates a global object called window.JST.

The JST object includes a templates object containing all of your precompiled templates:

JST = {
  <template_name>,
  <template_name_2>,
  ...
}

The helper methods are meant to make using templates as easy as possible, so they are functions that take JSON data to be templated as the only argument.

The functions themselves look like this:

  JST.<file_name> = function( data ){
    return $.tmpl( JST.template.<file_name>, data );
  }

And it's final usage would look something like this:

  var data = { title: "foobar" },
      compiled_template = window.JST.sample_template( my_data );

  $('body').html( compiled_template );

Multiple Named Templates from a single file

Add as many sub-templates as you want to a single JST file by writing a c-style comment with the sub-template name.

multiple_templates.JST
---
<hi>Nothing to see here</h1>

/* foo */
<h2>{foo}</h2>
<p>Check out this other awesome template<p>

This file will product 2 templates:

JST = {
  multiple_templates,
  multiple_templates_foo
}

Contributing

This is a need-based project, so I only wrote it to account for my needs as of right now.

If you've got any suggestestions, opinions, optimizations or fixes, please fork and pull request to contribute.

Everything original is MIT, everything else honors whatever license it was written under.