Skip to content

Commit 54f2d99

Browse files
committed
Rename fontFamily option to fontName
1 parent 6987e9e commit 54f2d99

File tree

5 files changed

+27
-22
lines changed

5 files changed

+27
-22
lines changed

README.md

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,16 +15,18 @@ Then, add it to your `gulpfile.js`:
1515
var iconfont = require('gulp-iconfont');
1616
var iconfontCss = require('gulp-iconfont-css');
1717

18+
var fontName = 'Icons';
19+
1820
gulp.task('iconfont', function(){
1921
gulp.src(['app/assets/icons/*.svg'])
2022
.pipe(iconfontCss({
21-
fontFamily: 'Icons', // has to be identical to iconfont's "fontName" option
23+
fontName: fontName,
2224
path: 'app/assets/css/templates/_icons.scss',
23-
targetPath: '../../css/_icons.scss', // relative to gulp.dest below
24-
fontPath: '../../fonts/icons/', // relative to targetPath (yes, slightly redundant but necessary for CSS template)
25-
})
25+
targetPath: '../../css/_icons.scss',
26+
fontPath: '../../fonts/icons/'
27+
}))
2628
.pipe(iconfont({
27-
fontName: 'Icons'
29+
fontName: fontName
2830
}))
2931
.pipe(gulp.dest('app/assets/fonts/icons/'));
3032
});
@@ -36,10 +38,10 @@ gulp.task('iconfont', function(){
3638

3739
### iconfontCSS(options)
3840

39-
#### options.fontFamily
41+
#### options.fontName
4042
Type: `String`
4143

42-
The name of the generated font family (optional, defaults to "Icons"). **Important**: Has to be identical to iconfont's ```fontName``` option.
44+
The name of the generated font family (required). **Important**: Has to be identical to iconfont's ```fontName``` option.
4345

4446
#### options.path
4547
Type: `String`

_icons.scss

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@font-face {
2-
font-family: "<%= fontFamily %>";
3-
src: url('<%= fontPath %><%= fontFamily %>.eot?') format('eot');
4-
src: url('<%= fontPath %><%= fontFamily %>.eot?iefix') format('eot'),
5-
url('<%= fontPath %><%= fontFamily %>.woff') format('woff'),
6-
url('<%= fontPath %><%= fontFamily %>.ttf') format('truetype');
2+
font-family: "<%= fontName %>";
3+
src: url('<%= fontPath %><%= fontName %>.eot?') format('eot');
4+
src: url('<%= fontPath %><%= fontName %>.eot?iefix') format('eot'),
5+
url('<%= fontPath %><%= fontName %>.woff') format('woff'),
6+
url('<%= fontPath %><%= fontName %>.ttf') format('truetype');
77
}
88

99
@mixin icon($filename) {
@@ -15,7 +15,7 @@
1515

1616
&:before {
1717
content: $char;
18-
font-family: "<%= fontFamily %>";
18+
font-family: "<%= fontName %>";
1919
-webkit-font-smoothing: antialiased;
2020
-moz-osx-font-smoothing: grayscale;
2121
font-style: normal;

index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,11 +23,13 @@ function iconfontCSS(config) {
2323
targetPath: '_icons.scss',
2424
fontPath: './',
2525
engine: 'lodash',
26-
firstGlyph: 0xE001,
27-
fontFamily: 'Icons'
26+
firstGlyph: 0xE001
2827
}, config);
2928

3029
// Validate config
30+
if (!config.fontName) {
31+
throw new gutil.PluginError(PLUGIN_NAME, 'Missing option "fontName"');
32+
}
3133
if (!consolidate[config.engine]) {
3234
throw new gutil.PluginError(PLUGIN_NAME, 'Consolidate missing template engine "' + config.engine + '"');
3335
}
@@ -87,7 +89,7 @@ function iconfontCSS(config) {
8789
if (glyphMap.length) {
8890
consolidate[config.engine](config.path, {
8991
glyphs: glyphMap,
90-
fontFamily: config.fontFamily,
92+
fontName: config.fontName,
9193
fontPath: config.fontPath
9294
}, function(error, html) {
9395
if (error) {

test/fixtures/_icons.scss

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
@font-face {
2-
font-family: "<%= fontFamily %>";
3-
src: url('<%= fontPath %><%= fontFamily %>.eot?') format('eot');
4-
src: url('<%= fontPath %><%= fontFamily %>.eot?iefix') format('eot'),
5-
url('<%= fontPath %><%= fontFamily %>.woff') format('woff'),
6-
url('<%= fontPath %><%= fontFamily %>.ttf') format('truetype');
2+
font-family: "<%= fontName %>";
3+
src: url('<%= fontPath %><%= fontName %>.eot?') format('eot');
4+
src: url('<%= fontPath %><%= fontName %>.eot?iefix') format('eot'),
5+
url('<%= fontPath %><%= fontName %>.woff') format('woff'),
6+
url('<%= fontPath %><%= fontName %>.ttf') format('truetype');
77
}
88

99
@mixin icon($filename) {
@@ -15,7 +15,7 @@
1515

1616
&:before {
1717
content: $char;
18-
font-family: "<%= fontFamily %>";
18+
font-family: "<%= fontName %>";
1919
-webkit-font-smoothing: antialiased;
2020
-moz-osx-font-smoothing: grayscale;
2121
font-style: normal;

test/main.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ describe('gulp-iconfont-css', function() {
88
it('should generate SCSS file', function(done) {
99
gulp.src(__dirname + '/fixtures/icons/*.svg')
1010
.pipe(iconfontCss({
11+
fontName: 'Icons',
1112
path: __dirname + '/fixtures/_icons.scss',
1213
targetPath: '../_icons.scss'
1314
}))

0 commit comments

Comments
 (0)