Skip to content

Commit

Permalink
gulp task which creates font styles from .svg icons
Browse files Browse the repository at this point in the history
  • Loading branch information
ambrinchaudhary committed Jan 28, 2015
1 parent 55e76a6 commit 73dd247
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 0 deletions.
3 changes: 3 additions & 0 deletions package.json
Expand Up @@ -9,6 +9,8 @@
"gulp": "~3.8.10",
"gulp-compass": "^2.0.3",
"gulp-concat": "^2.4.3",
"gulp-consolidate": "^0.1.2",
"gulp-iconfont": "^1.0.0",
"gulp-karma": "0.0.4",
"gulp-minify-css": "^0.3.12",
"gulp-rename": "^1.2.0",
Expand All @@ -29,6 +31,7 @@
"karma-safari-launcher": "^0.1.1",
"karma-sauce-launcher": "^0.2.10",
"karma-sinon": "^1.0.4",
"lodash": "^3.0.0",
"mocha": "^2.1.0",
"require-dir": "^0.1.0",
"run-sequence": "^1.0.2",
Expand Down
37 changes: 37 additions & 0 deletions src/ui/yui/gulp-tasks/fonts.js
@@ -0,0 +1,37 @@
'use strict';

var consolidate = require('gulp-consolidate'),
gulp = require('gulp'),
iconfont = require('gulp-iconfont'),
rename = require("gulp-rename"),
rimraf = require('gulp-rimraf'),

fontName = 'alloyeditor',
path = require('path'),
ROOT = path.join(__dirname, '../src/assets');

gulp.task('clean-fonts', function() {
return gulp.src(path.join(ROOT, 'font', 'fonts'), {read: false})
.pipe(rimraf({force: true}));
});

gulp.task('generate-fonts', function(){
gulp.src([ path.join(ROOT, 'svg', '*.svg')])
.pipe(iconfont({
fontName: fontName,
normalize: true
}))
.on('codepoints', function(codepoints) {
gulp.src(path.join(ROOT, 'font', 'font-template.css'))
.pipe(consolidate('lodash', {
fontName: fontName,
fontPath: 'fonts/',
glyphs: codepoints
}))
.pipe(rename({ basename: 'font'}))
.pipe(gulp.dest(path.join(ROOT, 'font')));
})
.pipe(gulp.dest(path.join(ROOT, 'font', 'fonts')));
});

gulp.task('fonts', ['clean-fonts', 'generate-fonts']);
30 changes: 30 additions & 0 deletions src/ui/yui/src/assets/font/font-template.css
@@ -0,0 +1,30 @@
@font-face {
font-family: '<%= fontName %>';
src:url('<%= fontPath %><%= fontName %>.eot');
src:url('<%= fontPath %><%= fontName %>.eot?#iefix') format('embedded-opentype'),
url('<%= fontPath %><%= fontName %>.woff') format('woff'),
url('<%= fontPath %><%= fontName %>.ttf') format('truetype'),
url('<%= fontPath %><%= fontName %>.svg#<%= fontName %>') format('svg');
font-weight: normal;
font-style: normal;
}

[class^="alloy-editor-icon-"], [class*=" alloy-editor-icon-"] {
font-family: '<%= fontName %>';
speak: none;
font-size: 20px;
font-style: normal;
font-weight: normal;
font-variant: normal;
text-transform: none;
line-height: 1.2;

/* Better Font Rendering =========== */
-webkit-font-smoothing: antialiased;
-moz-osx-font-smoothing: grayscale;
}
<% _.each(glyphs, function(glyph) { %>
.alloy-editor-icon-<%= glyph.name %>:before {
content: "\<%= glyph.codepoint.toString(16).toUpperCase() %>";
}
<% }); %>

0 comments on commit 73dd247

Please sign in to comment.