
Security News
The Changelog Podcast: Practical Steps to Stay Safe on npm
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.
| Package | gulp-jade |
| Description | Compile Jade templates |
| Node Version | ≥ 0.10 |
Compile to HTML
var jade = require('gulp-jade');
gulp.task('templates', function() {
var YOUR_LOCALS = {};
gulp.src('./lib/*.jade')
.pipe(jade({
locals: YOUR_LOCALS
}))
.pipe(gulp.dest('./dist/'))
});
Compile to JS
var jade = require('gulp-jade');
gulp.task('templates', function() {
gulp.src('./lib/*.jade')
.pipe(jade({
client: true
}))
.pipe(gulp.dest('./dist/'))
});
All options supported by the Jade API are supported
Note: filename option is taken from path property of incoming vinyl-file object. If you want to change it, use gulp-rename before gulp-jade with desired path.
In addition, you can pass in a locals or data option that will be used as locals for your HTML compilation. The locals option takes precedence over the data option, and both are overwritten by data on the vinyl file object (See "Use with gulp-data" below).
If you want to use a different version of jade, or define jade filters, you can pass your own instance of jade as the jade option:
var jade = require('jade');
var gulpJade = require('gulp-jade');
var katex = require('katex');
jade.filters.katex = katex.renderToString;
jade.filters.shoutFilter = function (str) {
return str + '!!!!';
}
gulp.task('jade', function () {
return gulp.src('public/**/*.jade')
.pipe(gulpJade({
jade: jade,
pretty: true
}))
.pipe(gulp.dest('public/'))
})
The gulp-data plugin, is a standard method for piping data down-stream to other plugins that need data in the form of a new file property file.data. If you have data from a JSON file, front-matter, a database, or anything really, use gulp-data to pass that data to gulp-jade.
Retrieve data from a JSON file, keyed on file name:
gulp.task('json-test', function() {
return gulp.src('./examples/test1.jade')
.pipe(data(function(file) {
return require('./examples/' + path.basename(file.path) + '.json');
}))
.pipe(jade())
.pipe(gulp.dest('build'));
});
Since gulp-data provides a callback, it means you can get data from a database query as well:
gulp.task('db-test', function() {
return gulp.src('./examples/test3.jade')
.pipe(data(function(file, cb) {
MongoClient.connect('mongodb://127.0.0.1:27017/gulp-data-test', function(err, db) {
if(err) return cb(err);
cb(undefined, db.collection('file-data-test').findOne({filename: path.basename(file.path)}));
});
}))
.pipe(jade())
.pipe(gulp.dest('build'));
});
If you want to use some static locals and some dynamic using gulp-data, the static locals will be overridden. Instead, you can extend in the gulp-data function:
var _ = require('lodash');
var statics = {
my: 'statics',
foo: 'bar'
};
gulp.task('json-test', function() {
return gulp.src('./examples/test1.jade')
.pipe(data(function(file) {
var json = require('./examples/' + path.basename(file.path) + '.json');
var data = _.assign({}, json, statics);
return data;
}))
.pipe(jade())
.pipe(gulp.dest('build'));
});
More info on gulp-data
If you are trying to wrap your Jade template functions in an AMD wrapper, use gulp-wrap-amd
var jade = require('gulp-jade');
var wrap = require('gulp-wrap-amd');
gulp.task('templates', function() {
gulp.src('./lib/*.jade')
.pipe(jade({
client: true
}))
.pipe(wrap({
deps: ['jade'],
params: ['jade']
}))
.pipe(gulp.dest('./dist/'))
});
(MIT License)
Copyright (c) 2013 Blaine Bublitz
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
FAQs
Compile Jade templates
The npm package gulp-jade receives a total of 2,603 weekly downloads. As such, gulp-jade popularity was classified as popular.
We found that gulp-jade demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?

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.

Security News
Learn the essential steps every developer should take to stay secure on npm and reduce exposure to supply chain attacks.

Security News
Experts push back on new claims about AI-driven ransomware, warning that hype and sponsored research are distorting how the threat is understood.

Security News
Ruby's creator Matz assumes control of RubyGems and Bundler repositories while former maintainers agree to step back and transfer all rights to end the dispute.