broccoli-rsvg
Advanced tools
Comparing version 0.3.0 to 0.3.1
# Contributor Code of Conduct | ||
As contributors and maintainers of this project, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. | ||
As contributors and maintainers of this project, and in the interest of fostering an open and welcoming community, we pledge to respect all people who contribute through reporting issues, posting feature requests, updating documentation, submitting pull requests or patches, and other activities. | ||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, or religion. | ||
We are committed to making participation in this project a harassment-free experience for everyone, regardless of level of experience, gender, gender identity and expression, sexual orientation, disability, personal appearance, body size, race, ethnicity, age, religion, or nationality. | ||
Examples of unacceptable behavior by participants include the use of sexual language or imagery, derogatory comments or personal attacks, trolling, public or private harassment, insults, or other unprofessional conduct. | ||
Examples of unacceptable behavior by participants include: | ||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. Project maintainers who do not follow the Code of Conduct may be removed from the project team. | ||
* The use of sexualized language or imagery | ||
* Personal attacks | ||
* Trolling or insulting/derogatory comments | ||
* Public or private harassment | ||
* Publishing others' private information, such as physical or electronic addresses, without explicit permission | ||
* Other unethical or unprofessional conduct. | ||
Project maintainers have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct. By adopting this Code of Conduct, project maintainers commit themselves to fairly and consistently applying these principles to every aspect of managing this project. Project maintainers who do not follow or enforce the Code of Conduct may be permanently removed from the project team. | ||
This code of conduct applies both within project spaces and in public spaces when an individual is representing the project or its community. | ||
@@ -15,2 +22,2 @@ | ||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.1.0, available at [http://contributor-covenant.org/version/1/1/0/](http://contributor-covenant.org/version/1/1/0/) | ||
This Code of Conduct is adapted from the [Contributor Covenant](http://contributor-covenant.org), version 1.2.0, available at [http://contributor-covenant.org/version/1/2/0/](http://contributor-covenant.org/version/1/2/0/) |
125
index.js
@@ -1,73 +0,70 @@ | ||
'use strict'; | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var CachingWriter = require('broccoli-caching-writer'); | ||
var Rsvg = require('librsvg').Rsvg; | ||
var RSVP = require('rsvp'); | ||
var path = require('path'); | ||
var mkdirp = require('mkdirp'); | ||
var walkSync = require('walk-sync'); | ||
var _ = require('lodash'); | ||
'use strict' | ||
function SvgRenderer(inputTree, fileOptions) { | ||
if (!(this instanceof SvgRenderer)) return new SvgRenderer(inputTree, fileOptions); | ||
CachingWriter.apply(this, arguments) | ||
this.fileOptions = fileOptions || {}; | ||
} | ||
var fs = require('fs') | ||
var path = require('path') | ||
var CachingWriter = require('broccoli-caching-writer') | ||
var Rsvg = require('librsvg').Rsvg | ||
var RSVP = require('rsvp') | ||
var path = require('path') | ||
var mkdirp = require('mkdirp') | ||
var walkSync = require('walk-sync') | ||
var _ = require('lodash') | ||
SvgRenderer.prototype = Object.create(CachingWriter.prototype); | ||
SvgRenderer.prototype.constructor = SvgRenderer; | ||
var SvgRenderer = CachingWriter.extend({ | ||
init: function(inputTrees, fileOptions) { | ||
this._super(inputTrees, {}) | ||
this.fileOptions = fileOptions || {} | ||
}, | ||
promiseForFile: function(srcDir, relativePath, destDir, version) { | ||
if (typeof version !== 'undefined') { | ||
var srcPath = path.join(srcDir, relativePath) | ||
var allPromises = (version['versions'] || []).map(function(v) { | ||
return this.promiseForFile(srcDir, relativePath, destDir, _.merge(_.omit(version, 'versions'), v)) | ||
}.bind(this)) | ||
allPromises.push(new RSVP.Promise(function(resolve, reject) { | ||
var destPath = path.join(destDir, version['path'] || getDestFilePath(relativePath)) | ||
mkdirp.sync(path.dirname(destPath)) | ||
render(srcPath, destPath, version, resolve) | ||
})) | ||
return RSVP.all(allPromises) | ||
} | ||
}, | ||
updateCache: function(srcPaths, destDir) { | ||
var promises = srcPaths.map(function(srcDir) { | ||
return RSVP.all(walkSync(srcDir).map(function(relativePath) { | ||
if (relativePath.slice(-1) === '/') { | ||
mkdirp.sync(path.join(destDir, relativePath)) | ||
} else { | ||
var version = this.fileOptions[relativePath] || {} | ||
return this.promiseForFile.bind(this)(srcDir, relativePath, destDir, version) | ||
} | ||
}.bind(this))) | ||
}.bind(this)) | ||
return RSVP.all(promises) | ||
} | ||
}) | ||
function render(from, to, options, callback) { | ||
var svg = new Rsvg(); | ||
svg.on('finish', function() { | ||
fs.writeFile(to, svg.render(_.merge({ | ||
format: 'png', | ||
width: svg.width, | ||
height: svg.height | ||
}, options)).data, callback); | ||
}); | ||
var transformer = options['transformer']; | ||
fs.readFile(from, {encoding: 'UTF-8'}, function(err, data) { | ||
if (err) throw err; | ||
if (typeof transformer === 'function') data = transformer(data); | ||
svg.end(data); | ||
}); | ||
var svg = new Rsvg() | ||
svg.on('finish', function() { | ||
fs.writeFile(to, svg.render(_.merge({ | ||
format: 'png', | ||
width: svg.width, | ||
height: svg.height | ||
}, options)).data, callback) | ||
}) | ||
var transformer = options['transformer'] | ||
fs.readFile(from, {encoding: 'UTF-8'}, function(err, data) { | ||
if (err) throw err | ||
if (typeof transformer === 'function') data = transformer(data) | ||
svg.end(data) | ||
}) | ||
} | ||
function getDestFilePath(relativePath) { | ||
return relativePath.replace('svg', 'png'); | ||
return relativePath.replace('svg', 'png') | ||
} | ||
SvgRenderer.prototype.promiseForFile = function(srcDir, relativePath, destDir, version) { | ||
if (typeof version !== 'undefined') { | ||
var self = this; | ||
var srcPath = path.join(srcDir, relativePath); | ||
var allPromises = (version['versions'] || []).map(function(v) { | ||
return self.promiseForFile(srcDir, relativePath, destDir, _.merge(_.omit(version, 'versions'), v)); | ||
}); | ||
allPromises.push(new RSVP.Promise(function(resolve, reject) { | ||
var destPath = path.join(destDir, version['path'] || getDestFilePath(relativePath)); | ||
mkdirp.sync(path.dirname(destPath)); | ||
render(srcPath, destPath, version, resolve); | ||
})); | ||
return RSVP.all(allPromises); | ||
} | ||
} | ||
SvgRenderer.prototype.updateCache = function(srcPaths, destDir) { | ||
var self = this; | ||
var promises = srcPaths.map(function(srcDir) { | ||
return RSVP.all(walkSync(srcDir).map(function(relativePath) { | ||
if (relativePath.slice(-1) === '/') { | ||
mkdirp.sync(path.join(destDir, relativePath)); | ||
} else { | ||
var version = self.fileOptions[relativePath] || {}; | ||
return self.promiseForFile.bind(self)(srcDir, relativePath, destDir, version); | ||
} | ||
})); | ||
}); | ||
return RSVP.all(promises); | ||
} | ||
module.exports = SvgRenderer; | ||
module.exports = function(t, o) { return new SvgRenderer(t, o) } |
{ | ||
"name": "broccoli-rsvg", | ||
"description": "SVG to PNG renderer for Broccoli", | ||
"version": "0.3.0", | ||
"version": "0.3.1", | ||
"author": "Greg V <greg@unrelenting.technology>", | ||
"main": "index.js", | ||
"license": "Unlicense", | ||
"repository": { | ||
@@ -12,6 +11,3 @@ "type": "git", | ||
}, | ||
"license": [{ | ||
"type": "Unlicense", | ||
"url": "http://unlicense.org" | ||
}], | ||
"license": "Unlicense", | ||
"bugs": { | ||
@@ -26,6 +22,6 @@ "url": "https://github.com/myfreeweb/broccoli-rsvg/issues" | ||
"scripts": { | ||
"test": "mocha test/ --full-trace" | ||
"test": "tape 'test/*.js' | tap-spec" | ||
}, | ||
"dependencies": { | ||
"broccoli-caching-writer": "^0.5.5", | ||
"broccoli-caching-writer": "^1.0.0", | ||
"mkdirp": "^0.5.0", | ||
@@ -39,5 +35,5 @@ "walk-sync": "^0.1.2", | ||
"broccoli": "^0.16.3", | ||
"mocha": "^2.2.5", | ||
"should": "^7.0.1" | ||
"tap-spec": "^4.0.2", | ||
"tape": "^4.0.1" | ||
} | ||
} |
@@ -27,5 +27,5 @@ # broccoli-rsvg [![npm version](https://img.shields.io/npm/v/broccoli-rsvg.svg?style=flat)](https://www.npmjs.org/package/broccoli-rsvg) [![npm downloads](https://img.shields.io/npm/dm/broccoli-rsvg.svg?style=flat)](https://www.npmjs.org/package/broccoli-rsvg) [![Build Status](https://img.shields.io/travis/myfreeweb/broccoli-rsvg.svg?style=flat)](https://travis-ci.org/myfreeweb/broccoli-rsvg) [![Dependency Status](https://img.shields.io/gemnasium/myfreeweb/broccoli-rsvg.svg)](https://gemnasium.com/myfreeweb/broccoli-rsvg) [![unlicense](https://img.shields.io/badge/un-license-green.svg?style=flat)](http://unlicense.org) | ||
```js | ||
var renderSvg = require('broccoli-rsvg'); | ||
var renderSvg = require('broccoli-rsvg') | ||
var outputTree = renderSvg(inputTree, fileOptions); | ||
var outputTree = renderSvg(inputTree, fileOptions) | ||
``` | ||
@@ -39,3 +39,3 @@ | ||
```js | ||
var renderSvg = require('broccoli-rsvg'); | ||
var renderSvg = require('broccoli-rsvg') | ||
@@ -54,3 +54,3 @@ var png = renderSvg("svg", { | ||
transformer: function(svg) { | ||
return svg.replace('#000000', '#ffffff'); // You can use elementtree or xmldom here... | ||
return svg.replace('#000000', '#ffffff') // You can use elementtree or xmldom here... | ||
}, | ||
@@ -68,5 +68,5 @@ path: 'logo-black.png', | ||
} | ||
}); | ||
}) | ||
return [svg, png]; | ||
return [svg, png] | ||
``` | ||
@@ -83,3 +83,3 @@ | ||
By participating in this project you agree to follow the [Contributor Code of Conduct](http://contributor-covenant.org/version/1/1/0/). | ||
By participating in this project you agree to follow the [Contributor Code of Conduct](http://contributor-covenant.org/version/1/2/0/). | ||
@@ -86,0 +86,0 @@ ## License |
@@ -1,16 +0,15 @@ | ||
'use strict'; | ||
require('should'); | ||
var fs = require('fs'); | ||
var path = require('path'); | ||
var broccoli = require('broccoli'); | ||
var rsvg = require('../'); | ||
'use strict' | ||
describe('broccoli-rsvg', function() { | ||
it('should create a png file throw errors', function(done) { | ||
var builder = new broccoli.Builder(rsvg('test/svg')); | ||
builder.build().then(function(results) { | ||
fs.existsSync(path.join(results.directory, 'test.png')).should.be.true(); | ||
builder.cleanup().then(function() { done(); }); | ||
}).catch(done); | ||
}); | ||
}); | ||
var test = require('tape') | ||
var fs = require('fs') | ||
var path = require('path') | ||
var broccoli = require('broccoli') | ||
var rsvg = require('../') | ||
test('rsvg', function(t) { | ||
t.plan(1) | ||
var builder = new broccoli.Builder(rsvg('test/svg')) | ||
builder.build().then(function(results) { | ||
t.ok(fs.existsSync(path.join(results.directory, 'test.png')), 'creates a png file') | ||
}).catch(t.end) | ||
}) |
Sorry, the diff of this file is not supported yet
10289
76
+ Addedbroccoli-caching-writer@1.1.0(transitive)
+ Addedbroccoli-read-compat@0.1.3(transitive)
+ Addedcore-object@1.1.0(transitive)
+ Addedlodash-node@3.10.2(transitive)
- Removedbroccoli-caching-writer@0.5.5(transitive)
- Removedcore-object@0.0.3(transitive)
- Removedlodash-node@2.4.1(transitive)