Code coverage report for yeoman-generator/lib/util/engines.js

Statements: 91.67% (11 / 12)      Branches: 100% (0 / 0)      Functions: 66.67% (2 / 3)      Lines: 91.67% (11 / 12)      Ignored: none     

All files » yeoman-generator/lib/util/ » engines.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44  1                 1                     1 1 1 9             9   8       8     1 32    
'use strict';
var _ = require('lodash');
 
// TODO(mklabs):
// - handle cache
// - implement adpaters for others engines (but do not add hard deps on them,
// should require manual install for anything that is not an underscore
// template)
// - put in multiple files, possibly other packages.
 
var engines = module.exports;
 
// Underscore
// ----------
 
// Underscore templates facade.
//
// Special kind of markers `<%%` for opening tags can be used to escape the
// placeholder opening tag. This is often useful for templates including
// snippet of templates you don't want to be interpolated.
 
var matcher = /<%%([^%]+)%>/g;
var detecter = /<%%?[^%]+%>/;
engines.underscore = function underscore(source, data) {
  source = source.replace(matcher, function (m, content) {
    // let's add some funny markers to replace back when templating is done,
    // should be fancy enough to reduce frictions with files using markers like
    // this already.
    return '(;>%%<;)' + content + '(;>%<;)';
  });
 
  source = _.template(source)(data);
 
  source = source
    .replace(/\(;>%%<;\)/g, '<%')
    .replace(/\(;>%<;\)/g, '%>');
 
  return source;
};
 
engines.underscore.detect = function detect(body) {
  return detecter.test(body);
};