Document --load-pause option, add metavars and polish

This commit is contained in:
Antonin Stefanutti 2016-03-29 09:55:28 +02:00
parent e623da42e0
commit 4d3fed0acf
3 changed files with 62 additions and 48 deletions

View File

@ -131,12 +131,14 @@ url URL of the slides deck
filename Filename of the output PDF file
Options:
-s, --size Size of the slides deck viewport: <width>x<height> [1280x720]
-p, --pause Duration in milliseconds before each slide is exported [1000]
--screenshots Capture each slide as an image [false]
--screenshots-directory Screenshots output directory [screenshots]
--screenshots-size Screenshots resolution, can be repeated [--size]
--screenshots-format Screenshots image format, one of [jpg, png] [png]
-s <size>, --size <size> Size of the slides deck viewport: <width>x<height> (ex. 1280x720)
-p <ms>, --pause <ms> Duration in milliseconds before each slide is exported [1000]
--load-pause <ms> Duration in milliseconds between the page has loaded
and starting to export slides [0]
--screenshots Capture each slide as an image [false]
--screenshots-directory <dir> Screenshots output directory [screenshots]
--screenshots-size <size> Screenshots resolution, can be repeated [--size]
--screenshots-format <format> Screenshots image format, one of [jpg, png] [png]
Defaults to the automatic command.
Iterates over the available plugins, picks the compatible one for presentation at the
@ -157,13 +159,13 @@ Iterates over the available link:plugins[], picks the compatible one for present
[#generic]
=== `generic`
Emulates the end-user interaction by pressing the key with the specified `keycode` option and iterates over the presentation as long as:
Emulates the end-user interaction by pressing the key with the specified `--keycode` option and iterates over the presentation as long as:
[loweralpha]
. Any change to the DOM is detected by observing mutation events targeting the body element and its subtree or
. the number of slides exported has reached the specified `maxSlides` option.
. Any change to the DOM is detected by observing mutation events targeting the body element and its subtree nor
. the number of slides exported has reached the specified `--max-slides` option.
The `keycode` value must be one of the {uri-phantomjs-page-event-keys}[PhantomJS page event keys] and defaults to `Right`, e.g.:
The `--keycode` value must be one of the {uri-phantomjs-page-event-keys}[PhantomJS page event keys] and defaults to `Right`, e.g.:
$ ./bin/phantomjs decktape.js generic --keycode=Space
@ -171,10 +173,9 @@ The `keycode` value must be one of the {uri-phantomjs-page-event-keys}[PhantomJS
=== `--screenshots`
Captures each slide as an image at the `screenshots-size` resolution, exports it to the `screenshots-format` image format and writes the output into the `screenshots-directory` directory.
Captures each slide as an image at the `--screenshots-size` resolution, exports it to the `--screenshots-format` image format and writes the output into the `--screenshots-directory` directory.
The `screenshots-size` option can be set multiple times.
For example:
The `--screenshots-size` option can be set multiple times. For example:
$ ./bin/phantomjs decktape.js --screenshots --screenshots-size=400x300 --screenshots-size=800x600

View File

@ -1,29 +1,31 @@
require.paths.push(phantom.libraryPath + '/libs/');
var page = require('webpage').create(),
printer = require('printer').create(),
system = require('system'),
fs = require('fs'),
Promise = require('promise');
var system = require('system');
// Node to PhantomJS bridging
var process = {
platform: { mac: 'darwin', windows: 'win32' }[system.os.name] || system.os.name,
env: system.env,
argv: system.args,
platform : { mac: 'darwin', windows: 'win32' }[system.os.name] || system.os.name,
env : system.env,
argv : system.args,
// To uncomment when system.stdout.isTTY is supported
//stdout: system.stdout,
exit: phantom.exit
//stdout : system.stdout,
exit : phantom.exit
};
// As opposed to PhantomJS, global variables declared in the main script are not accessible
// in modules loaded with require
// As opposed to PhantomJS, global variables declared in the main script are not
// accessible in modules loaded with require
if (system.platform === 'slimerjs')
require.globals.process = process;
var fs = require('fs'),
page = require('webpage').create(),
parser = require('nomnom'),
printer = require('printer').create(),
Promise = require('promise');
var plugins = loadAvailablePlugins(phantom.libraryPath + '/plugins/');
var parser = require('nomnom')
.script('phantomjs decktape.js')
parser.script('phantomjs decktape.js')
.options({
url: {
position: 1,
@ -37,16 +39,20 @@ var parser = require('nomnom')
},
size: {
abbr: 's',
callback: parseResolution,
transform: parseResolution,
help: 'Size of the slides deck viewport: <width>x<height>'
metavar: '<size>',
callback: parseSize,
transform: parseSize,
help: 'Size of the slides deck viewport: <width>x<height> (ex. 1280x720)'
},
pause: {
abbr: 'p',
metavar: '<ms>',
default: 1000,
help: 'Duration in milliseconds before each slide is exported'
},
loadpause: {
loadPause: {
full: "load-pause",
metavar: '<ms>',
default: 0,
help: 'Duration in milliseconds between the page has loaded and starting to export slides'
},
@ -57,23 +63,37 @@ var parser = require('nomnom')
},
screenshotDirectory: {
full: 'screenshots-directory',
metavar: '<dir>',
default: 'screenshots',
help: 'Screenshots output directory'
},
screenshotSize: {
full: 'screenshots-size',
metavar: '<size>',
list: true,
callback: parseResolution,
transform: parseResolution,
callback: parseSize,
transform: parseSize,
help: 'Screenshots resolution, can be repeated'
},
screenshotFormat: {
full: 'screenshots-format',
metavar: '<format>',
default: 'png',
choices: ['jpg', 'png'],
help: 'Screenshots image format, one of [jpg, png]'
}
});
function parseSize(size) {
// TODO: support device viewport sizes and graphics display standard resolutions
// see http://viewportsizes.com/ and https://en.wikipedia.org/wiki/Graphics_display_resolution
var match = size.match(/^(\d+)x(\d+)$/);
if (!match)
return '<size> must follow the <width>x<height> notation, e.g., 1280x720';
else
return { width: match[1], height: match[2] };
}
parser.nocommand()
.help('Defaults to the automatic command.\n' +
'Iterates over the available plugins, picks the compatible one for presentation at the \n' +
@ -124,9 +144,9 @@ page.open(options.url, function (status) {
phantom.exit(1);
}
if (options.loadpause > 0)
if (options.loadPause > 0)
Promise.resolve()
.then(delay(options.loadpause))
.then(delay(options.loadPause))
.then(exportSlides);
else
exportSlides();
@ -252,16 +272,6 @@ function delay(time) {
}
}
function parseResolution(resolution) {
// TODO: support device viewport sizes and graphics display standard resolutions
// see http://viewportsizes.com/ and https://en.wikipedia.org/wiki/Graphics_display_resolution
var match = resolution.match(/^(\d+)x(\d+)$/);
if (!match)
return 'Resolution must follow the <width>x<height> notation, e.g., 1280x720';
else
return { width: match[1], height: match[2] };
}
// TODO: add progress bar, duration, ETA and file size
function progressBar(plugin) {
var cols = [];

View File

@ -4,20 +4,23 @@
exports.options = {
keycode: {
default: 'Right',
metavar: '<code>',
help: 'Key code pressed to navigate to next slide'
},
maxSlides: {
full: 'max-slides',
metavar: '<size>',
help: 'Maximum number of slides to export'
}
};
exports.help =
'Emulates the end-user interaction by pressing the key with the specified [keycode] option\n' +
'Emulates the end-user interaction by pressing the key with the specified --keycode option\n' +
'and iterates over the presentation as long as:\n' +
'- Any change to the DOM is detected by observing mutation events targeting the body element\n' +
' and its subtree,\n' +
'- Nor the number of slides exported has reached the specified [maxSlides] option.\n' +
'The [keycode] option must be one of the PhantomJS page event keys and defaults to [Right].';
'- Nor the number of slides exported has reached the specified --max-slides option.\n' +
'The --keycode option must be one of the PhantomJS page event keys and defaults to [Right].';
exports.create = function (page, options) {
return new Generic(page, options);