gulp-jade-inheritance icon indicating copy to clipboard operation
gulp-jade-inheritance copied to clipboard

How to use gulp-jade-inheritance with gulp-data?

Open ruslanxdev opened this issue 9 years ago • 3 comments

Hi! I know how to use gulp-jade with gulp-data. https://github.com/phated/gulp-jade#use-with-gulp-data http://stackoverflow.com/questions/27313107/gulp-using-gulp-jade-with-gulp-data

But I do not know how to use gulp-jade-inheritance with gulp-data. You have to either compile all pages when you change the JSON file, or search for and compile the pages that use this data. Maybe you have any ideas?

Here is my code:

gulp.task('jade', function(){
    return gulp.src(['src/jade/**/*.jade'])
        .pipe(plumber(function(error) {
            gutil.log(gutil.colors.red('Error: ' + error.message));
            this.emit('end');
        }))
        .pipe(changed('public', {extension: '.html'}))
        .pipe(cached('jade'))
        .pipe(jadeInheritance({basedir: 'src/jade'}))
        .pipe(data(function(file) {
            return JSON.parse(fs.readFileSync('./src/jade/data.json'));
        }))
        .pipe(filter(function (file) {
            return !/\/_/.test(file.path) && !/^_/.test(file.relative);
        }))
        .pipe(jade({
            pretty: '\t'
        }))
        .pipe(gulp.dest('public'))
        .pipe(livereload());
});
gulp.task('jade:all', function(){
    return gulp.src(['src/jade/**/*.jade'])
        .pipe(plumber(function(error) {
            gutil.log(gutil.colors.red('Error: ' + error.message));
            this.emit('end');
        }))
        .pipe(data(function(file) {
            return JSON.parse(fs.readFileSync('./src/jade/data.json'));
        }))
        .pipe(filter(function (file) {
            return !/\/_/.test(file.path) && !/^_/.test(file.relative);
        }))
        .pipe(jade({
            pretty: '\t'
        }))
        .pipe(gulp.dest('public'))
        .pipe(livereload());
});

Thanks!

ruslanxdev avatar Feb 23 '16 13:02 ruslanxdev

I'm not very sure, I've to test it, but maybe using https://github.com/jgable/gulp-cache and using the data.json and the filte content to generate the key. I'll try to test it this week.

juanfran avatar Feb 23 '16 17:02 juanfran

I've testes with gulp-cache and its works with differents data.json, if all the jade files use the same data.json I think it should be compiled all again... sorry I don't have more ideas. Anyway, your code should work, are you having any errors?

juanfran avatar Feb 27 '16 22:02 juanfran

Thank you, I have not found a solution to his problem. Everything works, but I was not able yet to optimize this process.

ruslanxdev avatar Apr 24 '16 12:04 ruslanxdev