The examples below will guide you through how to use Envjs as an end-user, noting in each example which platform the example pertains to. Platform developers should add equivalent examples whenever possible.
Please be aware of the dangers of loading arbitrary code in an insecure environment.
Envjs can also be run in a console mode as mentioned above and its a great way to explore its features. Rhino 1.7rc2 provides a great console. You may find on Mac OSX that your up/down/left/right arrows and tab complete dont work. If this occurs just add JLine to the mix.
Embedding env.rhino.js in a Java application is relatively easy. The following pattern provides the general pattern.
Optionally you can turn on/off settings by passing an options object to Envjs as a function
Tell env.js to load an HTML file
With Envjs, we refer to crawling loosely as the act of injecting script into an HTML application. This means you could be adding jQuery to the browser environment and grepping for all links, potentially storing them and following them, or more simply allowing script to run while monitoring the DOM or state changes or logging test results to the console.
Envjs provides an amazing bridge to facilitate continuous testing cycles for web applications. There are many ways to achieve this, but in our example we show how to use qunit to create tests a developer can run directly in the browser while their working, or run the cammand line with Envjs.
Of course if you can run them at the command-line you can run them as part of your continuous testing scripts.
You can run these tests right now by going to test. Below is the script, followed by the itself command to run them at the command line. Additionally we write the tests results to file which you can see here test results.
Given the follow task you could have written it several different languages, straight bash, python, ruby, perl, etc. But I also know I could write in half the time with half as many lines using jQuery because that's what I'm really good at. Now I finally can...
In the following example I need to crawl a big xml database splitting up a monolithic document into smaller parts, geocode each document based on title, then save the geocodes to a flat file and a json database.
This example is prompted by work from Emre Sevinç who began to try to use Envjs to crawl web pages and use readability.js to output nice simple pages.