gulp-ttf2eot
Advanced tools
Comparing version 0.0.1 to 0.0.2
{ | ||
"name": "gulp-ttf2eot", | ||
"description": "Create an EOT font from a TTF font", | ||
"version": "0.0.1", | ||
"version": "0.0.2", | ||
"homepage": "https://github.com/nfroidure/gulp-ttf2eot", | ||
@@ -35,5 +35,2 @@ "author": { | ||
}, | ||
"peerDependencies": { | ||
"grunt": "~0.4.1" | ||
}, | ||
"keywords": [ | ||
@@ -40,0 +37,0 @@ "gulpplugin", |
@@ -24,2 +24,12 @@ # gulp-ttf2eot [![NPM version](https://badge.fury.io/js/gulp-ttf2eot.png)](https://npmjs.org/package/gulp-ttf2eot) [![Build status](https://secure.travis-ci.org/nfroidure/gulp-ttf2eot.png)](https://travis-ci.org/nfroidure/gulp-ttf2eot) | ||
## API | ||
### ttf2eot(options) | ||
#### options.ignoreExt | ||
Type: `Boolean` | ||
Default value: `false` | ||
Set to true to also convert files that doesn't have the .ttf extension. | ||
### Contributing / Issues | ||
@@ -26,0 +36,0 @@ |
@@ -5,4 +5,7 @@ var PassThrough = require('stream').PassThrough | ||
, ttf2eot = require('ttf2eot') | ||
, path = require('path') | ||
; | ||
const PLUGIN_NAME = 'gulp-ttf2eot'; | ||
// File level transform function | ||
@@ -15,3 +18,3 @@ function ttf2eotTransform(opt) { | ||
if(err) { | ||
cb(new gutil.PluginError('ttf2eot', err, {showStack: true})); | ||
cb(new gutil.PluginError(PLUGIN_NAME, err, {showStack: true})); | ||
} | ||
@@ -24,3 +27,3 @@ | ||
} catch(err) { | ||
cb(new gutil.PluginError('ttf2eot', err, {showStack: true})); | ||
cb(new gutil.PluginError(PLUGIN_NAME, err, {showStack: true})); | ||
} | ||
@@ -32,7 +35,12 @@ | ||
// Plugin function | ||
function ttf2eotGulp() { | ||
function ttf2eotGulp(options) { | ||
options = options || {}; | ||
options.ignoreExt = options.ignoreExt || false; | ||
var stream = new PassThrough({objectMode: true}); | ||
stream.on('data', function(file) { | ||
if(file.isNull()) return; | ||
if(file.isNull()) return; // Do nothing | ||
if((!options.ignoreExt) && '.ttf' !== path.extname(file.path)) return; | ||
@@ -48,3 +56,3 @@ file.path = gutil.replaceExtension(file.path, ".eot"); | ||
} catch(err) { | ||
stream.emit('error', new gutil.PluginError('ttf2eot', err, { | ||
stream.emit('error', new gutil.PluginError(PLUGIN_NAME, err, { | ||
showStack: true | ||
@@ -60,2 +68,3 @@ })); | ||
}); | ||
return stream; | ||
@@ -62,0 +71,0 @@ |
@@ -8,2 +8,4 @@ 'use strict'; | ||
, ttf2eot = require(__dirname + '/../src/index.js') | ||
, Stream = require('stream') | ||
, gutil = require('gulp-util') | ||
; | ||
@@ -25,31 +27,73 @@ | ||
it('should work in buffer mode', function(done) { | ||
describe('in buffer mode', function() { | ||
it('should work', function(done) { | ||
gulp.src(filename + '.ttf') | ||
.pipe(ttf2eot()) | ||
// Uncomment to regenerate the test files if changes in the ttf2eot lib | ||
// .pipe(gulp.dest(__dirname + '/fixtures/')) | ||
.pipe(es.map(function(file) { | ||
assert.equal(file.contents.length, eot.length); | ||
assert.equal(file.contents.toString('utf-8'), eot.toString('utf-8')); | ||
done(); | ||
gulp.src(filename + '.ttf') | ||
.pipe(ttf2eot()) | ||
// Uncomment to regenerate the test files if changes in the ttf2eot lib | ||
// .pipe(gulp.dest(__dirname + '/fixtures/')) | ||
.pipe(es.through(function(file) { | ||
assert.equal(file.contents.length, eot.length); | ||
assert.equal(file.contents.toString('utf-8'), eot.toString('utf-8')); | ||
}, function() { | ||
done(); | ||
})); | ||
}); | ||
it('should let non-ttf files pass through', function(done) { | ||
var s = ttf2eot(); | ||
s.pipe(es.through(function(file) { | ||
assert.equal(file.path,'bibabelula.foo'); | ||
assert.equal(file.contents.toString('utf-8'), 'ohyeah'); | ||
}, function() { | ||
done(); | ||
})); | ||
s.write(new gutil.File({ | ||
path: 'bibabelula.foo', | ||
contents: new Buffer('ohyeah') | ||
})); | ||
s.end(); | ||
}); | ||
}); | ||
it('should work in stream mode', function(done) { | ||
gulp.src(filename + '.ttf', {buffer: false}) | ||
.pipe(ttf2eot()) | ||
.pipe(es.map(function(file) { | ||
// Get the buffer to compare results | ||
file.contents.pipe(es.wait(function(err, data) { | ||
assert.equal(data.length, eot.toString('utf-8').length); | ||
assert.equal(data, eot.toString('utf-8')); | ||
done(); | ||
describe('in stream mode', function() { | ||
it('should work', function(done) { | ||
gulp.src(filename + '.ttf', {buffer: false}) | ||
.pipe(ttf2eot()) | ||
.pipe(es.through(function(file) { | ||
// Get the buffer to compare results | ||
file.contents.pipe(es.wait(function(err, data) { | ||
assert.equal(data.length, eot.toString('utf-8').length); | ||
assert.equal(data, eot.toString('utf-8')); | ||
})); | ||
}, function() { | ||
done(); | ||
})); | ||
}); | ||
it('should let non-ttf files pass through', function(done) { | ||
var s = ttf2eot(); | ||
s.pipe(es.through(function(file) { | ||
assert.equal(file.path,'bibabelula.foo', {buffer: false}); | ||
assert(file.contents instanceof Stream.PassThrough); | ||
}, function() { | ||
done(); | ||
})); | ||
s.write(new gutil.File({ | ||
path: 'bibabelula.foo', | ||
contents: new Stream.PassThrough() | ||
})); | ||
s.end(); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
12290
3
134
44