transformers
Advanced tools
Comparing version 2.1.0 to 3.0.0
@@ -0,1 +1,9 @@ | ||
## 3.0.0 - 2014-02-12 | ||
- **escape-html** | ||
- remove **html2jade** (it was all round problematic and not kept up to date with recent changes to jade) | ||
- remove **component-js** and **component-css** (I don't think they are very useful to have here, browserify is better) | ||
- improve **stylus** support | ||
- fix **mustache** (it no longer supports caching properly) | ||
## 2.1.0 - 2013-07-13 | ||
@@ -2,0 +10,0 @@ |
@@ -133,3 +133,8 @@ var dirname = require('path').dirname; | ||
outputFormat: 'xml', | ||
sync: sync | ||
sync: function (str, options) { | ||
// https://github.com/netzpirat/haml-coffee/issues/91 | ||
if (global.CoffeeScript) delete global.CoffeeScript; //prevent global leak | ||
var tmpl = this.cache(options) || this.cache(options, this.engine.compile(str, options)); | ||
return tmpl(options); | ||
} | ||
}); | ||
@@ -192,4 +197,4 @@ | ||
sync: function(str, options){ | ||
var tmpl = this.cache(options) || this.cache(options, this.engine.compile(str)); | ||
return tmpl(options, options.partials); | ||
str = this.cache(options) || this.cache(options, str); | ||
return this.engine.to_html(str, options, options.partials); | ||
} | ||
@@ -395,7 +400,40 @@ }); | ||
} | ||
//If this.cache is enabled, compress by default | ||
// If this.cache is enabled, compress by default | ||
if (options.compress !== true && options.compress !== false) { | ||
options.compress = options.cache || false; | ||
} | ||
this.engine.render(str, options, function (err, res) { | ||
// Utility function for cloning objects | ||
function clone(obj){ | ||
if (obj == null || typeof(obj) != 'object') return obj; | ||
var tmp = new obj.constructor(); | ||
for (var key in obj) tmp[key] = clone(obj[key]); | ||
return tmp; | ||
} | ||
var initial = this.engine(str); | ||
// Special handling for stylus js api functions | ||
// given { define: { foo: 'bar', baz: 'quux' } } | ||
// runs initial.define('foo', 'bar').define('baz', 'quux') | ||
var allowed = ['set', 'include', 'import', 'define', 'use']; | ||
var special = {} | ||
var normal = clone(options); | ||
for (var v in options) { | ||
if (allowed.indexOf(v) > -1) { special[v] = options[v]; delete normal[v]; } | ||
} | ||
// special options through their function names | ||
for (var k in special) { | ||
for (var v in special[k]) { initial[k](v, special[k][v]); } | ||
} | ||
// normal options through set() | ||
for (var k in normal) { | ||
for (var v in normal[k]) { initial['set'](v, normal[k][v]); } | ||
} | ||
initial.render(function (err, res) { | ||
if (err) return cb(err); | ||
@@ -452,4 +490,2 @@ self.cache(options, res); | ||
sync: function (str, options) { | ||
//todo: remove once https://github.com/rstacruz/js2coffee/pull/174 accepted & released | ||
if (global.Narcissus) delete global.Narcissus; //prevent global leak | ||
return this.cache(options) || this.cache(options, JSON.stringify(this.engine.parseSync(str))); | ||
@@ -498,69 +534,17 @@ } | ||
exports.component = exports['component-js'] = new Transformer({ | ||
name: 'component-js', | ||
engines: ['component-builder'], | ||
outputFormat: 'js', | ||
async: function (str, options, cb) { | ||
if (this.cache(options)) return this.cache(options); | ||
var self = this; | ||
var builder = new this.engine(dirname(options.filename)); | ||
if (options.development) { | ||
builder.development(); | ||
} | ||
if (options.sourceURLs === true || (options.sourceURLs !== false && options.development)) { | ||
builder.addSourceURLs(); | ||
} | ||
var path = require('path'); | ||
builder.paths = (options.paths || ['components']).map(function (p) { | ||
if (path.resolve(p) === p) { | ||
return p; | ||
} else { | ||
return path.join(dirname(options.filename), p); | ||
} | ||
}); | ||
builder.build(function (err, obj) { | ||
if (err) return cb(err); | ||
else return cb(null, self.cache(options, obj.require + obj.js)); | ||
}); | ||
} | ||
}); | ||
exports["escape-html"] = new Transformer({ | ||
name: 'escape-html', | ||
engines: ['.'],// `.` means "no dependency" | ||
outputFormat: 'xml', | ||
sync: function (str, options) { | ||
var escaped = str.replace(/&/g, '&') | ||
.replace(/</g, '<') | ||
.replace(/>/g, '>') | ||
.replace(/"/g, '"') | ||
.replace(/'/g, '''); | ||
exports['component-css'] = new Transformer({ | ||
name: 'component-css', | ||
engines: ['component-builder'], | ||
outputFormat: 'css', | ||
async: function (str, options, cb) { | ||
if (this.cache(options)) return this.cache(options); | ||
var self = this; | ||
var builder = new this.engine(dirname(options.filename)); | ||
if (options.development) { | ||
builder.development(); | ||
} | ||
if (options.sourceURLs === true || (options.sourceURLs !== false && options.development)) { | ||
builder.addSourceURLs(); | ||
} | ||
var path = require('path'); | ||
builder.paths = (options.paths || ['components']).map(function (p) { | ||
if (path.resolve(p) === p) { | ||
return p; | ||
} else { | ||
return path.join(dirname(options.filename), p); | ||
} | ||
}); | ||
builder.build(function (err, obj) { | ||
if (err) return cb(err); | ||
else return cb(null, self.cache(options, obj.css)); | ||
}); | ||
return this.cache(options) || this.cache(options, escaped); | ||
} | ||
}); | ||
exports['html2jade'] = new Transformer({ | ||
name: 'html2jade', | ||
engines: ['html2jade'], | ||
outputFormat: 'jade', | ||
async: function (str, options, cb) { | ||
return this.cache(options) || this.cache(options, this.engine.convertHtml(str, options, cb)); | ||
} | ||
}); | ||
exports['highlight'] = new Transformer({ | ||
@@ -567,0 +551,0 @@ name: 'highlight', |
{ | ||
"name": "transformers", | ||
"version": "2.1.0", | ||
"version": "3.0.0", | ||
"description": "String/Data transformations for use in templating libraries, static site generators and web frameworks", | ||
@@ -8,3 +8,3 @@ "main": "lib/transformers.js", | ||
"pretest": "node test/update-package && npm install", | ||
"test": "mocha test/test.js -R spec" | ||
"test": "mocha" | ||
}, | ||
@@ -61,3 +61,2 @@ "repository": { | ||
"component-builder": "*", | ||
"html2jade": "*", | ||
"highlight.js": "*" | ||
@@ -64,0 +63,0 @@ }, |
@@ -55,8 +55,6 @@ [![Build Status](https://travis-ci.org/ForbesLindesay/transformers.png?branch=master)](https://travis-ci.org/ForbesLindesay/transformers) | ||
- verbatim - No need to install anything, acts as a verbatim passthrough `${INPUT_STRING}` | ||
- escape-html - No need to install anything, just replaces special characters to sanitize input for html/xml | ||
- [coffee-script](http://coffeescript.org/) - `npm install coffee-script` | ||
- [cson](https://github.com/bevry/cson) - coffee-script based JSON format | ||
- markdown - You can use `marked`, `supermarked`, `markdown-js` or `markdown` | ||
- [component-js](http://documentup.com/component/component) [(website)](http://component.io) - `npm install component-builder` options: `{development: false}` | ||
- [component-css](http://documentup.com/component/component) [(website)](http://component.io) - `npm install component-builder` options: `{development: false}` | ||
- [html2jade](http://documentup.com/donpark/html2jade) [(website)](http://html2jade.aaron-powell.com/) - `npm install html2jade` - Converts HTML back into jade | ||
@@ -63,0 +61,0 @@ Pull requests to add more transforms will always be accepted providing they are open-source, come with unit tests, and don't cause any of the tests to fail. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
35196
42
7
0
678
139