diff --git a/bin/svg-stacker b/bin/svg-stacker index f798a21..801fcca 100755 --- a/bin/svg-stacker +++ b/bin/svg-stacker @@ -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 */ @@ -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) @@ -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 + }); }); } diff --git a/package.json b/package.json index f23f8ab..8902bd1 100644 --- a/package.json +++ b/package.json @@ -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", @@ -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"