Reformatted and gjslinted example-screenshot.js.

This commit is contained in:
Marc Jansen
2013-03-15 11:40:55 +01:00
parent 8692c42318
commit 24d3c903fe
+24 -24
View File
@@ -1,3 +1,5 @@
/**
* This script is supposed to be executed via phantomjs. It will generate
* screenshots of the html files in the directory specified by a commandline
@@ -32,13 +34,12 @@
*/
(function() { // global closure
var // imports
page = require('webpage').create(),
var page = require('webpage').create(), // imports
fs = require('fs'),
system = require('system'),
// arguments
baseExamplesUrl = system.args[1];
exampleDir = system.args[2];
baseExamplesUrl = system.args[1],
exampleDir = system.args[2],
// various settings
ignoreFiles = [
'example-list.html'
@@ -73,40 +74,40 @@ var util = {
* Appends a slash to given string if it isn't there already.
*/
appendSlash: function(str) {
return ((/\/$/).test(str)) ? str : str + "/";
return ((/\/$/).test(str)) ? str : str + '/';
},
/**
* generates an URL out of
* Generates an URL out of given baseurl and path.
*/
buildUrl: function(baseurl, path) {
var name = util.baseName(path),
mode = "raw";
return util.appendSlash(baseurl) + name + "?mode=" + mode;
mode = 'raw';
return util.appendSlash(baseurl) + name + '?mode=' + mode;
},
/**
* Simple progressbar logger that uses our globals.
*/
logProgress: function() {
var doneSymbol = "-",
todoSymbol = " ",
str = "[",
var doneSymbol = '-',
todoSymbol = ' ',
str = '[',
percent = (lenHtmlFiles === 0) ? 0 : (pageindex / lenHtmlFiles * 100),
i = 0;
for (; i < pageindex; i++) {
str += doneSymbol;
}
for (i = 0; i < lenHtmlFiles - pageindex; i++) {
str += (i === 0) ? ">" : todoSymbol;
str += (i === 0) ? '>' : todoSymbol;
}
str += "]";
str += ']';
if (percent < 10) {
str += " ";
str += ' ';
} else if (percent < 100) {
str += " ";
str += ' ';
}
str += " " + percent.toFixed(1) + " % done";
if (fileName !== "") {
str += ", " + util.baseName(fileName) + "";
str += ' ' + percent.toFixed(1) + ' % done';
if (fileName !== '') {
str += ', ' + util.baseName(fileName) + '';
}
console.log(str);
}
@@ -124,10 +125,10 @@ for(var i = 0; i< exampleDirList.length; i++) {
}
lenHtmlFiles = htmlFiles.length;
console.log("Capturing " + lenHtmlFiles + " example screenshots.");
console.log('Capturing ' + lenHtmlFiles + ' example screenshots.');
// The main interval function that is executed regularily and renders a page to
// a file
// The main interval function that is executed regularily and renders a
// page to a file
var interval = setInterval(function() {
if (!loadInProgress && pageindex < lenHtmlFiles) {
util.logProgress();
@@ -143,7 +144,7 @@ var interval = setInterval(function() {
}
if (pageindex == lenHtmlFiles) {
util.logProgress();
console.log(lenHtmlFiles + " screenshots captured.");
console.log(lenHtmlFiles + ' screenshots captured.');
phantom.exit();
}
}, intervalMillisecs);
@@ -155,7 +156,7 @@ page.onLoadStarted = function() {
// When the page is loaded, render it to an image
page.onLoadFinished = function() {
var dest = exampleDir + fs.separator + util.baseName(fileName) + ".png";
var dest = exampleDir + fs.separator + util.baseName(fileName) + '.png';
window.setTimeout(function() {
loadInProgress = false;
page.render(dest); // actually render the page.
@@ -163,5 +164,4 @@ page.onLoadFinished = function() {
}, renderMillisecs);
};
})(); // eof global closure