Skip to content

Commit

Permalink
Docs
Browse files Browse the repository at this point in the history
  • Loading branch information
battlesnake committed Nov 10, 2015
1 parent b3f9818 commit 2d8abf9
Show file tree
Hide file tree
Showing 7 changed files with 221 additions and 57 deletions.
57 changes: 57 additions & 0 deletions README.lmd
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
# gulp-google-webfonts

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

# Example #1
: example1/

## Input

### fonts.list

< fonts.list

### gulpfile.js

< gulpfile.js

## Output

$ gulp fonts
gulp fonts

### out/fonts/

| ls -1 out/fonts/

### out/fonts/fonts.css

< out/fonts/fonts.css

# 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 #2
$ cd $root/example2/

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

### gulpfile.js

< gulpfile.js

## Output

$ gulp fonts
gulp fonts

### out/
: example2/out/

| find fonts/

110 changes: 60 additions & 50 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,69 +6,70 @@ A gulp plugin to download Google webfonts and generate a stylesheet for them.

## Input

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

Oswald:400,700&subset=latin,latin-ext
# Tab-delimeted format
Oswald 400,700 latin,latin-ext

# Google format
Roboto:500,500italic&subset=greek

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

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

### gulpfile.js

var gulp = require('gulp');
var googleWebFonts = require('gulp-google-webfonts');

var options = { };

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

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

## Output

gulp fonts

### ls -1 out/fonts/
### 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
### out/fonts/fonts.css

@font-face {
font-family: 'Oswald';
font-style: normal;
font-weight: 400;
src: url(./Oswald-normal-400.woff) format('woff');
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-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-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');
}
font-family: 'Roboto';
font-style: italic;
font-weight: 500;
src: url(Roboto-italic-500.woff) format('woff');

# Options

Expand All @@ -84,28 +85,37 @@ The googleWebFonts object can take the following options:

### gulpfile.js

var gulp = require('gulp');
var googleWebFonts = require('gulp-google-webfonts');

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

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

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

## 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
gulp fonts

### out/

fonts/
fonts/googlecss
fonts/googlecss/myGoogleFonts.css
fonts/googlefonts
fonts/googlefonts/googlefonts
fonts/googlefonts/googlefonts/Oswald-normal-700.woff
fonts/googlefonts/googlefonts/Roboto-italic-500.woff
fonts/googlefonts/googlefonts/Oswald-normal-400.woff
fonts/googlefonts/googlefonts/Roboto-normal-500.woff

8 changes: 2 additions & 6 deletions example1/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,7 @@
var gulp = require('gulp');
var googleWebFonts = require('../'); //require('gulp-google-webfonts');
var googleWebFonts = require('gulp-google-webfonts');

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

gulp.task('fonts', function () {
return gulp.src('./fonts.list')
Expand Down
14 changes: 14 additions & 0 deletions example1/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "example1",
"version": "0.0.1",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "gulp"
},
"author": "Mark K Cowan",
"license": "ISC",
"dependencies": {
"gulp-google-webfonts": "*"
}
}
2 changes: 1 addition & 1 deletion example2/gulpfile.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
var gulp = require('gulp');
var googleWebFonts = require('../'); //require('gulp-google-webfonts');
var googleWebFonts = require('gulp-google-webfonts');

var options = {
fontsDir: 'googlefonts/',
Expand Down
14 changes: 14 additions & 0 deletions example2/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"name": "example2",
"version": "0.0.1",
"description": "",
"main": "gulpfile.js",
"scripts": {
"test": "gulp"
},
"author": "Mark K Cowan",
"license": "ISC",
"dependencies": {
"gulp-google-webfonts": "*"
}
}
73 changes: 73 additions & 0 deletions make-docs.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
#!/bin/bash

# Literal markdown, by Mark K Cowan mark@battlesnake.co.uk
#
# Special lines are lines beginning with:
# : [dir] - enter directory [dir], relative to LMD file
# < [file] - read contents of [file] and tab-indent it into MD file
# | [shell_cmd] - execute [shell_cmd] and tab-indent outputs into MD file
# $ [shell_cmd] - execute [shell_cmd] and direct outputs to STDERR
#
# Special lines must not be indented, the first character on the line must be
# the special character.

set -euo pipefail

if [ "${1:---help}" == "--help" ]; then
printf -- "Syntax: make-docs.sh <docfile>.lmd\n\n"
printf -- "Write output to <docfile>.md\n\n"
false
fi

declare -r root="$(realpath "$(dirname "$1")")"
declare -r in="$(basename "$1")"
declare -r out="${in%.lmd}.md"

cd "${root}"

function indent {
local line
while read line; do
printf -- "\t%s\n" "${line}"
done
}

function enter_dir {
local -r dir="$1"
cd "${root}/${dir}"
}

function read_in {
local -r file="$1"
printf >&2 -- "Read '%s' from '%s'\n" "${file}" "${PWD}"
<"${file}" indent
}

function pipe_in {
local -ra args=( $@ )
printf >&2 -- "Pipe in"
printf >&2 -- " '%s'" "${args[@]}"
printf >&2 -- " from '%s'\n" "${PWD}"
"${args[@]}" | indent
}

function map_line {
local -r line="$1"

local -r first="${line:0:1}"
local -r rest="$(echo "${line:1}" | sed -e 's/^\s*//')"

case "${first}" in
":") enter_dir "${rest}";;
"<") read_in "${rest}";;
"|") pipe_in "${rest}";;
"$") >&2 eval "${rest}";;
*) printf -- "%s\n" "${line}";;
esac
}

while IFS='' read __line; do

map_line "${__line}"

done < "${in}" > "${out}"

0 comments on commit 2d8abf9

Please sign in to comment.