Use dot notation to access screenshot options

This commit is contained in:
astefanutti 2015-07-21 18:24:18 +02:00
parent dd6065620a
commit ce2f851c4b

View File

@ -45,17 +45,20 @@ var parser = require("./libs/nomnom")
flag: true, flag: true,
help: "Capture each slide as an image" help: "Capture each slide as an image"
}, },
"screenshots-directory": { screenshotDirectory: {
full: "screenshots-directory",
default: "screenshots", default: "screenshots",
help: "Screenshots output directory" help: "Screenshots output directory"
}, },
"screenshots-size": { screenshotSize: {
full: "screenshots-size",
list: true, list: true,
callback: parseResolution, callback: parseResolution,
transform: parseResolution, transform: parseResolution,
help: "Screenshots resolution, can be repeated" help: "Screenshots resolution, can be repeated"
}, },
"screenshots-format": { screenshotFormat: {
full: "screenshots-format",
default: "png", default: "png",
choices: ["jpg", "png"], choices: ["jpg", "png"],
help: "Screenshots image format, one of [jpg, png]" help: "Screenshots image format, one of [jpg, png]"
@ -159,12 +162,12 @@ function exportSlide(plugin) {
.then(function() { printer.printPage(page) }); .then(function() { printer.printPage(page) });
if (options.screenshots) { if (options.screenshots) {
decktape = (options["screenshots-size"] || [options.size]).reduce(function(decktape, resolution) { decktape = (options.screenshotSize || [options.size]).reduce(function(decktape, resolution) {
return decktape.then(function() { page.viewportSize = resolution }) return decktape.then(function() { page.viewportSize = resolution })
// Delay page rendering to wait for the resize event to complete (may be needed to be configurable) // Delay page rendering to wait for the resize event to complete (may be needed to be configurable)
.then(delay(500)) .then(delay(500))
.then(function() { .then(function() {
page.render(options["screenshots-directory"] + '/' + options.filename.replace(".pdf", '_' + plugin.currentSlide + '_' + resolution.width + 'x' + resolution.height + '.' + options["screenshots-format"]), { mode: "viewport" }); page.render(options.screenshotDirectory + '/' + options.filename.replace(".pdf", '_' + plugin.currentSlide + '_' + resolution.width + 'x' + resolution.height + '.' + options.screenshotFormat), { mode: "viewport" });
}) })
}, decktape) }, decktape)
.then(function() { page.viewportSize = options.size }) .then(function() { page.viewportSize = options.size })