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

gulp-template-store

v1.1.2

Published

A gulp plugin for storing templates in a namespace object/JST file

Downloads

20

Readme

NPM

Build Status #gulp-template-store A gulp plugin for storing all of your lodash templates in a single cache file.

this.tmpl = {
  "test/templates/a": function(obj) {
    obj || (obj = {});
    var __t, __p = '', __e = _.escape;
    with (obj) {
      __p += '<div>' +
      __e( a ) +
      '</div>';
    }
    return __p
  }
};
this.tmpl = {
  "templates/superDiv": function(){ return document.createElement('div'); }
}

##Install Install using npm

npm install gulp-template-store

##Example use

var gulp = require('gulp'),
  tmplStore = require('gulp-template-store')
  sources = {
    templates: 'src/html/templates/**/*.html'
  },
  destinations = {
    tmpl: './tmp/'
  };
gulp.task('templates:compile', function() {
  return gulp.src(sources.templates)
    .pipe(tmplStore({
      name: 'templates.js',
      variable: 'this.templateCache',
      base: 'src/html/',
      bare: false
      options: {
        interpolate: /{{([\s\S]+?)}}/g
      }
    }))
    .pipe(gulp.dest(destinations.tmp));
})

The featured example will generate a single file named templates.js containing all template files as keyed lodash template functions contained within an object named this.templateCache. All keys under the file will be based to src/html. In addition, the templates will also evaluate Handlebars style interpolation({{}}) as that has been passed in as an option.

A possible output from say the files src/html/templates/a.html and src/html/templates/b.html would be;

this.templateCache = {
  "templates/a": [function Function],
  "templates/b": [function Function]
}

NOTE:: gulp-template-store aims to be platform agnostic. It has been developed on a UNIX system. Whatever base option is provided, gulp-template-store will interpret them using the current OS path separator by converting any slashes.

By default, the keys in the resulting store will use forward slashes / (UNIX style). For example; on Windows, your template may be located at \templates\a.html. The output key will be templates/a.

However, you can override this by setting the unix option to false if you wish for keys to use the platform path separator. Take into consideration that this may affect those working on a different platform.

##Options

  • name: {String} - Defines the filename for outputted template file.

  • variable: {String} - Defines the variable that shall be used to define the templates object. By default, this is this.tmpl.

  • base: {String} - Defines the base directory to generate key names from. By default, this is the root of the repo where your gulpfile is located.

  • unix: {Bool} - Defines whether to use forward slashes / in keys. When false, will use platform specific path separator. For Windows, \. Defaults to true.

  • bare: {Bool} - use with caution - Defines whether to use lodash templating or to simply create an object store for mapping file contents. Defaults to false.

    For example,

      this.tmpl = {
        "templates/superDiv": function() { return document.createElement('div'); }
        "templates/log"   : function(msg) { console.log(msg); }
      }
  • options: object - defines an object containing options that will be passed to the lodash template compiler. Supported options are interpolate, imports and variable.

##Contributing Contributions are welcome. Feel free to submit a PR or open an issue if there's something you think is missing.

##License MIT

@jh3y 2015