const config = protoss.config.templates;

const plumber = require('gulp-plumber');
const filter = require('gulp-filter');
const cached = require('gulp-cached');
const gulpif = require('gulp-if');
const compile = require('gulp-jade');
const inheritance = require('gulp-jade-inheritance');
const prettify = require('gulp-jsbeautifier');
const hashSrc = require('gulp-hash-src');
const rename = require('gulp-rename');
const w3cjs = require('gulp-w3cjs');

protoss.gulp.task('protoss/templates', (cb) => {
  protoss.gulp.src(config.src)
    .pipe(plumber({errorHandler: protoss.errorHandler(`Error in \'templates\' task`)}))
    .pipe(gulpif(protoss.flags.isWatch, cached()))
    .pipe(gulpif(protoss.flags.isWatch,inheritance({basedir: config.inhBaseDir})))
    .pipe(filter(file => {
        if (/\/_/.test(file.path) || /^_/.test(file.relative)) return false;

        if (config.filterFunc && typeof config.filterFunc === 'function') {
          return config.filterFunc(file);
        }

        return true;
      }
    ))
    .pipe(compile({pretty: false, data: config.data}))
    .pipe(gulpif(protoss.flags.isBuild, prettify()))
    .pipe(rename({dirname: '.'}))
    .pipe(gulpif(protoss.flags.isBuild && config.hashes, hashSrc({
      build_dir: './',
      src_path: './',
      query_name: 'v',
      hash_len: 10,
      exts: ['.js', '.css', '.jpg', '.jpeg', '.png', '.gif', '.webp', '.svg', '.pdf', '.ico']
    })))
    .pipe(protoss.gulp.dest(config.dest))
    .on('end', function() {
      protoss.notifier.success('Templates compiled');
      cb(null);
    });
});

protoss.gulp.task('protoss/templates:w3c-test', (cb) => {
  protoss.gulp.src(config.w3c.src)
    .pipe(w3cjs())
    .pipe(w3cjs.reporter())
    .on('end', function() {
      cb(null);
    });
});

@@ -774,24 +774,126 @@
 file =%3E %7B%0A  
+    let path = file.path.replace(/%5C%5C/g, '/');%0A      let relative = file.relative.replace(/%5C%5C/g, '/');%0A
       if (/%5C
@@ -901,21 +901,16 @@
 _/.test(
-file.
 path) %7C%7C
@@ -920,21 +920,16 @@
 _/.test(
-file.
 relative
@@ -948,26 +948,24 @@
 lse;%0A%0A      
-  
 if (config.f
@@ -1024,26 +1024,24 @@
 ) %7B%0A        
-  
 return confi
@@ -1070,15 +1070,11 @@
     
-  
 %7D%0A%0A
-  
     
@@ -1096,16 +1096,9 @@
     
-  %7D%0A    
+%7D
 ))%0A 

fix windows file path in templates task