Skip to content

Instantly share code, notes, and snippets.

@dpruessner
Created January 10, 2012 19:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dpruessner/1590560 to your computer and use it in GitHub Desktop.
Save dpruessner/1590560 to your computer and use it in GitHub Desktop.
JRuby DOM connection (start)
Hi--
Here's how (I believe) you can modify Web DOM within JRuby:
1) Modify jruby/src/org/jruby/JRubyApplet.java:
409a410,413
> final IRubyObject wrappedApplet = JavaEmbedUtils.javaToRuby(runtime, applet);
> runtime.defineGlobalConstant("JRUBY_APPLET", wrappedApplet);
> wrappedApplet.getMetaClass().defineAnnotatedMethods(RubyMethods.class);
>
This will allow the console-based IRB session to have access to the
JRUBY_APPLET-- not just the non-console-based applet.
2)
jso = Java::NetscapeJavascript::JSObject.getWindow(JRUBY_APPLET)
doc = jso.getMember 'document'
loc = jso.getMember 'location'
loc.getMember 'href' #=> "http://...."
Useful links:
http://docs.oracle.com/javase/1.4.2/docs/guide/plugin/developer_guide/java_js.html
http://www.rgagnon.com/javadetails/java-0172.html
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment