Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Added README

  • Loading branch information...
commit 217efd0f3bebd98c7d4c7baf317e553a04ee662c 1 parent a70a49b
Eric Allam authored August 27, 2011

Showing 1 changed file with 40 additions and 0 deletions. Show diff stats Hide diff stats

  1. 40  README.md
40  README.md
Source Rendered
... ...
@@ -0,0 +1,40 @@
  1
+ExecJS Async
  2
+======
  3
+
  4
+ExecJS lets you run JavaScript code from Ruby. ExecJS Async allows you to execute, and receive results from, asynchronous javascript.
  5
+
  6
+ExecJS Async supports these runtimes (will try to support more in the future, but this is a early release):
  7
+
  8
+* [Node.js](http://nodejs.org/)
  9
+
  10
+A short example:
  11
+
  12
+    require "execjs-async"
  13
+    context = ExecJS.compile_async <<-JAVASCRIPT
  14
+      var run = function(html, code){
  15
+        var jsdom = require('jsdom');
  16
+        
  17
+        jsdom.env(html, function(errors, window) {
  18
+          callback(window.document.getElementByName('body').innerHTML);
  19
+        });
  20
+      }
  21
+    JAVASCRIPT
  22
+    context.call 'run', "<p>Hello World</p>"
  23
+    # => "<p>Hello World</p>"
  24
+    
  25
+
  26
+Notice the "callback" call in the compiled javascript code above.  They object passed into this callback will be the result of context#call.  Without ExecJS Async you would not be able to get back 'window.document.getElementByName('body').innerHTML' because jsdom.env is asynchronous.  And since more and more js libs are being written asynchronously these days (thanks to the popularity of node.js), it would make sense to support it in ExecJS (even if it's hard to support it across runtimes)
  27
+
  28
+Even though ExecJS supports just calling ExecJS.eval or ExecJS.exec, async only supports using ExecJS.compile_async, because that is how it is currently being used.
  29
+
  30
+# Installation
  31
+
  32
+    $ gem install execjs-async
  33
+
  34
+# License
  35
+
  36
+Copyright (c) 2011 Eric Allam.
  37
+
  38
+ExecJS is maintained by Sam Stephenson and Josh Peek. 
  39
+
  40
+Released under the MIT license.

0 notes on commit 217efd0

Please sign in to comment.
Something went wrong with that request. Please try again.