Skip to content

Gulp plugin to rebuild jade files and other files that have extended or included those files

Notifications You must be signed in to change notification settings

juanfran/gulp-jade-inheritance

Folders and files

NameName
Last commit message
Last commit date

Latest commit

History

30 Commits

Repository files navigation

#gulp-jade-inheritance Build Status

Rebuild a jade file with other files that have extended or included those file

Inspired byjade-inheritance

Install

npm install gulp-jade-inheritance --save-dev

Usage

gulpfile.js

varjadeInheritance=require('gulp-jade-inheritance');
varjade=require('gulp-jade');

gulp.task('jade-inheritance',function(){
gulp.src('/jade/example.jade')
.pipe(jadeInheritance({basedir:'/jade/'}))
.pipe(jade());
});

In this example jade compileexample.jadeand all other files that have been extended or includedexample.jade.The plugin searches for those dependencies in thebasedirdirectory.

Only process changed files

You can usegulp-jade-inheritancewithgulp-changedandgulp-cachedto only process the files that have changed. This also prevent partials from being processed separately by marking them with an underscore before their name.

'use strict';
vargulp=require('gulp');
varjadeInheritance=require('gulp-jade-inheritance');
varjade=require('gulp-jade');
varchanged=require('gulp-changed');
varcached=require('gulp-cached');
vargulpif=require('gulp-if');
varfilter=require('gulp-filter');

gulp.task('jade',function(){
returngulp.src('app/**/*.jade')

//only pass unchanged *main* files and *all* the partials
.pipe(changed('dist',{extension:'.html'}))

//filter out unchanged partials, but it only works when watching
.pipe(gulpif(global.isWatching,cached('jade')))

//find files that depend on the files that have changed
.pipe(jadeInheritance({basedir:'app'}))

//filter out partials (folders and files starting with "_" )
.pipe(filter(function(file){
return!/\/_/.test(file.path)&&!/^_/.test(file.relative);
}))

//process jade templates
.pipe(jade())

//save all the files
.pipe(gulp.dest('dist'));
});
gulp.task('setWatch',function(){
global.isWatching=true;
});
gulp.task('watch',['setWatch','jade'],function(){
//your watch functions...
});

If you want to prevent partials from being processed, mark them with an underscore before their name or their parent folder's name. Example structure:

/app/index.jade
/app/_header.jade
/app/_partials/article.jade
/dist/

To install all that's need for it:

npm install gulp-jade-inheritance gulp-jade gulp-changed gulp-cached gulp-if gulp-filter --save-dev

jade >= 1.11

if your using jade 1.11 add"jade": "^1.11.0"to yourpackage.jsonto overwrite the jade-inheritance version.Issue

About

Gulp plugin to rebuild jade files and other files that have extended or included those files

Resources

Stars

Watchers

Forks

Packages

No packages published