ember-inline-svg
Advanced tools
Comparing version 0.0.3 to 0.1.0
@@ -9,3 +9,11 @@ import Ember from 'ember'; | ||
export function inlineSvg(path, options) { | ||
var svg = Ember.get(SVGs, dottify(path)); | ||
var jsonPath = dottify(path); | ||
var svg = Ember.get(SVGs, jsonPath); | ||
// TODO: Ember.get should return `null`, not `undefined`. | ||
// if (svg === null && /\.svg$/.test(path)) | ||
if (typeof svg === "undefined" && /\.svg$/.test(path)) { | ||
svg = Ember.get(SVGs, jsonPath.slice(0, -4)); | ||
} | ||
Ember.assert("No SVG found for "+path, svg); | ||
@@ -19,2 +27,2 @@ | ||
export default Ember.Handlebars.makeBoundHelper(inlineSvg); | ||
export default Ember.Handlebars.makeBoundHelper(inlineSvg); |
@@ -5,2 +5,10 @@ # CHANGELOG | ||
## v0.1.0 | ||
* #5 The path to an image can now optionally have a `.svg` extension. | ||
* #6 The default source directory changed from `./public/images` to `./public`. | ||
* #7 If there is an error during SVG optimization, the build is now aborted and a descriptive error is displayed. | ||
* #7 If there are no images present, nothing happens and the build continues. [More info](https://github.com/minutebase/ember-inline-svg/issues/1#issuecomment-70625510). | ||
* #9 Refactored tests to be independent of one another. | ||
## v0.0.3 | ||
@@ -16,2 +24,2 @@ | ||
* initial release | ||
* initial release |
27
index.js
/* jshint node: true */ | ||
'use strict'; | ||
var fs = require('fs'); | ||
var merge = require('merge') | ||
var mergeTrees = require('broccoli-merge-trees'); | ||
var flattenFolder = require('broccoli-spelunk'); | ||
var pickFiles = require('broccoli-static-compiler'); | ||
var SVGOptmizer = require('./svg-optimizer'); | ||
var fs = require('fs'); | ||
var merge = require('merge') | ||
var mergeTrees = require('broccoli-merge-trees'); | ||
var flatiron = require('broccoli-flatiron'); | ||
var Funnel = require('broccoli-funnel'); | ||
var SVGOptmizer = require('./svg-optimizer'); | ||
@@ -16,3 +16,3 @@ module.exports = { | ||
return merge(true, {}, { | ||
paths: ['public/images'], | ||
paths: ['public'], | ||
optimize: { /* svgo defaults */ } | ||
@@ -24,3 +24,3 @@ }, this.app.options.svg || {}); | ||
if (this.isDevelopingAddon()) { | ||
return ['tests/dummy/public/images']; | ||
return ['tests/dummy/public']; | ||
} | ||
@@ -44,6 +44,4 @@ return this.options().paths; | ||
svgs = pickFiles(svgs, { | ||
srcDir: '/', | ||
files: ['**/*.svg'], | ||
destDir: '/' | ||
svgs = new Funnel(svgs, { | ||
include: [new RegExp(/\.svg$/)] | ||
}); | ||
@@ -53,6 +51,5 @@ | ||
svgs = flattenFolder(svgs, { | ||
svgs = flatiron(svgs, { | ||
outputFile: 'svgs.js', | ||
mode: 'es6', | ||
keepExtensions: false | ||
trimExtensions: true | ||
}); | ||
@@ -59,0 +56,0 @@ |
{ | ||
"name": "ember-inline-svg", | ||
"description": "Ember CLI addon to render SVG images inline", | ||
"version": "0.0.3", | ||
"version": "0.1.0", | ||
"directories": { | ||
@@ -48,4 +48,4 @@ "doc": "doc", | ||
"broccoli-merge-trees": "^0.2.1", | ||
"broccoli-spelunk": "^0.1.2", | ||
"broccoli-static-compiler": "^0.2.1", | ||
"broccoli-flatiron": "^0.0.0", | ||
"broccoli-funnel": "^0.1.7", | ||
"merge": "^1.2.0", | ||
@@ -52,0 +52,0 @@ "mkdirp": "^0.5.0", |
@@ -32,2 +32,8 @@ var CachingWriter = require('broccoli-caching-writer'); | ||
svgo.optimize(rawSVG, function(result) { | ||
if (result.error) { | ||
var error = new Error(result.error); | ||
error.file = relativePath; | ||
return reject(error); | ||
} | ||
fs.writeFileSync(destPath, result.data, { encoding: 'utf8'}); | ||
@@ -41,2 +47,2 @@ resolve(); | ||
} | ||
}); | ||
}); |
@@ -16,3 +16,3 @@ import Ember from 'ember'; | ||
test('displays SVG at root', function() { | ||
visit('/'); | ||
visit('/root'); | ||
@@ -25,3 +25,3 @@ andThen(function() { | ||
test('displays SVG in subdirectory', function() { | ||
visit('/'); | ||
visit('/subdirectory'); | ||
@@ -34,7 +34,15 @@ andThen(function() { | ||
test('adds class to SVG', function() { | ||
visit('/'); | ||
visit('/class'); | ||
andThen(function() { | ||
ok(find(".kiwi-image-in-directory svg.with-a-class").length, "has added the class"); | ||
ok(find(".kiwi-image-with-a-class svg.with-a-class").length, "has added the class"); | ||
}); | ||
}); | ||
}); | ||
test('trims unnecessary .svg` extension', function() { | ||
visit('/extension'); | ||
andThen(function() { | ||
ok(find(".kiwi-image-with-extension svg").length, "has an SVG, extension was trimmed"); | ||
}); | ||
}); |
@@ -9,4 +9,8 @@ import Ember from 'ember'; | ||
Router.map(function() { | ||
this.route("root"); | ||
this.route("subdirectory"); | ||
this.route("class"); | ||
this.route("extension"); | ||
}); | ||
export default Router; |
Sorry, the diff of this file is not supported yet
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
26203
54
309
+ Addedbroccoli-flatiron@^0.0.0
+ Addedbroccoli-funnel@^0.1.7
+ Addedbroccoli-flatiron@0.0.0(transitive)
+ Addedbroccoli-funnel@0.1.7(transitive)
+ Addedcore-object@0.0.2(transitive)
+ Addedminimatch@2.0.10(transitive)
+ Addedmkdirp@0.3.5(transitive)
+ Addedrsvp@3.0.21(transitive)
- Removedbroccoli-spelunk@^0.1.2
- Removedbroccoli-static-compiler@^0.2.1
- Removedbroccoli-spelunk@0.1.2(transitive)
- Removedbroccoli-static-compiler@0.2.2(transitive)
- Removedes6-promise@1.0.0(transitive)
- Removedfs-extra@0.9.1(transitive)
- Removedgraceful-fs@2.0.3(transitive)
- Removedjsonfile@1.1.1(transitive)
- Removedlru-cache@2.7.3(transitive)
- Removedminimatch@0.2.14(transitive)
- Removedncp@0.5.1(transitive)
- Removedsigmund@1.0.1(transitive)
- Removedspelunk@0.1.2(transitive)
- Removedtosource@0.1.3(transitive)