Skip to content

Commit 2254914

Browse files
author
Wassim CHEGHAM
committed
use custom gulp-markdown-pdf module
1 parent 58ad99a commit 2254914

File tree

3 files changed

+100
-2
lines changed

3 files changed

+100
-2
lines changed

.gitignore

+3-1
Original file line numberDiff line numberDiff line change
@@ -1 +1,3 @@
1-
build/README.pdf
1+
build/
2+
node_modules/
3+
temp/

gulpfile.js

+84
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
var gulp = require('gulp');
2+
var markdownpdf = require('gulp-markdown-pdf');
3+
var path = require('path');
4+
var replace = require('gulp-replace');
5+
var package = require('./package.json');
6+
var rename = require('gulp-rename');
7+
var rimraf = require('gulp-rimraf');
8+
var runSequence = require('run-sequence');
9+
var glob = require('glob');
10+
11+
var TITLE = 'AngularJS in Patterns';
12+
13+
function genericTask(lang){
14+
15+
gulp.task('generate:pdf:' + lang, function() {
16+
17+
var files = ['./temp/*.md'];
18+
if (lang === 'eng'){
19+
files = './temp/README.md';
20+
}
21+
else if(lang !== 'all'){
22+
files = ['./temp/*-'+lang+'.md'];
23+
}
24+
25+
return gulp.src(files)
26+
.pipe(markdownpdf({
27+
cwd: path.resolve('./temp/'),
28+
layout: 'github'
29+
}))
30+
.on('error', function(err){
31+
gutil.log(gutil.colors.red('doc task failed'), err);
32+
})
33+
.pipe(rename(function (path) {
34+
var lang = 'ENG';
35+
if(path.basename.indexOf('-') >= 0){
36+
lang = path.basename.replace('README-', '').toUpperCase();
37+
}
38+
path.basename = TITLE + ' ('+lang+')';
39+
path.extname = '.pdf'
40+
}))
41+
.pipe(gulp.dest('./build/'));
42+
});
43+
44+
}
45+
46+
// build custom tasks for i18n
47+
48+
glob.sync('./temp/README-*.md').map(function(file){
49+
50+
return file.replace('README-', '');
51+
52+
}).concat(['all', 'eng']).forEach(function(lang){
53+
54+
genericTask(lang);
55+
gulp.task('doc:pdf:'+lang, function(cb){
56+
runSequence('clean', ['copy:images', 'copy:md'], 'generate:pdf:'+lang, cb);
57+
});
58+
59+
});
60+
61+
gulp.task('default', function(cb){
62+
runSequence('clean', ['copy:images', 'copy:md'], 'doc:pdf:all', cb);
63+
});
64+
65+
gulp.task('copy:md', function(){
66+
return gulp.src(['README.md', 'i18n/README-*.md'])
67+
68+
// @todo I have no idea where should the TOC go?!
69+
// for now, let's keep the TOC content and remove these markers
70+
.pipe(replace('<!--toc-->', ''))
71+
.pipe(replace('<!--endtoc-->', ''))
72+
73+
// preapre the image paths for the renderer
74+
.pipe(replace(/https:\/\/rawgit.com\/mgechev\/angularjs-in-patterns\/master\/images/g, '.'))
75+
.pipe(gulp.dest('./temp/'));
76+
});
77+
78+
gulp.task('copy:images', function(){
79+
return gulp.src(['images/*.svg','meta.json']).pipe(gulp.dest('./temp'));
80+
});
81+
82+
gulp.task('clean', function() {
83+
return gulp.src('./temp/', { read: false }).pipe(rimraf());
84+
});

package.json

+13-1
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,22 @@
1111
"url": "git://github.com/mgechev/angularjs-patterns.git"
1212
},
1313
"author": "mgechev",
14+
"contributors": [{
15+
"name" : "Wassim Chegham",
16+
"email" : "[email protected]",
17+
"url" : "https://github.com/manekinekko/"
18+
}],
1419
"license": "MIT",
1520
"gitHead": "2009434a6dfdbe5f06f81253fb853840af753b36",
1621
"readmeFilename": "README.md",
1722
"devDependencies": {
18-
"markdown-styles": "https://github.com/mgechev/markdown-styles/tarball/master"
23+
"glob": "^5.0.14",
24+
"gulp": "^3.9.0",
25+
"gulp-markdown-pdf": "https://github.com/manekinekko/gulp-markdown-pdf.git#master",
26+
"gulp-rename": "^1.2.2",
27+
"gulp-replace": "^0.5.3",
28+
"gulp-rimraf": "^0.1.1",
29+
"markdown-styles": "https://github.com/mgechev/markdown-styles/tarball/master",
30+
"run-sequence": "^1.1.1"
1931
}
2032
}

0 commit comments

Comments
 (0)