Skip to content

Commit

Permalink
Use updated (streaming) markdown-pdf module and implement concat file…
Browse files Browse the repository at this point in the history
…s properly
  • Loading branch information
alanshaw committed Dec 27, 2013
1 parent d258903 commit 1289b09
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 19 deletions.
7 changes: 6 additions & 1 deletion Gruntfile.js
Expand Up @@ -31,6 +31,11 @@ module.exports = function(grunt) {
files: {
"tmp/some1": "test/fixtures/test/*"
}
},
concat: {
options: {concat: true},
src: "test/fixtures/**/*",
dest: "tmp/concatenated.pdf"
}
},

Expand All @@ -54,5 +59,5 @@ module.exports = function(grunt) {

// By default, run all tests.
grunt.registerTask('default', ['test'])

}
3 changes: 2 additions & 1 deletion README.md
Expand Up @@ -47,7 +47,7 @@ Default value: `Path provided by phantomjs module`

Path to phantom binary

#### options.concatFiles
#### options.concat
Type: `Boolean`
Default value: `false`

Expand Down Expand Up @@ -117,6 +117,7 @@ In lieu of a formal styleguide, take care to maintain the existing coding style.

## Release History

* 2013-12-27   v2.0.0   Use updated (streaming) markdown-pdf module and implement concat files properly
* 2013-09-04   v1.0.0   Use updated markdown-pdf module - CSS path is now relative to current working directory
* 2013-06-14   v0.3.0   Use marked module for better markdown compatibility and performance
* 2013-05-30   v0.2.0   Allow concatenation of multiple source files to produce a single PDF
Expand Down
29 changes: 19 additions & 10 deletions tasks/markdownpdf.js
Expand Up @@ -7,7 +7,6 @@
*/

var markdownpdf = require("markdown-pdf")

, path = require("path")
, async = require("async")

Expand Down Expand Up @@ -37,16 +36,26 @@ module.exports = function (grunt) {
return true
})

var dests = srcs.map(function (src) {
var destPath = path.join(f.dest, path.basename(src).replace(/\.(markdown|md)/g, "") + ".pdf")
grunt.verbose.writeln("Determined dest path: " + destPath)
return destPath
})
if (opts.concat) {

markdownpdf(opts).from(srcs).to(dests, function (er) {
if (er) return cb(er)
cb(null, dests)
})
markdownpdf(opts).concat.from(srcs).to(f.dest, function (er) {
if (er) return cb(er)
cb(null, [f.dest])
})

} else {

var dests = srcs.map(function (src) {
var destPath = path.join(f.dest, path.basename(src).replace(/\.(markdown|md)/g, "") + ".pdf")
grunt.verbose.writeln("Determined dest path: " + destPath)
return destPath
})

markdownpdf(opts).from(srcs).to(dests, function (er) {
if (er) return cb(er)
cb(null, dests)
})
}
}
})

Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/test/test1.markdown
Expand Up @@ -4,4 +4,4 @@ Test 1
foo
---

foo bar [baz](https://github.com/alanshaw/grunt-markdown-pdf)
foo bar [baz](https://github.com/alanshaw/grunt-markdown-pdf)
2 changes: 1 addition & 1 deletion test/fixtures/test0.md
Expand Up @@ -5,4 +5,4 @@ Test markdown file 0

* foo
* bar
* baz
* baz
19 changes: 14 additions & 5 deletions test/markdownpdf_test.js
Expand Up @@ -5,11 +5,11 @@ exports.markdownpdf = {
test.expect(2)

var contents0 = grunt.file.read('tmp/all/test0.pdf')

test.ok(contents0.length > 0)

var contents1 = grunt.file.read('tmp/all/test1.pdf')

test.ok(contents1.length > 0)

test.done()
Expand All @@ -18,7 +18,7 @@ exports.markdownpdf = {
test.expect(1)

var contents = grunt.file.read('tmp/some0/test0.pdf')

test.ok(contents.length > 0)

test.done()
Expand All @@ -27,7 +27,16 @@ exports.markdownpdf = {
test.expect(1)

var contents = grunt.file.read('tmp/some1/test1.pdf')


test.ok(contents.length > 0)

test.done()
},
concatenated: function(test) {
test.expect(1)

var contents = grunt.file.read('tmp/concatenated.pdf')

test.ok(contents.length > 0)

test.done()
Expand Down

0 comments on commit 1289b09

Please sign in to comment.