Nashorn and AsciidoctorJs
Alex Soto
asotobu at gmail.com
Sat Jul 26 12:02:23 UTC 2014
Hi guys,
currently I am working on integrating Asciidoctor to Java using Nashorn and
Opal. Nowadays we have got an asciidoctor java running above JRuby.
Apart from Asciidoctor java we also have an asciidoctorjs which is created
using Opal (a gem to convert Ruby programs to JavaScript).
So next step is to integrate this js to java using nashorn. But we are
having one problem.
I have created a project with a test so you can take a look as well:
https://github.com/lordofthejars/asciidoctorjs
The test is located at
https://github.com/lordofthejars/asciidoctorjs/blob/master/src/test/java/rhino/RenderDocumentWithRhino.java
(although it is called Rhino currently we are using Nashorn).
If I create an script engine an I use the eval method everywhere it works
perfectly but because I would like to use some more typesafe approach I
decided to create an interface mirroring some asciidoctor operations so I
call invocable.getInterface(AsciidoctorJs.class) to create the proxied
instance and then I call defined methods.
This interface mimics the js asciidoctorjava.js which internally calls
asciidoctor.js operations. This is done because I only want some operations
available from Java part, not the whole operations that asciidoctor.js
offers.
asciidoctorjava.js looks like:
var render = function(content, optionsHash2) {
return Opal.Asciidoctor.$render(content, optionsHash2);
};
The problem is that when I run the test an exception is thrown notifying
that Opal.Asciidoctor.$render is not found. If I change that line to:
var render = function(content, optionsHash2) {
return "Hello World";
};
then it works so it seems that Nashorn don't load the asciidoctor.js but
this is not exactly true because if I execute the same operation but using
eval method it works.
Probably I am missing something in the creation of proxied interface, but
currently I cannot see what.
Any idea on why this happens?
Thank you so much for your help in advance.
Alex.
--
+----------------------------------------------------------+
Alex Soto Bueno - Computer Engineer
www.lordofthejars.com
+----------------------------------------------------------+
More information about the nashorn-dev
mailing list