Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

gulp-job

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

gulp-job

Wrap compiled Gulp templates and bind them to an object

  • 0.1.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
0
Maintainers
1
Weekly downloads
 
Created
Source

gulp-job NPM version Build status

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:

window.templates.example([locals]);

Gulp-job can take a compiled template (my-example.js) such as:

function template(locals) {
  var buf = [];
  var jade_mixins = {};
  var jade_interp;

  buf.push("<p>Hello world</p>");
  return buf.join("");
}

and wrap it like so:

(function (window) {
  window.templates = window.templates || {};
  window.templates.myExample = function template(locals) {
    var buf = [];
    var jade_mixins = {};
    var jade_interp;

    buf.push("<p>Hello world</p>");
    return buf.join("");
}})(window);

Usage

var gulp = require('gulp'),
    jade = require('gulp-jade'),
    job = require('gulp-job');

gulp.task('job', function () {
  return gulp.src(['src/templates/*.jade'])
    .pipe(jade({ client: true }))
    .pipe(job())
    .pipe(gulp.dest('public/templates'));
});

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:

window.templates.myExample();

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.

Licence

MIT

Keywords

FAQs

Package last updated on 18 Feb 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