diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..e21a66b --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +util/node_modules +material-design-icons diff --git a/update-icons.sh b/update-icons.sh new file mode 100755 index 0000000..c78ffb2 --- /dev/null +++ b/update-icons.sh @@ -0,0 +1,138 @@ +#!/bin/bash +# +# @license +# Copyright (c) 2014 The Polymer Project Authors. All rights reserved. +# This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt +# The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt +# The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt +# Code distributed by Google as part of the polymer project is also +# subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt +# +set -e + +ICONSRC="material-design-icons/" +ORIGIN="git://github.com/google/material-design-icons.git" + +# bootstrap a sparse SVG only checkout +bootstrap() { + mkdir -p ${ICONSRC} + pushd ${ICONSRC} + git init + git config core.sparsecheckout true + echo "*/svg/*_24px.svg" >> .git/info/sparse-checkout + git remote add -f origin ${ORIGIN} + popd +} + +header() { +cat > $1 < + + + + + +ENDL +} + +footer(){ +cat >> $1 < + +ENDL +} + +contains() { + local e + for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done + return 1; +} + +build() { +# dirname of path to current script +local runfrom="${0%[/\\]*}" +local folder="$1" + +# put these sets into one big "icons" set +local default=(action alert content file navigation toggle) + +local name="icons" +local file="../core-icons.html" + +# special docs header for core-icons.html +cat > $file <<'ENDL' + + + + + + +ENDL + +# find all the default icons, sort by basename (in perl), run concat +find "${default[@]/#/$folder}" -name "*24px.svg" | xargs $runfrom/concat-svg.js | sort >> $file + +footer $file + +local dir +for dir in $folder/*/; do + if contains "`basename $dir`" "${default[@]}"; then + continue + fi + echo $dir + name=`basename $dir` + file="../$name-icons.html" + header $file $name + find $dir -name "*24px.svg" | xargs $runfrom/concat-svg.js | sort >> $file + footer $file +done +} + +[ -d ${ICONSRC} ] || bootstrap + +pushd ${ICONSRC} +git pull origin master +popd + +pushd util +npm install +build ../${ICONSRC} +popd diff --git a/util/compile-icon-sets.sh b/util/compile-icon-sets.sh new file mode 100755 index 0000000..d4884a4 --- /dev/null +++ b/util/compile-icon-sets.sh @@ -0,0 +1,73 @@ +#!/bin/bash +# +# @license +# Copyright (c) 2014 The Polymer Project Authors. All rights reserved. +# This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt +# The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt +# The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt +# Code distributed by Google as part of the polymer project is also +# subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt +# + +# dirname of path to current script +runfrom="${0%[/\\]*}" +FOLDER="$1" + +# put these sets into one big "icons" set +DEFAULT=(action alert content file navigation toggle) + +# there are no icons here +BLACKLIST=(moticons common_cfg proprietary) + +header() { +cat > $FILE < + + + + + +ENDL +} + +footer(){ +cat >> $FILE < + +ENDL +} + +contains() { + local e + for e in "${@:2}"; do [[ "$e" == "$1" ]] && return 0; done + return 1; +} + +NAME="icons" +FILE="core-icons.html" +header +# find all the default icons, sort by basename (in perl), run concat +find "${DEFAULT[@]/#/$FOLDER}" -name "*24px.svg" | perl -le 'print sort{($p=$a)=~s|.*/||; ($q=$b)=~s|.*/||; lc($p) cmp lc($q)} <>' | xargs $runfrom/concat-svg.js >> $FILE +footer + +for dir in $FOLDER/*/; do + if contains "`basename $dir`" "${DEFAULT[@]}"; then + continue + fi + if contains "`basename $dir`" "${BLACKLIST[@]}"; then + continue + fi + echo $dir + NAME=`basename $dir` + FILE="$NAME-icons.html" + header + find $dir -name "*24px.svg" | sort | xargs $runfrom/concat-svg.js >> $FILE + footer +done diff --git a/util/concat-svg.js b/util/concat-svg.js new file mode 100755 index 0000000..89eb144 --- /dev/null +++ b/util/concat-svg.js @@ -0,0 +1,64 @@ +#!/usr/bin/env node +/* + * @license + * Copyright (c) 2014 The Polymer Project Authors. All rights reserved. + * This code may only be used under the BSD style license found at http://polymer.github.io/LICENSE.txt + * The complete set of authors may be found at http://polymer.github.io/AUTHORS.txt + * The complete set of contributors may be found at http://polymer.github.io/CONTRIBUTORS.txt + * Code distributed by Google as part of the polymer project is also + * subject to an additional IP rights grant found at http://polymer.github.io/PATENTS.txt + */ + +var fs = require('fs'); +var cheerio = require('cheerio'); +var path = require('path'); + +var cheerioOptions = {xmlMode: true}; +var files = process.argv.slice(2); + +function read(file) { + var content = fs.readFileSync(file, 'utf8'); + return cheerio.load(content, cheerioOptions); +} + +function transmogrify($, name) { + var node = $('svg'); + // remove spacer rectangles + node.find('[fill=none]').remove(); + // remove fill colors + node.find('[fill]').each(function() { + var e = $(this); + var color = e.attr('fill'); + // some "white" nodes are extraneous + if (color === '#FFFFFF') { + e.remove(); + } else { + e.removeAttr('fill'); + } + }); + // remove adobe "save for web" elements + node.find('sfw, metadata').remove(); + // remove empty groups + var innerHTML = $.xml(node.find('*').filter(':not(g)')); + // remove extraneous whitespace + innerHTML = innerHTML.replace(/\t|\r|\n/g, ''); + // add parent group with icon name as id + var output = '' + innerHTML + ''; + // print icon svg + console.log(output); +} + +function path2IconName(file) { + parts = path.basename(file).split('_'); + // remove ic_ + parts.shift(); + // remove _24px.svg + parts.pop(); + return parts.join('-'); +} + +files.forEach(function(file) { + var name = path2IconName(file); + var $ = read(file); + transmogrify($, name); +}); diff --git a/util/package.json b/util/package.json new file mode 100644 index 0000000..49af464 --- /dev/null +++ b/util/package.json @@ -0,0 +1,9 @@ +{ + "name": "concat-svg", + "version": "0.0.0", + "description": "", + "main": "concat-svg.js", + "dependencies": { + "cheerio": "^0.15.0" + } +}