Skip to content

Commit

Permalink
Improved code quality of contributions, defined fonts.list format a b…
Browse files Browse the repository at this point in the history
…it better
  • Loading branch information
battlesnake committed Nov 10, 2015
1 parent afdce21 commit b3f9818
Show file tree
Hide file tree
Showing 11 changed files with 214 additions and 134 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
node_modules/
example*/out/
.*.swp
.*.swo
4 changes: 4 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
example*/out/
node_modules/
.*.swp
.*.swo
204 changes: 95 additions & 109 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,124 +2,110 @@

A gulp plugin to download Google webfonts and generate a stylesheet for them.

# Example #1

## Input

### fonts.list
### fonts.list (using Google format)

Oswald:400,700&subset=latin,latin-ext
Roboto:500,500italic&subset=greek

### fonts.list (using tab-delimeted format, tabs shown as pipes)

Oswald:400,700
Roboto:400,500,700,400italic,500italic,700italic
Oswald | 400,700 | latin,latin-ext
Roboto | 500,500italic | greek

### gulpfile.js

var gulp = require('gulp');
var googleWebFonts = require('gulp-google-webfonts');
gulp.task('fonts', function () {
return gulp.src('./fonts.list')
.pipe(googleWebFonts())
.pipe(gulp.dest('out/fonts'))
;
});
var gulp = require('gulp');
var googleWebFonts = require('gulp-google-webfonts');
gulp.task('fonts', function () {
return gulp.src('./fonts.list')
.pipe(googleWebFonts())
.pipe(gulp.dest('out/fonts'))
;
});

## Output

`gulp fonts`

### ls out/fonts/

fonts.css
Oswald-normal-400.woff
Oswald-normal-700.woff
Roboto-italic-400.woff
Roboto-italic-500.woff
Roboto-italic-700.woff
Roboto-normal-400.woff
Roboto-normal-500.woff
Roboto-normal-700.woff

### out/fonts/fonts.css

@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 400;
src: url(Oswald-normal-400.woff) format('woff');
}

@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 700;
src: url(Oswald-normal-700.woff) format('woff');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 400;
src: url(Roboto-normal-400.woff) format('woff');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 500;
src: url(Roboto-normal-500.woff) format('woff');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 700;
src: url(Roboto-normal-700.woff) format('woff');
}

@font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 400;
src: url(Roboto-italic-400.woff) format('woff');
}

@font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 500;
src: url(Roboto-italic-500.woff) format('woff');
}

@font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 700;
src: url(Roboto-italic-700.woff) format('woff');
}

## Options
gulp fonts

### ls -1 out/fonts/

fonts.css
Oswald-normal-400.woff
Oswald-normal-700.woff
Roboto-italic-500.woff
Roboto-normal-500.woff

### cat out/fonts/fonts.css

@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 400;
src: url(./Oswald-normal-400.woff) format('woff');
}

@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 700;
src: url(./Oswald-normal-700.woff) format('woff');
}

@font-face {
font-family: 'Roboto';
font-style: normal;
font-weight: 500;
src: url(./Roboto-normal-500.woff) format('woff');
}

@font-face {
font-family: 'Roboto';
font-style: italic;
font-weight: 500;
src: url(./Roboto-italic-500.woff) format('woff');
}

# Options

The googleWebFonts object can take the following options:

* fontsDir - The path the output fonts should be under. (Note: the path is relative to `gulp.dest`)
* cssDir - The path the output css should be under. (Note: the path is relative to `gulp.dest`)
* cssFilename - The filename of the output css file.

### Example:

````javascript
gulp.task('googlefonts', function () {
return gulp.src(paths.src +'/assets/fonts.list')
.pipe(googleWebFonts({fontsDir: 'googlefonts', cssDir: 'googlecss', cssFilename: 'myGoogleFonts.css'}))
.pipe(gulp.dest(paths.src +'/assets/'));
});
````

Will create the following directory structure:
```
assets
└───googlefonts
│ *.woff font files
|
└───googlecss
│ myGoogleFonts.css
```
* fontsDir - The path the output fonts should be under. (Note: the path is relative to `gulp.dest`)
* cssDir - The path the output css should be under. (Note: the path is relative to `gulp.dest`)
* cssFilename - The filename of the output css file.

# Example #2

## Input (other inputs same as example #1)

### gulpfile.js

var options = {
fontsDir: 'googlefonts/',
cssDir: 'googlecss/',
cssFilename: 'myGoogleFonts.css'
};

gulp.task('fonts', function () {
return gulp.src('./fonts.list')
.pipe(googleWebFonts(options))
.pipe(gulp.dest('out/'));
});

## Output

### find out/

out/
out/fonts
out/fonts/googlecss
out/fonts/googlecss/myGoogleFonts.css
out/fonts/googlefonts
out/fonts/googlefonts/Oswald-normal-700.woff
out/fonts/googlefonts/Roboto-italic-500.woff
out/fonts/googlefonts/Roboto-normal-500.woff
out/fonts/googlefonts/Oswald-normal-400.woff
1 change: 1 addition & 0 deletions example1/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
5 changes: 5 additions & 0 deletions example1/fonts.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tab-delimeted format
Oswald 400,700 latin,latin-ext

# Google format
Roboto:500,500italic&subset=greek
17 changes: 17 additions & 0 deletions example1/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var gulp = require('gulp');
var googleWebFonts = require('../'); //require('gulp-google-webfonts');

var options = {
// fontsDir: 'googlefonts/',
// cssDir: 'googlecss/',
// cssFilename: 'myGoogleFonts.css'
};

gulp.task('fonts', function () {
return gulp.src('./fonts.list')
.pipe(googleWebFonts(options))
.pipe(gulp.dest('out/fonts'))
;
});

gulp.task('default', ['fonts']);
1 change: 1 addition & 0 deletions example2/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
out/
5 changes: 5 additions & 0 deletions example2/fonts.list
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Tab-delimeted format
Oswald 400,700 latin,latin-ext

# Google format
Roboto:500,500italic&subset=greek
17 changes: 17 additions & 0 deletions example2/gulpfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
var gulp = require('gulp');
var googleWebFonts = require('../'); //require('gulp-google-webfonts');

var options = {
fontsDir: 'googlefonts/',
cssDir: 'googlecss/',
cssFilename: 'myGoogleFonts.css'
};

gulp.task('fonts', function () {
return gulp.src('./fonts.list')
.pipe(googleWebFonts(options))
.pipe(gulp.dest('out/fonts'))
;
});

gulp.task('default', ['fonts']);
Loading

0 comments on commit b3f9818

Please sign in to comment.