diff --git a/.gitignore b/.gitignore index 907c78a..3d28264 100644 --- a/.gitignore +++ b/.gitignore @@ -1,29 +1,4 @@ -# Logs -logs -*.log - -# Runtime data -pids -*.pid -*.seed - -# Directory for instrumented libs generated by jscoverage/JSCover -lib-cov - -# Coverage directory used by tools like istanbul -coverage - -# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files) -.grunt - -# node-waf configuration -.lock-wscript - -# Compiled binary addons (http://nodejs.org/api/addons.html) -build/Release - -# Dependency directory -# https://www.npmjs.org/doc/misc/npm-faq.html#should-i-check-my-node_modules-folder-into-git node_modules - dist +.tmp +*.log diff --git a/README.md b/README.md index 98c2392..fcd5794 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # entypo -411 carefully crafted premium pictograms by Daniel Bruce as a module. [entypo.com](http://www.entypo.com/) CC BY-SA 4.0. +SVG sprite for the [Entypo+](http://entypo.com) icon collection. [![npm][npm-image]][npm-url] [![travis][travis-image]][travis-url] @@ -16,8 +16,24 @@ [standard-image]: https://img.shields.io/badge/code%20style-standard-brightgreen.svg?style=flat-square [standard-url]: http://npm.im/standard +## About + +This is a [node](https://nodejs.org) module that packages the [Entypo+](http://entypo.com) icon collection as a SVG sprite. + +### What is Entypo? + +__411 carefully crafted premium pictograms by [Daniel Bruce](http://www.danielbruce.se/) - [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/).__ + +See [entypo.com](http://entypo.com) for more information. + +### What is a SVG sprite? + +A SVG sprite is a hidden SVG element inserted at the top of the body element that defines a set of icons with unique IDs. These icons can later be referenced throughout the document with the [`` element](https://developer.mozilla.org/en-US/docs/Web/SVG/Element/use). + +Read [Icon System with SVG Sprites](https://css-tricks.com/svg-sprites-use-better-icon-fonts/) by [Chris Coyier](http://chriscoyier.net/) for more information. + ## Install ``` @@ -26,27 +42,487 @@ npm install entypo ## Usage +### Basic + +```js +const entypo = require('entypo') + +const sprite = entypo() + +document.body.innerHTML += sprite +document.body.innerHTML += '' +``` + +### Slightly More Advanced + +```js +const entypo = require('entypo') + +document.body.insertBefore(entypo.getNode(), document.body.firstChild) +``` + +### API + +#### `entypo()` + +- [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function): returns svg sprite file contents as utf-8 text + +You can insert this into the page easily using the [DOM API](https://developer.mozilla.org/en-US/docs/Web/API/Document_Object_Model). You will need to use something like [brfs](https://github.com/substack/brfs) to make this function work. + +#### `entypo.getNode()` + +- [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function): returns svg sprite DOM node + +This a convenience function that returns the svg sprite as a [DOM Node](https://developer.mozilla.org/en-US/docs/Web/API/Node) so that it can be inserted into the `body` element using the DOM API. + +##### Example + ```js -var svgSprite = require('entypo') // Spritesheet contents -console.log(svgSprite.path) // node_modules/entypo/dist/sprite.svg -console.log(svgSprite.rawPath) // node_modules/entypo/Entypo+ -// Then put the contents into the page somehow -document.body.insertBefore(htmlToElement(svgSprite), document.body.firstChild) - -function htmlToElement (html) { - var template = document.createElement('template') - template.innerHTML = html - return template.content.firstChild -} +document.body.insertBefore(entypo.getNode(), document.body.firstChild) ``` -This module packages Entypo+ as a npm installable module, and ships a sprite-sheet for convenience. The sprite-sheet ran the original assets through [svgo](https://github.com/svg/svgo). +#### `entypo.htmlToElement(html: string)` + +- [function](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Function): converts a string to a DOM node + +This is a utility function used by `getNode()` to convert the raw SVG text provided by the main `entypo()` function into a DOM node. + +#### `entypo.path` + +- [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String): path to svg sprite (e.g. `node_modules/entypo/dist/sprite.svg`) + +#### `entypo.rawPath` + +- [string](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String): path to unmodified `Entypo+` directory (e.g. `node_modules/entypo/Entypo+`) + + +### Icon Names + +#### Entypo+ + +Icon | Name +:--: | ---- + | `entypo-add-to-list` + | `entypo-add-user` + | `entypo-address` + | `entypo-adjust` + | `entypo-air` + | `entypo-aircraft-landing` + | `entypo-aircraft-take-off` + | `entypo-aircraft` + | `entypo-align-bottom` + | `entypo-align-horizontal-middle` + | `entypo-align-left` + | `entypo-align-right` + | `entypo-align-top` + | `entypo-align-vertical-middle` + | `entypo-archive` + | `entypo-area-graph` + | `entypo-arrow-bold-down` + | `entypo-arrow-bold-left` + | `entypo-arrow-bold-right` + | `entypo-arrow-bold-up` + | `entypo-arrow-down` + | `entypo-arrow-left` + | `entypo-arrow-long-down` + | `entypo-arrow-long-left` + | `entypo-arrow-long-right` + | `entypo-arrow-long-up` + | `entypo-arrow-right` + | `entypo-arrow-up` + | `entypo-arrow-with-circle-down` + | `entypo-arrow-with-circle-left` + | `entypo-arrow-with-circle-right` + | `entypo-arrow-with-circle-up` + | `entypo-attachment` + | `entypo-awareness-ribbon` + | `entypo-back-in-time` + | `entypo-back` + | `entypo-bar-graph` + | `entypo-battery` + | `entypo-beamed-note` + | `entypo-bell` + | `entypo-blackboard` + | `entypo-block` + | `entypo-book` + | `entypo-bookmark` + | `entypo-bookmarks` + | `entypo-bowl` + | `entypo-box` + | `entypo-briefcase` + | `entypo-browser` + | `entypo-brush` + | `entypo-bucket` + | `entypo-bug` + | `entypo-cake` + | `entypo-calculator` + | `entypo-calendar` + | `entypo-camera` + | `entypo-ccw` + | `entypo-chat` + | `entypo-check` + | `entypo-chevron-down` + | `entypo-chevron-left` + | `entypo-chevron-right` + | `entypo-chevron-small-down` + | `entypo-chevron-small-left` + | `entypo-chevron-small-right` + | `entypo-chevron-small-up` + | `entypo-chevron-thin-down` + | `entypo-chevron-thin-left` + | `entypo-chevron-thin-right` + | `entypo-chevron-thin-up` + | `entypo-chevron-up` + | `entypo-chevron-with-circle-down` + | `entypo-chevron-with-circle-left` + | `entypo-chevron-with-circle-right` + | `entypo-chevron-with-circle-up` + | `entypo-circle-with-cross` + | `entypo-circle-with-minus` + | `entypo-circle-with-plus` + | `entypo-circle` + | `entypo-circular-graph` + | `entypo-clapperboard` + | `entypo-classic-computer` + | `entypo-clipboard` + | `entypo-clock` + | `entypo-cloud` + | `entypo-code` + | `entypo-cog` + | `entypo-colours` + | `entypo-compass` + | `entypo-controller-fast-backward` + | `entypo-controller-fast-forward` + | `entypo-controller-jump-to-start` + | `entypo-controller-next` + | `entypo-controller-paus` + | `entypo-controller-play` + | `entypo-controller-record` + | `entypo-controller-stop` + | `entypo-controller-volume` + | `entypo-copy` + | `entypo-creative-commons-attribution` + | `entypo-creative-commons-noderivs` + | `entypo-creative-commons-noncommercial-eu` + | `entypo-creative-commons-noncommercial-us` + | `entypo-creative-commons-public-domain` + | `entypo-creative-commons-remix` + | `entypo-creative-commons-share` + | `entypo-creative-commons-sharealike` + | `entypo-creative-commons` + | `entypo-credit-card` + | `entypo-credit` + | `entypo-crop` + | `entypo-cross` + | `entypo-cup` + | `entypo-cw` + | `entypo-cycle` + | `entypo-database` + | `entypo-dial-pad` + | `entypo-direction` + | `entypo-document-landscape` + | `entypo-document` + | `entypo-documents` + | `entypo-dot-single` + | `entypo-dots-three-horizontal` + | `entypo-dots-three-vertical` + | `entypo-dots-two-horizontal` + | `entypo-dots-two-vertical` + | `entypo-download` + | `entypo-drink` + | `entypo-drive` + | `entypo-drop` + | `entypo-edit` + | `entypo-email` + | `entypo-emoji-flirt` + | `entypo-emoji-happy` + | `entypo-emoji-neutral` + | `entypo-emoji-sad` + | `entypo-erase` + | `entypo-eraser` + | `entypo-export` + | `entypo-eye-with-line` + | `entypo-eye` + | `entypo-feather` + | `entypo-fingerprint` + | `entypo-flag` + | `entypo-flash` + | `entypo-flashlight` + | `entypo-flat-brush` + | `entypo-flow-branch` + | `entypo-flow-cascade` + | `entypo-flow-line` + | `entypo-flow-parallel` + | `entypo-flow-tree` + | `entypo-flower` + | `entypo-folder-images` + | `entypo-folder-music` + | `entypo-folder-video` + | `entypo-folder` + | `entypo-forward` + | `entypo-funnel` + | `entypo-game-controller` + | `entypo-gauge` + | `entypo-globe` + | `entypo-graduation-cap` + | `entypo-grid` + | `entypo-hair-cross` + | `entypo-hand` + | `entypo-heart-outlined` + | `entypo-heart` + | `entypo-help-with-circle` + | `entypo-help` + | `entypo-home` + | `entypo-hour-glass` + | `entypo-image-inverted` + | `entypo-image` + | `entypo-images` + | `entypo-inbox` + | `entypo-infinity` + | `entypo-info-with-circle` + | `entypo-info` + | `entypo-install` + | `entypo-key` + | `entypo-keyboard` + | `entypo-lab-flask` + | `entypo-landline` + | `entypo-language` + | `entypo-laptop` + | `entypo-layers` + | `entypo-leaf` + | `entypo-level-down` + | `entypo-level-up` + | `entypo-lifebuoy` + | `entypo-light-bulb` + | `entypo-light-down` + | `entypo-light-up` + | `entypo-line-graph` + | `entypo-link` + | `entypo-list` + | `entypo-location-pin` + | `entypo-location` + | `entypo-lock-open` + | `entypo-lock` + | `entypo-log-out` + | `entypo-login` + | `entypo-loop` + | `entypo-magnet` + | `entypo-magnifying-glass` + | `entypo-mail` + | `entypo-man` + | `entypo-map` + | `entypo-mask` + | `entypo-medal` + | `entypo-megaphone` + | `entypo-menu` + | `entypo-merge` + | `entypo-message` + | `entypo-mic` + | `entypo-minus` + | `entypo-mobile` + | `entypo-modern-mic` + | `entypo-moon` + | `entypo-mouse-pointer` + | `entypo-mouse` + | `entypo-music` + | `entypo-network` + | `entypo-new-message` + | `entypo-new` + | `entypo-news` + | `entypo-newsletter` + | `entypo-note` + | `entypo-notification` + | `entypo-notifications-off` + | `entypo-old-mobile` + | `entypo-old-phone` + | `entypo-open-book` + | `entypo-palette` + | `entypo-paper-plane` + | `entypo-pencil` + | `entypo-phone` + | `entypo-pie-chart` + | `entypo-pin` + | `entypo-plus` + | `entypo-popup` + | `entypo-power-plug` + | `entypo-price-ribbon` + | `entypo-price-tag` + | `entypo-print` + | `entypo-progress-empty` + | `entypo-progress-full` + | `entypo-progress-one` + | `entypo-progress-two` + | `entypo-publish` + | `entypo-quote` + | `entypo-radio` + | `entypo-remove-user` + | `entypo-reply-all` + | `entypo-reply` + | `entypo-resize-100%` + | `entypo-resize-full-screen` + | `entypo-retweet` + | `entypo-rocket` + | `entypo-round-brush` + | `entypo-rss` + | `entypo-ruler` + | `entypo-save` + | `entypo-scissors` + | `entypo-select-arrows` + | `entypo-share-alternative` + | `entypo-share` + | `entypo-shareable` + | `entypo-shield` + | `entypo-shop` + | `entypo-shopping-bag` + | `entypo-shopping-basket` + | `entypo-shopping-cart` + | `entypo-shuffle` + | `entypo-signal` + | `entypo-sound-mix` + | `entypo-sound-mute` + | `entypo-sound` + | `entypo-sports-club` + | `entypo-spreadsheet` + | `entypo-squared-cross` + | `entypo-squared-minus` + | `entypo-squared-plus` + | `entypo-star-outlined` + | `entypo-star` + | `entypo-stopwatch` + | `entypo-suitcase` + | `entypo-swap` + | `entypo-sweden` + | `entypo-switch` + | `entypo-tablet-mobile-combo` + | `entypo-tablet` + | `entypo-tag` + | `entypo-text-document-inverted` + | `entypo-text-document` + | `entypo-text` + | `entypo-thermometer` + | `entypo-thumbs-down` +"> | `entypo-thumbs-up` + | `entypo-thunder-cloud` + | `entypo-ticket` + | `entypo-time-slot` + | `entypo-tools` + | `entypo-traffic-cone` + | `entypo-trash` + | `entypo-tree` + | `entypo-triangle-down` + | `entypo-triangle-left` + | `entypo-triangle-right` + | `entypo-triangle-up` + | `entypo-trophy` + | `entypo-tv` + | `entypo-typing` + | `entypo-uninstall` + | `entypo-unread` + | `entypo-untag` + | `entypo-upload-to-cloud` + | `entypo-upload` + | `entypo-user` + | `entypo-users` + | `entypo-v-card` + | `entypo-video-camera` + | `entypo-video` + | `entypo-vinyl` + | `entypo-voicemail` + | `entypo-wallet` + | `entypo-warning` + | `entypo-water` + +#### Entypo+ Social Extension + + +Icon | Name +---- | ---- + | `entypo-500px-with-circle` + | `entypo-500px` + | `entypo-app-store` + | `entypo-baidu` + | `entypo-basecamp` + | `entypo-behance` + | `entypo-creative-cloud` + | `entypo-dribbble-with-circle` + | `entypo-dribbble` + | `entypo-dropbox` + | `entypo-evernote` + | `entypo-facebook-with-circle` + | `entypo-facebook` + | `entypo-flattr` + | `entypo-flickr-with-circle` + | `entypo-flickr` + | `entypo-foursquare` + | `entypo-github-with-circle` + | `entypo-github` + | `entypo-google+-with-circle` + | `entypo-google+` + | `entypo-google-drive` + | `entypo-google-hangouts` + | `entypo-google-play` + | `entypo-grooveshark` + | `entypo-houzz` + | `entypo-icloud` + | `entypo-instagram-with-circle` + | `entypo-instagram` + | `entypo-lastfm-with-circle` + | `entypo-lastfm` + | `entypo-linkedin-with-circle` + | `entypo-linkedin` + | `entypo-mail-with-circle` + | `entypo-medium-with-circle` + | `entypo-medium` + | `entypo-mixi` + | `entypo-onedrive` + | `entypo-paypal` + | `entypo-picasa` + | `entypo-pinterest-with-circle` + | `entypo-pinterest` + | `entypo-qq-with-circle` + | `entypo-qq` + | `entypo-raft-with-circle` + | `entypo-raft` + | `entypo-rainbow` + | `entypo-rdio-with-circle` + | `entypo-rdio` + | `entypo-renren` + | `entypo-scribd` + | `entypo-sina-weibo` + | `entypo-skype-with-circle` + | `entypo-skype` + | `entypo-slideshare` + | `entypo-smashing` + | `entypo-soundcloud` + | `entypo-spotify-with-circle` + | `entypo-spotify` + | `entypo-stumbleupon-with-circle` + | `entypo-stumbleupon` + | `entypo-swarm` + | `entypo-tripadvisor` + | `entypo-tumblr-with-circle` + | `entypo-tumblr` + | `entypo-twitter-with-circle` + | `entypo-twitter` + | `entypo-vimeo-with-circle` + | `entypo-vimeo` + | `entypo-vine-with-circle` + | `entypo-vine` + | `entypo-vk-alternitive` + | `entypo-vk-with-circle` + | `entypo-vk` + | `entypo-windows-store` + | `entypo-xing-with-circle` + | `entypo-xing` + | `entypo-yelp` + | `entypo-youko-with-circle` + | `entypo-youko` + | `entypo-youtube-with-circle` + | `entypo-youtube` -The JS module exports 3 things: +## Example -- The contents of the sprite sheet. You can insert this into the page easily using the DOM api. You will need to use something like [BRFS](https://github.com/substack/brfs) to make this function work. -- The path to the sprite sheet is also exported. You can use this with some other kind of asset loading method. -- A path to the original Entypo+ folder with all of the untouched raw SVGs. +To see an example implementation, try `npm run example`. Source code is in [`example.js`](example.js). ## Contributing @@ -57,4 +533,4 @@ Daniel Bruce, if you are reading this, send me an email if you want commit / rel ## License - Module: [ISC](LICENSE.md) -- Icons: CC BY-SA 4.0. +- Icons: [CC BY-SA 4.0](https://creativecommons.org/licenses/by-sa/4.0/). diff --git a/example.js b/example.js new file mode 100644 index 0000000..43f3ac6 --- /dev/null +++ b/example.js @@ -0,0 +1,81 @@ +const entypo = require('./') +const node = entypo.getNode() + +const head = document.getElementsByTagName('head')[0] +const style = document.createElement('style') + +style.setAttribute('type', 'text/css') +style.textContent += ` + * { box-sizing: border-box } + html { + font-family: -apple-system, sans-serif; + font-size: 14px; + } + body { + background: #1e1e1e; + color: #fff; + display: flex; + flex-flow: row wrap; + padding: 0 10% 6em; + } + header { + width: 100%; + margin: 3em 0; + } + h1 { + font-weight: 300; + } + h1 a { + color: #fff; + } + a { + color: gold; + text-decoration: none; + } + .icon { + display: flex; + align-items: center; + width: 16%; + min-width: 240px; + padding: .5em; + } + .icon svg { + height: 2em; + width: 2em; + fill: #fff; + } + .icon span { + padding-left: 1em; + } +` +head.appendChild(style) + +document.body.insertBefore(entypo.getNode(), document.body.firstChild) + +document.body.innerHTML += ` +
+

entypo

+

SVG sprite for the Entypo+ icon collection.

+

+ + + + + + + + + + +

+
+` + +node.querySelectorAll('[id]').forEach(svg => { + document.body.innerHTML += ` +
+ + ${svg.id.replace('entypo-', '')} +
+ ` +}) diff --git a/index.js b/index.js index 604e9ec..b339e07 100644 --- a/index.js +++ b/index.js @@ -5,8 +5,7 @@ var spritePath = path.join(__dirname, 'dist', 'sprite.svg') var svgPath = path.join(__dirname, 'Entypo+') function main () { - var svgSprite = fs.readFileSync(spritePath, 'utf8') - return svgSprite + return fs.readFileSync(path.join(__dirname, 'dist', 'sprite.svg'), 'utf8') } function htmlToElement (html) { diff --git a/package.json b/package.json index 36990ec..c667dfa 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "entypo", - "description": "411 carefully crafted premium pictograms by Daniel Bruce", + "description": "SVG sprite for the Entypo+ icon collection.", "version": "1.0.2", "author": "Bret Comnes ", "bugs": { @@ -30,15 +30,16 @@ "url": "https://github.com/hypermodules/entypo.git" }, "scripts": { - "test": "standard && tape test/*.js | tap-spec", - "prepublish": "npm run build", "build": "run-s clean optimize make-sprite clean:tmp", - "make-sprite": "mkdirp dist && spritesh -i node_modules/.tmp -o dist/sprite.svg --prefix entypo-", - "optimize": "run-p optimize:*", - "optimize:base": "svgo -f Entypo+/Entypo+ -o node_modules/.tmp", - "optimize:social": "svgo -f Entypo+/Entypo+\\ Social\\ Extension -o node_modules/.tmp", "clean": "run-p clean:*", - "clean:tmp": "rimraf node_modules/.tmp", - "clean:dist": "rimraf dist" + "clean:dist": "rimraf dist", + "clean:tmp": "rimraf .tmp", + "example": "budo example.js --open --live -- -t brfs", + "make-sprite": "mkdirp dist && spritesh -i .tmp -o dist/sprite.svg --prefix entypo-", + "optimize": "run-p optimize:*", + "optimize:base": "svgo -f Entypo+/Entypo+ -o .tmp", + "optimize:social": "svgo -f Entypo+/Entypo+\\ Social\\ Extension -o .tmp", + "prepublish": "npm run build", + "test": "standard && tape test/*.js | tap-spec" } } diff --git a/test/index.js b/test/index.js index 9bf8e88..525b948 100644 --- a/test/index.js +++ b/test/index.js @@ -1,9 +1,11 @@ var test = require('tape') var entypo = require('../') -test('Example Test', function (t) { - t.plan(3) +test('API contract', function (t) { t.equal(typeof entypo, 'function', 'main export is a function') t.equal(typeof entypo.path, 'string', 'path exports a string') t.equal(typeof entypo.rawPath, 'string', 'rawPath exports a string') + t.equal(typeof entypo.htmlToElement, 'function', 'htmlToElement exports a function') + t.equal(typeof entypo.getNode, 'function', 'getNode exports a function') + t.end() })