New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

gulp-template-store

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-template-store

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

  • 1.1.1
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

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 however been developed on a UNIX system. Therefore, no matter what base option is provided, whether one is provided or not, the keys in the resulting store will use forward slashes /.

For example; on Windows, your template may be located at \templates\a.html. The output key will be templates/a.html.

##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.

  • bare: bool - use with caution - defines whether to use lodash templating or to simply create an object store for mapping file contents.

    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

Keywords

FAQs

Package last updated on 14 Dec 2015

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc