From 4d3fed0acfa2a798f1116148bd9b2f6f42f65c4b Mon Sep 17 00:00:00 2001 From: Antonin Stefanutti Date: Tue, 29 Mar 2016 09:55:28 +0200 Subject: [PATCH] Document --load-pause option, add metavars and polish --- README.adoc | 27 +++++++++-------- decktape.js | 74 ++++++++++++++++++++++++++-------------------- plugins/generic.js | 9 ++++-- 3 files changed, 62 insertions(+), 48 deletions(-) diff --git a/README.adoc b/README.adoc index 3b977a6..23a1de3 100644 --- a/README.adoc +++ b/README.adoc @@ -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: x [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 of the slides deck viewport: x (ex. 1280x720) + -p , --pause Duration in milliseconds before each slide is exported [1000] + --load-pause Duration in milliseconds between the page has loaded + and starting to export slides [0] + --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] 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 diff --git a/decktape.js b/decktape.js index fe834be..c7c57b7 100644 --- a/decktape.js +++ b/decktape.js @@ -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: x' + metavar: '', + callback: parseSize, + transform: parseSize, + help: 'Size of the slides deck viewport: x (ex. 1280x720)' }, pause: { abbr: 'p', + metavar: '', default: 1000, help: 'Duration in milliseconds before each slide is exported' }, - loadpause: { + loadPause: { + full: "load-pause", + metavar: '', 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: '', default: 'screenshots', help: 'Screenshots output directory' }, screenshotSize: { full: 'screenshots-size', + metavar: '', list: true, - callback: parseResolution, - transform: parseResolution, + callback: parseSize, + transform: parseSize, help: 'Screenshots resolution, can be repeated' }, screenshotFormat: { full: 'screenshots-format', + metavar: '', 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 ' must follow the x 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 x 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 = []; diff --git a/plugins/generic.js b/plugins/generic.js index 1f2e82f..49a8af8 100644 --- a/plugins/generic.js +++ b/plugins/generic.js @@ -4,20 +4,23 @@ exports.options = { keycode: { default: 'Right', + metavar: '', help: 'Key code pressed to navigate to next slide' }, maxSlides: { + full: 'max-slides', + metavar: '', 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);