Skip to content

Commit

Permalink
ES6, woff2 and some cleaning for readability
Browse files Browse the repository at this point in the history
  • Loading branch information
cognitom committed Feb 27, 2016
1 parent 461a2c7 commit a63df6c
Show file tree
Hide file tree
Showing 8 changed files with 128 additions and 131 deletions.
92 changes: 25 additions & 67 deletions README.md
Expand Up @@ -68,15 +68,9 @@ We use these plugin for gulp.js, FYI.

### Sketch and Sketch Tools

You haven't got Sketch yet? Visit [App Store](https://itunes.apple.com/jp/app/sketch-3/id852320343?l=en&mt=12). It's worth more than its price tag. Next, get the `sketchtool` to extract the data from `.sketch` files via CLI.
You haven't got Sketch yet? Visit [their site](http://sketchapp.com/). It's worth more than its price tag. Sketch bundles CLI tool, too. You can use `sketchtool` command to extract the data from `.sketch` files.

To get the tool, run this command:

```bash
$ npm run installtool
```

Or, you can do the same thing manually. See [install sketchtool manually](#install-sketchtool-manually).
Note: from ver 3.5, `sketchtool` has become an out-of-box feature. You don't have to install it seperately.


## Draw Icons
Expand Down Expand Up @@ -112,53 +106,23 @@ Then check the `dist` directory. There'll be the font and CSS files generated.

### Config

If you want to change the name of your font, see the gulpfile.js and modify it.
If you want to change the name of your font, see the [gulpfile.js](gulpfile.js) and modify it.

To change the name or style of your font, it would be enough just changing the part below:

```javascript
var gulp = require("gulp");
var rename = require("gulp-rename");
var sketch = require("gulp-sketch");
var iconfont = require('gulp-iconfont');
var consolidate = require('gulp-consolidate');
var gulpImagemin = require('gulp-imagemin'); // simplify the svg in case you run into troubles with transformed elements

var fontName = 'symbols'; // set name of your symbol font
var template = 'fontawesome-style'; // you can also choose 'foundation-style'

gulp.task('symbols', function(){
gulp.src("symbol-font-14px.sketch") // you can also choose "symbol-font-16px.sketch"
.pipe(sketch({
export: 'artboards',
formats: 'svg'
}))
.pipe(gulpImagemin()) // pipe image-min before you pass it to the iconfont task
.pipe(iconfont({ fontName: fontName }))
.on('codepoints', function(codepoints) {
var options = {
glyphs: codepoints,
fontName: fontName,
fontPath: '../fonts/', // set path to font (from your CSS file if relative)
className: 's' // set class name in your CSS
};
gulp.src('templates/' + template + '.css')
.pipe(consolidate('lodash', options))
.pipe(rename({ basename:fontName }))
.pipe(gulp.dest('dist/css/')); // set path to export your CSS

// if you don't need sample.html, remove next 4 lines
gulp.src('templates/' + template + '.html')
.pipe(consolidate('lodash', options))
.pipe(rename({ basename:'sample' }))
.pipe(gulp.dest('dist/')); // set path to export your sample HTML

// if you don't need android string xml, remove next 4 lines
gulp.src('templates/' + template + '.xml')
.pipe(consolidate('lodash', options))
.pipe(rename({ basename:fontName }))
.pipe(gulp.dest('dist/android/')); // set path to export your android res/value
})
.pipe(gulp.dest('dist/fonts/')); // set path to export your fonts
});
/**
* Font settings
*/
const
// set name of your symbol font
fontName = 'symbols',
// set class name in your CSS
className = 's',
// you can also choose 'foundation-style'
template = 'fontawesome-style',
// you can also choose 'symbol-font-16px.sketch'
skethcFileName = 'symbol-font-14px.sketch'
```


Expand Down Expand Up @@ -187,6 +151,13 @@ You can choose CSS Style templates, and make your own with [lodash template](htt
```


## Variations

### Android

See [variants/android](variants/android) directory.


## Trouble Shooting

#### Case 1: Icons with circle 'filled' with black
Expand Down Expand Up @@ -219,22 +190,9 @@ Conditions:

Solution: Pipe [gulp-imagemin](https://github.com/sindresorhus/gulp-imagemin) before the iconfont task, which basically makes use of the [SVG Optimizer](https://github.com/svg/svgo) and collapses multiple transformations.

## Install sketchtool manually

You can install `sketchtool` by `$ npm run installtool` as mentioned already, but if you prefer to do it manually, follow the steps below:

0. Download [Sketch Tools](http://sketchtool.bohemiancoding.com/sketchtool-latest.zip).
0. Unzip the archive.
0. Open Terminal.
0. Change the current directory to the unziped folder.
0. Run the instll script and enter your password.

```bash
$ cd ~/Downloads/sketchtools/
$ sudo ./install.sh
```

## History

- 2.0.0: ES6, WOFF2, and adding variations (for Android app by @weitsai)
- 1.2.0: Catch up versions, simplify the instruction
- 1.1.0: Catch up to [gulp-iconfont v2](https://github.com/nfroidure/gulp-iconfont)([svgicons2svgfont](https://github.com/nfroidure/svgicons2svgfont))
84 changes: 51 additions & 33 deletions gulpfile.js
@@ -1,49 +1,67 @@
var gulp = require("gulp");
var rename = require("gulp-rename");
var sketch = require("gulp-sketch");
var iconfont = require('gulp-iconfont');
var consolidate = require('gulp-consolidate');
const
gulp = require('gulp'),
rename = require('gulp-rename'),
sketch = require('gulp-sketch'),
iconfont = require('gulp-iconfont'),
consolidate = require('gulp-consolidate')

var fontName = 'symbols'; // set name of your symbol font
var fontCssClassName = 's'; // set class name in your CSS
var template = 'fontawesome-style'; // you can also choose 'foundation-style'
var skethcFileName = 'symbol-font-14px.sketch'; // you can also choose 'symbol-font-16px.sketch'
/**
* Font settings
*/
const
// set name of your symbol font
fontName = 'symbols',
// set class name in your CSS
className = 's',
// you can also choose 'foundation-style'
template = 'fontawesome-style',
// you can also choose 'symbol-font-16px.sketch'
skethcFileName = 'symbol-font-14px.sketch'

gulp.task('symbols', function(){
/**
* Recommended to get consistent builds when watching files
* See https://github.com/nfroidure/gulp-iconfont
*/
const timestamp = Math.round(Date.now() / 1000)

gulp.task('symbols', () =>
gulp.src(skethcFileName)
.pipe(sketch({
export: 'artboards',
formats: 'svg'
}))
.pipe(iconfont({
fontName: fontName,
formats: ['ttf', 'eot', 'woff', 'svg']
fontName,
formats: ['ttf', 'eot', 'woff', 'woff2', 'svg'],
timestamp,
log: () => {} // suppress unnecessary logging
}))
.on('glyphs', function(glyphs) {
var options = {
glyphs: glyphs.map(function(glyph) {
// this line is needed because gulp-iconfont has changed the api from 2.0
return { name: glyph.name, codepoint: glyph.unicode[0].charCodeAt(0) }
}),
fontName: fontName,
.on('glyphs', (glyphs) => {
const options = {
className,
fontName,
fontPath: '../fonts/', // set path to font (from your CSS file if relative)
className: fontCssClassName
};

gulp.src('templates/' + template + '.css')
glyphs: glyphs.map(mapGlyphs)
}
gulp.src(`templates/${ template }.css`)
.pipe(consolidate('lodash', options))
.pipe(rename({ basename:fontName }))
.pipe(gulp.dest('dist/css/')); // set path to export your CSS
.pipe(rename({ basename: fontName }))
.pipe(gulp.dest('dist/css/')) // set path to export your CSS

// if you don't need sample.html, remove next 4 lines
gulp.src('templates/' + template + '.html')
gulp.src(`templates/${ template }.html`)
.pipe(consolidate('lodash', options))
.pipe(rename({ basename:'sample' }))
.pipe(gulp.dest('dist/')); // set path to export your sample HTML
.pipe(rename({ basename: 'sample' }))
.pipe(gulp.dest('dist/')) // set path to export your sample HTML
})
.pipe(gulp.dest('dist/fonts/')); // set path to export your fonts
});
.pipe(gulp.dest('dist/fonts/')) // set path to export your fonts
)

gulp.task('watch', () => gulp.watch('*.sketch', ['symbols']))

gulp.task('watch', function(){
gulp.watch('*.sketch/Data', { debounceDelay: 3000 }, ['symbols']); // wait 3 sec after the last run
});
/**
* This is needed for mapping glyphs and codepoints.
*/
function mapGlyphs(glyph) {
return { name: glyph.name, codepoint: glyph.unicode[0].charCodeAt(0) }
}
13 changes: 6 additions & 7 deletions package.json
@@ -1,6 +1,6 @@
{
"name": "symbols-for-sketch",
"version": "1.2.0",
"version": "2.0.0",
"homepage": "https://github.com/cognitom/symbols-for-sketch",
"repository": {
"type": "git",
Expand All @@ -9,7 +9,7 @@
"description": "Symbol font templates for Sketch.app",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1",
"installtool": "curl -L https://raw.githubusercontent.com/cognitom/dotfiles/master/lib/sketchtool.sh | sudo sh"
"installtool": "curl -L https://raw.githubusercontent.com/cognitom/gulp-sketch/master/install-sketchtool.sh | sudo sh"
},
"keywords": [
"symbol font",
Expand All @@ -20,12 +20,11 @@
"author": "Tsutomu Kawamura <tsutomu@librize.com>",
"license": "MIT",
"devDependencies": {
"coffee-script": "^1.9.3",
"gulp": "^3.9.0",
"gulp": "^3.9.1",
"gulp-consolidate": "^0.1.2",
"gulp-iconfont": "^5.0.0",
"gulp-iconfont": "^6.0.0",
"gulp-rename": "^1.2.2",
"gulp-sketch": "^0.1.0",
"lodash": "^3.9.3"
"gulp-sketch": "^1.0.2",
"lodash": "^4.5.1"
}
}
3 changes: 2 additions & 1 deletion templates/fontawesome-style.css
Expand Up @@ -2,6 +2,7 @@
font-family: "<%= fontName %>";
src: url('<%= fontPath %><%= fontName %>.eot');
src: url('<%= fontPath %><%= fontName %>.eot?#iefix') format('eot'),
url('<%= fontPath %><%= fontName %>.woff2') format('woff2'),
url('<%= fontPath %><%= fontName %>.woff') format('woff'),
url('<%= fontPath %><%= fontName %>.ttf') format('truetype'),
url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg');
Expand Down Expand Up @@ -34,4 +35,4 @@
}

<% _.each(glyphs, function(glyph) { %>.<%= className %>-<%= glyph.name %>:before { content: "\<%= glyph.codepoint.toString(16).toUpperCase() %>" }
<% }); %>
<% }); %>
2 changes: 1 addition & 1 deletion templates/fontawesome-style.html
Expand Up @@ -22,4 +22,4 @@ <h1><%= fontName %></h1>
</li><% }); %>
</ul>
</body>
</html>
</html>
3 changes: 2 additions & 1 deletion templates/foundation-style.css
Expand Up @@ -2,6 +2,7 @@
font-family: "<%= fontName %>";
src: url('<%= fontPath %><%= fontName %>.eot');
src: url('<%= fontPath %><%= fontName %>.eot?#iefix') format('eot'),
url('<%= fontPath %><%= fontName %>.woff2') format('woff2'),
url('<%= fontPath %><%= fontName %>.woff') format('woff'),
url('<%= fontPath %><%= fontName %>.ttf') format('truetype'),
url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg');
Expand All @@ -22,4 +23,4 @@
}

<% _.each(glyphs, function(glyph) { %>.<%= className %>-<%= glyph.name %>:before { content: "\<%= glyph.codepoint.toString(16).toUpperCase() %>" }
<% }); %>
<% }); %>
2 changes: 1 addition & 1 deletion templates/foundation-style.html
Expand Up @@ -22,4 +22,4 @@ <h1><%= fontName %></h1>
</li><% }); %>
</ul>
</body>
</html>
</html>
60 changes: 40 additions & 20 deletions variations/android/gulpfile.js
@@ -1,31 +1,51 @@
var gulp = require("gulp");
var rename = require("gulp-rename");
var sketch = require("gulp-sketch");
var iconfont = require('gulp-iconfont');
var consolidate = require('gulp-consolidate');
const
gulp = require('gulp'),
rename = require('gulp-rename'),
sketch = require('gulp-sketch'),
iconfont = require('gulp-iconfont'),
consolidate = require('gulp-consolidate')

var fontName = 'symbols'; // set name of your symbol font
var skethcFileName = 'symbol-android-16px.sketch';
/**
* Font settings
*/
const
// set name of your symbol font
fontName = 'symbols'

gulp.task('symbols', function(){
gulp.src(skethcFileName) // you can also choose 'symbol-font-16px.sketch'
/**
* Recommended to get consistent builds when watching files
* See https://github.com/nfroidure/gulp-iconfont
*/
const timestamp = Math.round(Date.now() / 1000)

gulp.task('symbols', () =>
gulp.src('symbol-android-16px.sketch')
.pipe(sketch({
export: 'artboards',
formats: 'svg'
}))
.pipe(iconfont({ fontName: fontName }))
.pipe(iconfont({
fontName,
formats: ['ttf'],
timestamp,
log: () => {} // suppress unnecessary logging
}))
.on('glyphs', function(glyphs) {
var options = {
glyphs: glyphs.map(function(glyph) {
// this line is needed because gulp-iconfont has changed the api from 2.0
return { name: glyph.name, codepoint: glyph.unicode[0].charCodeAt(0) }
}),
const options = {
glyphs: glyphs.map(mapGlyphs),
fontName: fontName
};
}
gulp.src('android.xml')
.pipe(consolidate('lodash', options))
.pipe(rename({ basename:fontName }))
.pipe(gulp.dest('dist/xml/')); // set path to export your xml
.pipe(rename({ basename: fontName }))
.pipe(gulp.dest('dist/xml/')) // set path to export your xml
})
.pipe(gulp.dest('dist/fonts/')); // set path to export your fonts
});
.pipe(gulp.dest('dist/fonts/')) // set path to export your fonts
)

/**
* This is needed for mapping glyphs and codepoints.
*/
function mapGlyphs(glyph) {
return { name: glyph.name, codepoint: glyph.unicode[0].charCodeAt(0) }
}

0 comments on commit a63df6c

Please sign in to comment.