gulp-velocity icon indicating copy to clipboard operation
gulp-velocity copied to clipboard

We always need a js file to a vm file?

Open leonardomerlin opened this issue 11 years ago • 2 comments

Hi @winnieBear,

First of all, great job with this node-module. I am starting to use this module to improve my workflow at a project which uses a lot of Velocity files. I am a beginner with the velocity language, but... Can we have a way to not need to create a index.js to a index.vm file?

Here is what i am doing:

// file: index.js
// at: function getContext()
// ....
if(!fs.existsSync(datafileAbsPath)){

  if(opt.skipContext === true){
    console.log('[gulp-velocity] info:', colors.yellow('skipping context to: ' + tplFileName));
    return opt.defaultContext || {};
  }

  throw new Error(PLUGIN_NAME + ": the corresponding data file [" + datafileAbsPath + "] is not exists!");
}
// ...
// file: gulpfile.js
// at velocity options
// ...
.pipe(velocity({
  root: './src/tpl/',
  files: './src/tpl/**/*.vm',
  encoding: 'utf-8',
  macro: './src/tpl/global-macro/macro.vm',
  globalMacroPath: './src/tpl/global-macro/',
  dataPath: './src/data/',
  skipContext: true,
  defaultContext: {
    foo: 'bar'
  }
}).on('error', util.log))
// ...

Like you can see, i suggest put this two new options: skipContext and defaultContext. If you agree with that, i can send you a PR.

Thanks.

leonardomerlin avatar Nov 11 '14 18:11 leonardomerlin

Here is the code

leonardomerlin avatar Nov 11 '14 19:11 leonardomerlin

I'm sorry I saw your issue so late, I'll read your code and give your an answer! Thank your code again!

winnieBear avatar Nov 17 '14 09:11 winnieBear