Fixed compatibility with grunt 0.4
This commit is contained in:
parent
ac15297331
commit
f02cffd8a5
3 changed files with 56 additions and 40 deletions
|
@ -36,6 +36,9 @@
|
||||||
"grunt": "~0.3.9"
|
"grunt": "~0.3.9"
|
||||||
},
|
},
|
||||||
"keywords": [
|
"keywords": [
|
||||||
"gruntplugin"
|
"gruntplugin",
|
||||||
|
"pdf",
|
||||||
|
"convert",
|
||||||
|
"html"
|
||||||
]
|
]
|
||||||
}
|
}
|
49
tasks/lib/wkhtmltopdf-lib.js
Normal file
49
tasks/lib/wkhtmltopdf-lib.js
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*
|
||||||
|
* grunt-wkhtmltopdf
|
||||||
|
* http://www.dhar.fr/grunt-wkhtmltopdf/
|
||||||
|
*
|
||||||
|
* Copyright (c) 2012 Olivier Audard, contributors
|
||||||
|
* Licensed under the MIT license.
|
||||||
|
*/
|
||||||
|
/*globals exports:false*/
|
||||||
|
|
||||||
|
exports.init = function(grunt) {
|
||||||
|
'use strict';
|
||||||
|
|
||||||
|
return {
|
||||||
|
convert: function(options) {
|
||||||
|
|
||||||
|
if (!options || !options.args) {
|
||||||
|
grunt.warn("You need to specify atleast one input file, and exactly one output file");
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
// TODO: ditch this when grunt v0.4 is released
|
||||||
|
grunt.util = grunt.util || grunt.utils;
|
||||||
|
|
||||||
|
return grunt.util.spawn({
|
||||||
|
cmd: 'wkhtmltopdf',
|
||||||
|
args: options.args
|
||||||
|
}, function(err, result, code) {
|
||||||
|
grunt.log.writeln('wkhtmltopdf done');
|
||||||
|
if (!err) { return options.done(null); }
|
||||||
|
// Something went horribly wrong.
|
||||||
|
grunt.verbose.or.writeln();
|
||||||
|
grunt.log.write('Running wkhtmltopdf...').error();
|
||||||
|
if (code === 127) {
|
||||||
|
grunt.log.errorlns(
|
||||||
|
'In order for this task to work properly, wkhtmltopdf must be ' +
|
||||||
|
'installed and in the system PATH (if you can run "wkhtmltopdf" at' +
|
||||||
|
' the command line, this task should work). Unfortunately, ' +
|
||||||
|
'wkhtmltopdf cannot be installed automatically via npm or grunt. '
|
||||||
|
);
|
||||||
|
grunt.warn('wkhtmltopdf not found.', options.code);
|
||||||
|
} else {
|
||||||
|
result.split('\n').forEach(grunt.log.error, grunt.log);
|
||||||
|
grunt.warn('wkhtmltopdf exited unexpectedly with exit code ' + code + '.', options.code);
|
||||||
|
}
|
||||||
|
options.done(code);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
||||||
|
};
|
|
@ -5,7 +5,7 @@
|
||||||
* Copyright (c) 2012 Olivier Audard
|
* Copyright (c) 2012 Olivier Audard
|
||||||
* Licensed under the MIT license.
|
* Licensed under the MIT license.
|
||||||
*/
|
*/
|
||||||
/*globals module:false*/
|
/*globals module:false, require:false*/
|
||||||
module.exports = function(grunt) {
|
module.exports = function(grunt) {
|
||||||
|
|
||||||
// Please see the grunt documentation for more information regarding task and
|
// Please see the grunt documentation for more information regarding task and
|
||||||
|
@ -14,6 +14,7 @@ module.exports = function(grunt) {
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
// TASKS
|
// TASKS
|
||||||
// ==========================================================================
|
// ==========================================================================
|
||||||
|
var helper = require('./lib/wkhtmltopdf-lib').init(grunt);
|
||||||
|
|
||||||
grunt.registerTask('wkhtmltopdf', 'Your task description goes here.', function() {
|
grunt.registerTask('wkhtmltopdf', 'Your task description goes here.', function() {
|
||||||
grunt.config.requires('wkhtmltopdf.src');
|
grunt.config.requires('wkhtmltopdf.src');
|
||||||
|
@ -35,7 +36,7 @@ module.exports = function(grunt) {
|
||||||
srcpath.replace(/.*\/([^\/]+)\.html/, '$1.pdf');
|
srcpath.replace(/.*\/([^\/]+)\.html/, '$1.pdf');
|
||||||
|
|
||||||
// Launch PhantomJS.
|
// Launch PhantomJS.
|
||||||
grunt.helper('wkhtmltopdf', {
|
helper.convert({
|
||||||
code: 90,
|
code: 90,
|
||||||
args: [
|
args: [
|
||||||
'--dpi', '96', // workarround to wkhtmltopdf letter-spacing bug (see http://code.google.com/p/wkhtmltopdf/issues/detail?id=72)
|
'--dpi', '96', // workarround to wkhtmltopdf letter-spacing bug (see http://code.google.com/p/wkhtmltopdf/issues/detail?id=72)
|
||||||
|
@ -51,41 +52,4 @@ module.exports = function(grunt) {
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// ==========================================================================
|
|
||||||
// HELPERS
|
|
||||||
// ==========================================================================
|
|
||||||
|
|
||||||
grunt.registerHelper('wkhtmltopdf', function(options) {
|
|
||||||
|
|
||||||
if (!options || !options.args) {
|
|
||||||
grunt.warn("You need to specify atleast one input file, and exactly one output file");
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
|
|
||||||
return grunt.utils.spawn({
|
|
||||||
cmd: 'wkhtmltopdf',
|
|
||||||
args: options.args
|
|
||||||
}, function(err, result, code) {
|
|
||||||
grunt.log.writeln('wkhtmltopdf done');
|
|
||||||
if (!err) { return options.done(null); }
|
|
||||||
// Something went horribly wrong.
|
|
||||||
grunt.verbose.or.writeln();
|
|
||||||
grunt.log.write('Running wkhtmltopdf...').error();
|
|
||||||
if (code === 127) {
|
|
||||||
grunt.log.errorlns(
|
|
||||||
'In order for this task to work properly, wkhtmltopdf must be ' +
|
|
||||||
'installed and in the system PATH (if you can run "wkhtmltopdf" at' +
|
|
||||||
' the command line, this task should work). Unfortunately, ' +
|
|
||||||
'wkhtmltopdf cannot be installed automatically via npm or grunt. '
|
|
||||||
);
|
|
||||||
grunt.warn('wkhtmltopdf not found.', options.code);
|
|
||||||
} else {
|
|
||||||
result.split('\n').forEach(grunt.log.error, grunt.log);
|
|
||||||
grunt.warn('wkhtmltopdf exited unexpectedly with exit code ' + code + '.', options.code);
|
|
||||||
}
|
|
||||||
options.done(code);
|
|
||||||
});
|
|
||||||
});
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue