From 7fb39b366a5cc558e0b8facd7a2bf5118fe1adb8 Mon Sep 17 00:00:00 2001 From: Tri Nguyen Date: Wed, 6 Jun 2018 03:25:03 -0400 Subject: make icon its own module (#95) abstract the method to make icon markup into its own module. this allows for it to be used in JavaScript environment that does not have access to nodeism like `fs` or `__dirname` (such as browserify or webpack). this method could potentially be re-used in the browser asset bundle, as it is the same. --- evil-icons.js | 26 +------------------------- icon.js | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+), 25 deletions(-) create mode 100644 icon.js diff --git a/evil-icons.js b/evil-icons.js index fc4ef46..6e58a12 100644 --- a/evil-icons.js +++ b/evil-icons.js @@ -1,31 +1,7 @@ var fs = require('fs'); var spritePath = __dirname + '/assets/sprite.svg'; var sprite = fs.readFileSync(spritePath).toString(); - -function icon(name, options) { - var options = options || {}; - var size = options.size ? ' icon--' + options.size : ''; - var classes = 'icon icon--' + name + size + ' ' + (options.class || ''); - classes = classes.trim(); - - var icon = '' + - '' + - ''; - - var html = '
' + - wrapSpinner(icon, classes) + - '
'; - - return html; -} - -function wrapSpinner(html, klass) { - if (klass.indexOf('spinner') > -1) { - return '
' + html + '
'; - } else { - return html; - } -} +var icon = require('./icon');; function buildParamsFromString(string) { var match, attr, value; diff --git a/icon.js b/icon.js new file mode 100644 index 0000000..1f04b41 --- /dev/null +++ b/icon.js @@ -0,0 +1,26 @@ +module.exports = icon; + +function icon(name, options) { + var options = options || {}; + var size = options.size ? ' icon--' + options.size : ''; + var classes = 'icon icon--' + name + size + ' ' + (options.class || ''); + classes = classes.trim(); + + var icon = '' + + '' + + ''; + + var html = '
' + + wrapSpinner(icon, classes) + + '
'; + + return html; +} + +function wrapSpinner(html, klass) { + if (klass.indexOf('spinner') > -1) { + return '
' + html + '
'; + } else { + return html; + } +} -- cgit v1.2.3