gulp-job
Wrap files in self invoking functions that bind them to an object. Possibly compiled Jade templates.
Installation
npm install gulp-job
Use case
Gulp job will wrap a file in a self invoking function that in turn binds the 'file' to a namespace on an object. The following describes the specific use case that lead to the creation of gulp-job.
Lets say you have a Jade template, something like:
p Hello world
And you want to compile this, load it in as a client side script and then access it in a way such as:
windowtemplates;
Gulp-job can take a compiled template (my-example.js) such as:
{ var buf = ; var jade_mixins = {}; var jade_interp; buf; return buf;}
and wrap it like so:
{ windowtemplates = windowtemplates || {}; windowtemplates { var buf = ; var jade_mixins = {}; var jade_interp; buf; return buf;}}window;
Usage
var gulp = jade = job = ; gulp;
This will compile your templates using gulp-jade and wrap them as shown above so that they can be included like normal js files.
Options
Gulp-job accepts an options object with the following attributes
parent (string)
default: 'window'
The object to bind to.
namespace (string)
default: 'templates'
The namespace to bind to
seperator (string)
default: '-'
The file name seperator. This will be used for converting file names to camel case object references.
i.e with the default settings the template file my-example.js would be accessible with:
windowtemplates;
It's a bit specific isn't it?
Yes it is, we had a very specific problem and we built a very specific solution to it. We also needed it to be part of our Gulp task flow.
Maybe someone else will have that very same specific problem one day; so here it is for all to use, fork, share, whatever.