Created
October 29, 2018 18:37
-
-
Save rondale-sc/01b2e38f605bffc745678d015b5027e7 to your computer and use it in GitHub Desktop.
Glimmer Inline SVG
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// src/utilities/inline-svg/helper.js | |
// @ts-ignore: | |
import { svgs } from '../../../utils/svgs'; | |
function dottify(path) { | |
return (path || '').replace(/^\//g, '').replace(/\//g, '.'); | |
} | |
export default function inlineSvg([path]) { | |
let jsonPath = dottify(path); | |
let svg = svgs[jsonPath]; | |
return { | |
string: svg, | |
toHTML() { | |
return this.string; | |
}, | |
toString() { | |
return this.string; | |
} | |
}; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in-repo addon | |
/* eslint-env node */ | |
'use strict'; | |
var mergeTrees = require('broccoli-merge-trees'); | |
var Funnel = require('broccoli-funnel'); | |
var flatiron = require('broccoli-flatiron'); | |
var BroccoliDebug = require('broccoli-debug'); | |
module.exports = { | |
name: 'inline-svg', | |
isDevelopingAddon() { | |
return true; | |
}, | |
preprocessTree(type, tree) { | |
if (type === 'src') { | |
let debugTree = BroccoliDebug.buildDebugCallback(`inline-svg-addon`); | |
let svgTree = new Funnel('svgs', { | |
include: [new RegExp(/\.svg$/)] | |
}); | |
let manifest = flatiron(svgTree, { | |
outputFile: 'src/utils/svgs.ts', | |
prefix: 'export let svgs = ', | |
trimExtensions: true | |
}); | |
manifest = debugTree(manifest, 'manifest'); | |
tree = debugTree(tree, 'srcTree'); | |
let finalOutput = debugTree(new mergeTrees([tree, manifest]), 'src_manifest_merged'); | |
return finalOutput; | |
} else { | |
return tree; | |
} | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment