forked from thatcher/env-js
/
README
39 lines (27 loc) · 1.51 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
This is a fork of the env.js project (http://github.com/thatcher/env-js/). See that link for env.js details.
This fork is based on the Johnson Ruby gem (http://github.com/jbarnette/johnson). It should become obsolete when the Johnson support has been reintegrated into the master repo.
For now, you can install the envjs gem by installing Johnson:
gem install johnson --prerelease
(You'll need to manually install any prerequisites it asks for) and then installing the envjs gem with
gem install envjs
The envjs gem provides the envjsrb command, which functions as an extended version of the Johnson javascript shell. For example:
mbp:env-js smparkes$ envjsrb
js> this
=> [object Window 0]
js> window.location
=> about:blank
js> document.innerHTML
=> "<html><head><title></title></head><body></body></html>"
js>
It's also possible to embed the envjs interpreter similar to the way it's done in Johnson, e.g.,
require 'rubygems' # if necessary
require 'johnson/tracemonkey'
require 'envjs/runtime'
envjs = Johnson::Runtime.new
envjs.extend Envjs::Runtime
window = envjs.evaluate("window")
puts window.location.to_s # == "about:blank"
puts window.document.innerHTML # == "<html><head><title></title></head><body></body></html>"
envjs.wait
You need the Runtime#wait at the end to give env.js's event loop a chance to execute queued events and timers. You may need to do this at other times as well, depending on the asynchronous nature of your application.
Comments to http://groups.google.com/group/envjs or #envjs on freenode.