From ae513e70c50aafc2c739ec3f76af9faa74029b16 Mon Sep 17 00:00:00 2001 From: "kumar.devaraj" Date: Tue, 10 Oct 2017 14:05:21 +0530 Subject: [PATCH] patch- decouple svg.js from app.js and have it as a separate file --- addon/helpers/inline-svg.js | 16 +++++++++++++++- app/helpers/inline-svg.js | 16 +--------------- index.js | 21 +++++++++++---------- package.json | 2 +- 4 files changed, 28 insertions(+), 27 deletions(-) diff --git a/addon/helpers/inline-svg.js b/addon/helpers/inline-svg.js index cebce9e..b174b4a 100644 --- a/addon/helpers/inline-svg.js +++ b/addon/helpers/inline-svg.js @@ -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); @@ -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; + diff --git a/app/helpers/inline-svg.js b/app/helpers/inline-svg.js index a52a7fd..b6e6dd6 100644 --- a/app/helpers/inline-svg.js +++ b/app/helpers/inline-svg.js @@ -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'; diff --git a/index.js b/index.js index a0eb10b..f2ab30f 100644 --- a/index.js +++ b/index.js @@ -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; } }; diff --git a/package.json b/package.json index e6c8f3f..aada715 100644 --- a/package.json +++ b/package.json @@ -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",