Example #1
0
function filter(name, str, options) {
  if (typeof filter[name] === 'function') {
    var res = filter[name](str, options);
  } else if (transformers[name]) {
    var res = transformers[name].renderSync(str, options);
  } else {
    throw new Error('unknown filter ":' + name + '"');
  }
  return res;
}
Example #2
0
function filter(name, str, options) {
  if (typeof filter[name] === 'function') {
    return filter[name](str, options);
  } else {
    var tr;
    try {
      tr = jstransformer(require('jstransformer-' + name));
    } catch (ex) {}
    if (tr) {
      // TODO: we may want to add a way for people to separately specify "locals"
      var result = tr.render(str, options, options).body;
      if (options && options.minify) {
        try {
          switch (tr.outputFormat) {
            case 'js':
              result = uglify.minify(result, {fromString: true}).code;
              break;
            case 'css':
              result = new CleanCSS().minify(result).styles;
              break;
          }
        } catch (ex) {
          // better to fail to minify than output nothing
        }
      }
      return result;
    } else if (transformers[name]) {
      if (!warned[name]) {
        warned[name] = true;
        if (name === 'md' || name === 'markdown') {
          var implementation = getMarkdownImplementation();
          console.log('Transformers.' + name + ' is deprecated, you must replace the :' +
                      name + ' jade filter, with :' +
                      implementation + ' and install jstransformer-' +
                      implementation + ' before you update to jade@2.0.0.');
        } else if (alternatives[name]) {
          console.log('Transformers.' + name + ' is deprecated, you must replace the :' +
                      name + ' jade filter, with :' +
                      alternatives[name] + ' and install jstransformer-' +
                      alternatives[name] + ' before you update to jade@2.0.0.');
        } else {
          console.log('Transformers.' + name + ' is deprecated, to continue using the :' +
                      name + ' jade filter after jade@2.0.0, you will need to install jstransformer-' +
                      name.toLowerCase() + '.');
        }
      }
      return transformers[name].renderSync(str, options);
    } else {
      throw new Error('unknown filter ":' + name + '"');
    }
  }
}
Example #3
0
function filter(name, str, options) {
  if (typeof filter[name] === 'function') {
    var res = filter[name](str, options);
  } else if (transformers[name]) {
    var res = transformers[name].renderSync(str, options);
    if (transformers[name].outputFormat === 'js') {
      res = '<script type="text/javascript">\n' + res + '</script>';
    } else if (transformers[name].outputFormat === 'css') {
      res = '<style type="text/css">' + res + '</style>';
    } else if (transformers[name].outputFormat === 'xml') {
      res = res.replace(/'/g, '&#39;');
    }
  } else {
    throw new Error('unknown filter ":' + name + '"');
  }
  return res;
}