Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 20 additions & 15 deletions bin/svg-stacker
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
#!/usr/bin/env node --harmony-proxies
#!/usr/bin/env node

var fs = require('fs')
, path = require('path')
, program = require('commander')
, easy = require('libxmljs-easy')
, xml2js = require('xml2js')
/* -- internal */
, stack = []
/* -- user */
Expand All @@ -12,7 +12,7 @@ var fs = require('fs')
;

program
.version('0.0.2')
.version('0.0.3')
.option('-D, --no-demo', 'disables creation of demo files')
.option('-s, --source [./]', 'source directory: location of svg files [./]', './')
.option('-t, --target [./stack]', 'target directory: location for stack.svg and demo files [SOURCE_DIR/stack]', null)
Expand All @@ -37,23 +37,28 @@ function addToStack(file) {

var id = path.basename(file, '.svg');
var svgXml = fs.readFileSync(file, 'utf-8');
var parser = new xml2js.Parser();
var builder = new xml2js.Builder({headless: true, rootName: 'svg'});
var options = {};

if ( program.huge ) {
options['huge'] = true;
}

var svg = easy.parse(svgXml, options);

// manipulate svg
svg.$class = 'i';
svg.$id = id;

stack.push({
id: id,
svg: svg.$.toString().replace('xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink"', ''),
w: svg.$width,
h: svg.$height

parser.parseString(svgXml, function (err, result) {

// manipulate svg
result.svg.$.class = 'i';
result.svg.$.id = id;
delete result.svg.$['xmlns'];
delete result.svg.$['xmlns:xlink'];

stack.push({
id: id,
svg: builder.buildObject(result.svg),
w: result.svg.$.width,
h: result.svg.$.height
});
});
}

Expand Down
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "svg-stacker",
"version": "0.0.2",
"version": "0.0.3",
"description": "An experimental tool that turns a folder of SVG files into a single SVG Stack",
"keywords": [
"svg",
Expand All @@ -22,7 +22,7 @@
},
"dependencies": {
"commander": "1.0.x",
"libxmljs-easy": "0.2.1"
"xml2js": ""
},
"bugs": "http://github.com/preciousforever/SVG-Stacker/issues",
"bin": "./bin/svg-stacker"
Expand Down