Sha256: bf8e35aa55859ff84789796596fcf3abf992caff53766d7be37c4daf7aff8513
Contents?: true
Size: 1.73 KB
Versions: 4
Compression:
Stored size: 1.73 KB
Contents
// Invokes PhantomJS to render a webpage to stdout. Config is supplied as json on stdin. /* jshint phantom: true */ var system = require('system') var page = require('webpage').create() function errorHandler(msg, trace) { system.stderr.writeLine(msg) trace.forEach(function(item) { system.stderr.writeLine(' -> ' + (item.file || item.sourceURL) + ': ' + item.line + (item.function ? ' (in function ' + item.function + ')' : '')); }) phantom.exit(1) } phantom.onError = function(msg, trace) { errorHandler("PHANTOM ERROR: " + msg, trace) } page.onError = function(msg, trace) { errorHandler("PAGE ERROR: " + msg, trace) } var config = JSON.parse(system.stdin.read()) for(var key in config.page) { page[key] = config.page[key] } page.open(config.input, function (status) { if (status !== 'success' /* || (statusCode !== 200 && statusCode !== null) */) { system.stderr.writeLine('Unable to load ' + config.input); phantom.exit(1); } if(config.render.format === 'text') { system.stdout.writeLine(page.plainText) } else if(config.render.format === 'html') { system.stdout.writeLine(page.content) } else { page.render('/dev/stdout', config.render); } phantom.exit(0); }); // if (typeof cookie_file !== 'undefined') { // try { // var f = fs.open(cookie_file, "r"); // cookies = JSON.parse(f.read()); // fs.remove(cookie_file) // } catch (e) { // // TODO: run this through regular error reporter. just don't catch right? // console.log(e); // } // phantom.cookiesEnabled = true; // phantom.cookies = cookies; // } // Determine the statusCode // page.onResourceReceived = function (resource) { // if (resource.url === address) { // statusCode = resource.status; // } // };
Version data entries
4 entries across 4 versions & 1 rubygems
Version | Path |
---|---|
shrimple-0.8.6 | lib/render.js |
shrimple-0.8.4 | lib/render.js |
shrimple-0.8.2 | lib/render.js |
shrimple-0.8.0 | lib/render.js |