Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feature: adds plugin interface, webdriver support #17

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions bin/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ var argv = optimist
.describe('cut', 'Cut snapshots to exact screen size')
.default('cut', false)

.describe('plugin', 'Set snapshot plugin')
.default('plugin', 'phantomjs')

.describe('help', 'Print usage instructions')
.alias('h', 'help')
.argv
Expand All @@ -50,6 +53,7 @@ server.sites(JSON.parse(argv.sites))
server.resolutions(JSON.parse(argv.resolutions))
server.wait(argv.wait)
server.cut(argv.cut)
server.plugin(argv.plugin)

if (argv.cache) {
server.cache({
Expand Down
3 changes: 2 additions & 1 deletion lib/review.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ module.exports = function review () {
app.set('cache', false)
app.set('cookies', [])
app.set('cut', false)
app.set('plugin', 'phantomjs')

app.set('view engine', 'jade')
app.set('views', __dirname + '/../views')
Expand All @@ -30,7 +31,7 @@ module.exports = function review () {
*/

var setters = [
'title', 'sites', 'resolutions', 'wait', 'cache', 'cut'
'title', 'sites', 'resolutions', 'wait', 'cache', 'cut', 'plugin',
]
setters.forEach(function (key) {
app[key] = function (value) {
Expand Down
28 changes: 2 additions & 26 deletions lib/snapshot.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
* module dependencies
*/

var spawn = require('child_process').spawn
var crypto = require('crypto')
var mkdirp = require('mkdirp')
var path = require('path')
Expand All @@ -17,38 +16,15 @@ var phantomjs = require('phantomjs')
var caching = {}
var caches = new EventEmitter()

/**
* fs shortcuts
*/

var script = __dirname + '/../script/rasterize.js'

/**
* snapshot route
*/

module.exports = function (app) {
function snapshot (params, cb) {
var ps = spawn(phantomjs.path, [
script, params.url, params.resolution,
params.wait, app.get('cut'), JSON.stringify(app.get('cookies'))
])

ps.on('error', cb)

var chunks = []
ps.stdout.on('data', function (chunk) {
chunks.push(chunk)
})

ps.on('exit', function () {
cb(null, new Buffer(chunks.join(''), 'base64'))
})
}

return function (req, res, next) {
var snapshot = require(__dirname + '/../plugin/' + app.get('plugin') + '.js');
if (!app.get('cache')) {
return snapshot(req.params, function (err, rasterized) {
return snapshot(app, req.params, function (err, rasterized) {
if (err) return next(err)
res.set('Content-Type', 'image/png')
res.send(rasterized)
Expand Down
Loading