Skip to content

Commit

Permalink
patch- decouple svg.js from app.js and have it as a separate file
Browse files Browse the repository at this point in the history
  • Loading branch information
dkdrk452 committed Nov 23, 2017
1 parent dae1c58 commit ae513e7
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 27 deletions.
16 changes: 15 additions & 1 deletion addon/helpers/inline-svg.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import {
applyClass
} from 'ember-inline-svg/utils/general';

export function inlineSvg(svgs, path, options) {
function inlineSvg(svgs, path, options) {
var jsonPath = dottify(path);
var svg = Ember.get(svgs, jsonPath);

Expand All @@ -20,4 +20,18 @@ export function inlineSvg(svgs, path, options) {
svg = applyClass(svg, options.class);

return Ember.String.htmlSafe(svg);
};

let helper;
if (Ember.Helper && Ember.Helper.helper) {
helper = Ember.Helper.helper(function([path], options) {
return inlineSvg(APP_SVGs, path, options);
});
} else {
helper = Ember.Handlebars.makeBoundHelper(function(path, options) {
return inlineSvg(APP_SVGs, path, options.hash || {});
});
}

export default helper;

16 changes: 1 addition & 15 deletions app/helpers/inline-svg.js
Original file line number Diff line number Diff line change
@@ -1,15 +1 @@
import { inlineSvg } from 'ember-inline-svg/helpers/inline-svg';
import SVGs from '../svgs';

let helper;
if (Ember.Helper && Ember.Helper.helper) {
helper = Ember.Helper.helper(function([path], options) {
return inlineSvg(SVGs, path, options);
});
} else {
helper = Ember.Handlebars.makeBoundHelper(function(path, options) {
return inlineSvg(SVGs, path, options.hash || {});
});
}

export default helper;
export { default } from 'ember-inline-svg/helpers/inline-svg';
21 changes: 11 additions & 10 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,29 +40,30 @@ module.exports = {

return new SVGOptmizer([tree], {svgoConfig: config});
},

treeForApp: function(tree) {
treeForPublic: function(tree) {
var existingPaths = this.svgPaths().filter(function(path) {
return fs.existsSync(path);
});

var svgTrees = existingPaths.map(function(path) {
return new Funnel(path, {
include: [new RegExp(/\.svg$/)]
});
});

var svgs = mergeTrees(svgTrees, {
overwrite: true
});

var optimized = this.optimizeSVGs(svgs);

var manifest = flatiron(optimized, {
outputFile: 'svgs.js',
trimExtensions: true
outputFile: 'assets/svgs.js',
trimExtensions: true,
prefix: 'APP_SVGs = '
});

return mergeTrees([tree, manifest]);
return manifest;
}
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
],
"dependencies": {
"broccoli-caching-writer": "^3.0.3",
"broccoli-flatiron": "0.0.0",
"broccoli-flatiron": "0.1.2",
"broccoli-funnel": "^1.0.1",
"broccoli-merge-trees": "^2.0.0",
"ember-cli-babel": "^5.1.6",
Expand Down

0 comments on commit ae513e7

Please sign in to comment.