From b756d3fbba7ffdbc1ed175ca4250873fccc841a7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Stalheim=20=C3=98fsdahl?= Date: Sat, 16 Jan 2016 14:39:42 +0100 Subject: [PATCH 1/4] Added react-addons-test-utils --- package.json | 1 + test/main.js | 4 ++-- 2 files changed, 3 insertions(+), 2 deletions(-) diff --git a/package.json b/package.json index d552080..f1a2b6d 100644 --- a/package.json +++ b/package.json @@ -20,6 +20,7 @@ "dependencies" : { "through" : "2.3", "react" : "0.14", + "react-addons-test-utils": "0.14", "babel" : "5.8", "svgo" : "0.5", "extend" : "3.0", diff --git a/test/main.js b/test/main.js index 1e8a9c7..bdb9ac9 100644 --- a/test/main.js +++ b/test/main.js @@ -1,5 +1,5 @@ -var React = require('react/addons'), - TestUtils = React.addons.TestUtils, +var React = require('react'), + TestUtils = require('react-addons-test-utils'), fs = require('fs'), vm = require('vm'), path = require('path'), From d8e0ac85ab8851df9e2a18b204872574f255108c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Stalheim=20=C3=98fsdahl?= Date: Sat, 16 Jan 2016 14:40:13 +0100 Subject: [PATCH 2/4] Added testcase for camelizing attributes --- test/main.js | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/test/main.js b/test/main.js index bdb9ac9..c7ad2e3 100644 --- a/test/main.js +++ b/test/main.js @@ -160,4 +160,20 @@ describe('The app', function () { template: 'all', type : 'icon' })); -}); \ No newline at end of file + + it('should work for all template and camelize dashed element attributes', load('some.svg', function (svg) { + + var component = React.createElement(svg, { + type: 'svg' + }), + rendered = TestUtils.renderIntoDocument(component), + path = TestUtils.findRenderedDOMComponentWithTag(rendered, 'path'); + + (rendered.getDOMNode().tagName.toLowerCase()).should.equal('svg'); + (rendered.getDOMNode().querySelector('path').getAttribute('d')).should.equal('M0 0h100v100H0z'); + (rendered.getDOMNode().querySelector('path').getAttribute('stroke-width')).should.equal('2.5'); + (rendered.getDOMNode().querySelector('path').getAttribute('clip-path')).should.equal('something'); + }, { + template: 'all' + })); +}); From cbed5a81d06ea7d062d01e73a071c3570ba168a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Stalheim=20=C3=98fsdahl?= Date: Sat, 16 Jan 2016 14:40:35 +0100 Subject: [PATCH 3/4] Added options to SVGO to prevent stripping og stroke and fill attributes --- index.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/index.js b/index.js index 340cd41..a99cb39 100644 --- a/index.js +++ b/index.js @@ -12,7 +12,15 @@ var templates = ['all', 'svg', 'icon'], var settings = { babel: {}, - svgo : {} + svgo : { + plugins: [ + { + removeViewBox: false + }, { + removeUselessStrokeAndFill: false + } + ] + } }; var isSVG = function (filename) { @@ -42,12 +50,10 @@ var type = 'svg', var transform = function (filename) { var write = function (buffer) { - data += buffer; }; var end = function () { - svgo.optimize(data, out); }; @@ -56,6 +62,14 @@ var transform = function (filename) { var source = render(filename, svg.data), output = babel.transform(source, settings.babel); + var replaceAttribute = function (a, str) { + return str.replace(/-(.)/g, function (_, letter) { + return letter.toUpperCase(); + }); + }; + + output.code = output.code.replace(/\"(clip-path|fill-opacity|font-family|font-size|marker-end|marker-mid|marker-start|stop-color|stop-opacity|stroke-width|stroke-linecap|stroke-dasharray|stroke-opacity|text-anchor)\"/g, replaceAttribute); + stream.queue(output.code); stream.queue(null); }; From 1c2fa93db98ec3e605e009abad87d8f2286d6a70 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Anders=20Stalheim=20=C3=98fsdahl?= Date: Sat, 16 Jan 2016 14:41:02 +0100 Subject: [PATCH 4/4] Added attributes to test SVG to see if test passes --- test/svg/some.svg | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/svg/some.svg b/test/svg/some.svg index 8db74f6..d59e2a5 100644 --- a/test/svg/some.svg +++ b/test/svg/some.svg @@ -1,4 +1,4 @@ - - \ No newline at end of file + +