juanfran / gulp-jade-inheritance

Gulp plugin to rebuild jade files and other files that have extended or included those files
34 stars 32 forks source link

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

Open ruslanxdev opened 8 years ago

ruslanxdev commented 8 years ago

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!

juanfran commented 8 years ago

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 commented 8 years ago

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?

ruslanxdev commented 8 years ago

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