WaterfallEngineering/SpookyJS — pull request #43 by jeresig (2013-04-22 14:25:23+00:00)
Title: Add New spooky.exec("code") method.

This adds a new method to the Spooky API named `exec()`. This method takes in a string of JavaScript and executes it in the CasperJS/PhantomJS environment. Additionally it stops waiting for stdin if the stdio transport is being used.

With this particular method it becomes really easy to load a CasperJS file (using `fs.readFileSync`, or some such) and pass it to Spooky/Casper for execution.

An example of how it would be used:

```javascript
var spooky = new Spooky({
casper: {
logLevel: 'debug',
verbose: true
}
}, function (err) {
if (err) {
e = new Error('Failed to initialize SpookyJS');
e.details = err;
throw e;
}

spooky.on('error', function (e) {
console.error(e);
});

spooky.on('log', function (log) {
if (log.space === 'remote') {
console.log(log.message.replace(/ \- .*/, ''));
}
});

var file = fs.readFileSync("casper.js").toString();
spooky.exec(file, args);
});
```