Asciidoctor.js and Java

classic Classic list List threaded Threaded
11 messages Options
Reply | Threaded
Open this post in threaded view
|

Asciidoctor.js and Java

asotobu
Hi I am trying to integrate Asciidoctor.js into JVM, I have tried with dynjs and rhino, and the result has been unsuccessful. I am thinking that maybe I have some kind of problem with computer encoding or some kind of gnome inside my computer is changing the code.

Can anybody try next code to check if I am doing something wrong?

Basically is create a Java project, downloading both files: https://github.com/asciidoctor/asciidoctor.js/tree/master/dist

And then execute next code:

 ScriptEngineManager manager = new ScriptEngineManager();
 ScriptEngine engine = manager.getEngineByName("JavaScript");

 engine.eval(new java.io.FileReader(new File("src/main/resources/opal.js")));
// engine.eval(new java.io.FileReader(new File("src/main/resources/asciidoctor.js")));


An exception is thrown:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing variable name (<Unknown source>#7718) in <Unknown source> at line number 7718
        at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
       

Thank you so much.
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

mojavelinux
Administrator
Good news! I got it working.

It appears the problem is that in JDK 6 & 7, "char" is a reserved word in the JavaScript engine, and Opal uses that name as a variable. They seemed to have fixed this in JDK 8, even when using the same version of Rhino.

The fix here is to send a patch to Opal to not using the word "char" as a variable name.

Once I changed "char" to "ch" in the generated source, I was able to run the following script:

```javascript
print(Opal.Asciidoctor.$render('*Hello, World!*', Opal.hash2(['doctype'], {'doctype': 'inline'})));
```

I combined the opal.js and asciidoctor.js and loaded it using this Java:

```java
import javax.script.*;
import java.io.*;

public class RunScript {

    public static void main(String[] args) throws Exception {
        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        engine.eval(new java.io.FileReader(new File(args[0])));
    }

}
```

Which I compiled under JDK 7 using:

 $ javac RunScript.java

And I ran using:

 $ java RunScript combined.js

The output, as we expect, is:

....
<strong>Hello, World!</strong>
....

I'll file this issue in Opal and send a patch.

-Dan


On Fri, Feb 7, 2014 at 5:38 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi I am trying to integrate Asciidoctor.js into JVM, I have tried with dynjs and rhino, and the result has been unsuccessful. I am thinking that maybe I have some kind of problem with computer encoding or some kind of gnome inside my computer is changing the code.

Can anybody try next code to check if I am doing something wrong?

Basically is create a Java project, downloading both files: https://github.com/asciidoctor/asciidoctor.js/tree/master/dist

And then execute next code:

 ScriptEngineManager manager = new ScriptEngineManager();
 ScriptEngine engine = manager.getEngineByName("JavaScript");

 engine.eval(new java.io.FileReader(new File("src/main/resources/opal.js")));
// engine.eval(new java.io.FileReader(new File("src/main/resources/asciidoctor.js")));


An exception is thrown:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing variable name (<Unknown source>#7718) in <Unknown source> at line number 7718
        at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
       

Thank you so much.



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

mojavelinux
Administrator
In reply to this post by asotobu
I've attached a fixed version of opal.js that you can play with in the meantime. (I attached a raw version, minified version and gzipped version).

-Dan


On Fri, Feb 7, 2014 at 6:18 PM, Dan Allen <[hidden email]> wrote:
Good news! I got it working.

It appears the problem is that in JDK 6 & 7, "char" is a reserved word in the JavaScript engine, and Opal uses that name as a variable. They seemed to have fixed this in JDK 8, even when using the same version of Rhino.

The fix here is to send a patch to Opal to not using the word "char" as a variable name.

Once I changed "char" to "ch" in the generated source, I was able to run the following script:

```javascript
print(Opal.Asciidoctor.$render('*Hello, World!*', Opal.hash2(['doctype'], {'doctype': 'inline'})));
```

I combined the opal.js and asciidoctor.js and loaded it using this Java:

```java
import javax.script.*;
import java.io.*;

public class RunScript {

    public static void main(String[] args) throws Exception {

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        engine.eval(new java.io.FileReader(new File(args[0])));
    }

}
```

Which I compiled under JDK 7 using:

 $ javac RunScript.java

And I ran using:

 $ java RunScript combined.js

The output, as we expect, is:

....
<strong>Hello, World!</strong>
....

I'll file this issue in Opal and send a patch.

-Dan


On Fri, Feb 7, 2014 at 5:38 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi I am trying to integrate Asciidoctor.js into JVM, I have tried with dynjs and rhino, and the result has been unsuccessful. I am thinking that maybe I have some kind of problem with computer encoding or some kind of gnome inside my computer is changing the code.

Can anybody try next code to check if I am doing something wrong?

Basically is create a Java project, downloading both files: https://github.com/asciidoctor/asciidoctor.js/tree/master/dist

And then execute next code:

 ScriptEngineManager manager = new ScriptEngineManager();
 ScriptEngine engine = manager.getEngineByName("JavaScript");

 engine.eval(new java.io.FileReader(new File("src/main/resources/opal.js")));
// engine.eval(new java.io.FileReader(new File("src/main/resources/asciidoctor.js")));


An exception is thrown:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing variable name (<Unknown source>#7718) in <Unknown source> at line number 7718
        at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
       

Thank you so much.



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--



--

opal.js (399K) Download Attachment
opal.min.js (257K) Download Attachment
opal.min.js.gz (47K) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

mojavelinux
Administrator
In reply to this post by asotobu
Actually, those aren't the right ones. Stay tuned.

-Dan


On Fri, Feb 7, 2014 at 6:39 PM, Dan Allen <[hidden email]> wrote:
I've attached a fixed version of opal.js that you can play with in the meantime. (I attached a raw version, minified version and gzipped version).

-Dan


On Fri, Feb 7, 2014 at 6:18 PM, Dan Allen <[hidden email]> wrote:
Good news! I got it working.

It appears the problem is that in JDK 6 & 7, "char" is a reserved word in the JavaScript engine, and Opal uses that name as a variable. They seemed to have fixed this in JDK 8, even when using the same version of Rhino.

The fix here is to send a patch to Opal to not using the word "char" as a variable name.

Once I changed "char" to "ch" in the generated source, I was able to run the following script:

```javascript
print(Opal.Asciidoctor.$render('*Hello, World!*', Opal.hash2(['doctype'], {'doctype': 'inline'})));
```

I combined the opal.js and asciidoctor.js and loaded it using this Java:

```java
import javax.script.*;
import java.io.*;

public class RunScript {

    public static void main(String[] args) throws Exception {

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        engine.eval(new java.io.FileReader(new File(args[0])));
    }

}
```

Which I compiled under JDK 7 using:

 $ javac RunScript.java

And I ran using:

 $ java RunScript combined.js

The output, as we expect, is:

....
<strong>Hello, World!</strong>
....

I'll file this issue in Opal and send a patch.

-Dan


On Fri, Feb 7, 2014 at 5:38 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi I am trying to integrate Asciidoctor.js into JVM, I have tried with dynjs and rhino, and the result has been unsuccessful. I am thinking that maybe I have some kind of problem with computer encoding or some kind of gnome inside my computer is changing the code.

Can anybody try next code to check if I am doing something wrong?

Basically is create a Java project, downloading both files: https://github.com/asciidoctor/asciidoctor.js/tree/master/dist

And then execute next code:

 ScriptEngineManager manager = new ScriptEngineManager();
 ScriptEngine engine = manager.getEngineByName("JavaScript");

 engine.eval(new java.io.FileReader(new File("src/main/resources/opal.js")));
// engine.eval(new java.io.FileReader(new File("src/main/resources/asciidoctor.js")));


An exception is thrown:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing variable name (<Unknown source>#7718) in <Unknown source> at line number 7718
        at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
       

Thank you so much.



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--



--



--
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

mojavelinux
Administrator
In reply to this post by asotobu
Here's the combined file of opal.js and asciidoctor.js that works for me. It's a hacked up version because I can't get any combination of the latest masters to produce anything good atm :)

There's a little test print at the end of the file that I commented out you can use to verify.

-Dan


On Fri, Feb 7, 2014 at 6:50 PM, Dan Allen <[hidden email]> wrote:
Actually, those aren't the right ones. Stay tuned.

-Dan


On Fri, Feb 7, 2014 at 6:39 PM, Dan Allen <[hidden email]> wrote:
I've attached a fixed version of opal.js that you can play with in the meantime. (I attached a raw version, minified version and gzipped version).

-Dan


On Fri, Feb 7, 2014 at 6:18 PM, Dan Allen <[hidden email]> wrote:
Good news! I got it working.

It appears the problem is that in JDK 6 & 7, "char" is a reserved word in the JavaScript engine, and Opal uses that name as a variable. They seemed to have fixed this in JDK 8, even when using the same version of Rhino.

The fix here is to send a patch to Opal to not using the word "char" as a variable name.

Once I changed "char" to "ch" in the generated source, I was able to run the following script:

```javascript
print(Opal.Asciidoctor.$render('*Hello, World!*', Opal.hash2(['doctype'], {'doctype': 'inline'})));
```

I combined the opal.js and asciidoctor.js and loaded it using this Java:

```java
import javax.script.*;
import java.io.*;

public class RunScript {

    public static void main(String[] args) throws Exception {

        ScriptEngineManager manager = new ScriptEngineManager();
        ScriptEngine engine = manager.getEngineByName("JavaScript");
        engine.eval(new java.io.FileReader(new File(args[0])));
    }

}
```

Which I compiled under JDK 7 using:

 $ javac RunScript.java

And I ran using:

 $ java RunScript combined.js

The output, as we expect, is:

....
<strong>Hello, World!</strong>
....

I'll file this issue in Opal and send a patch.

-Dan


On Fri, Feb 7, 2014 at 5:38 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hi I am trying to integrate Asciidoctor.js into JVM, I have tried with dynjs and rhino, and the result has been unsuccessful. I am thinking that maybe I have some kind of problem with computer encoding or some kind of gnome inside my computer is changing the code.

Can anybody try next code to check if I am doing something wrong?

Basically is create a Java project, downloading both files: https://github.com/asciidoctor/asciidoctor.js/tree/master/dist

And then execute next code:

 ScriptEngineManager manager = new ScriptEngineManager();
 ScriptEngine engine = manager.getEngineByName("JavaScript");

 engine.eval(new java.io.FileReader(new File("src/main/resources/opal.js")));
// engine.eval(new java.io.FileReader(new File("src/main/resources/asciidoctor.js")));


An exception is thrown:

javax.script.ScriptException: sun.org.mozilla.javascript.internal.EvaluatorException: missing variable name (<Unknown source>#7718) in <Unknown source> at line number 7718
        at com.sun.script.javascript.RhinoScriptEngine.eval(RhinoScriptEngine.java:224)
        at javax.script.AbstractScriptEngine.eval(AbstractScriptEngine.java:249)
       

Thank you so much.



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--



--



--



--

combined-good.js (1M) Download Attachment
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

asotobu
Hello,

I have been rendering the Asciidoctor-Chrome-Plugin documentation using three Javascript engines and the JRuby implementation. In all tests I have used the same options and the way of rendering docs, and here are the results:

DynJs: Doesn't work there is an opened issue about it, and we should wait until it is fixed.
Rhino: 1700ms to render all document.
Nashorn: 3740ms to render all document.

AsciidoctorJ with JRuby: 256ms

I have not counted the start up time, but of course starting JRuby environment is much expensive than ScriptEngine. So if DynJs doesn't offer a better performance I think for now using JRuby it is the best option.

Anyway if everybody agree we can create a version based on asciidoctorjs so some packages that having to download 20Mb of JRuby is not acceptable, they can still run asciidoctorj. But let me inform you that Dan has also discovered that people of JRuby wants to split the runtime, so in near future we may offer a package with less weight.

Should I say long love to Ruby?
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

mojavelinux
Administrator
Hehehe. I'm not surprised that JRuby is out performing Rhino and Nashorn because JRuby is just that mature.

However, don't fret just yet. Part of the reason the JavaScript goes so much slower is because the backend in Asciidoctor.js is based on the ERB templates. Now that I've stripped out all the ERB from the built-in templates, we can also cut all that out from Asciidoctor.js so that the output is generated using only direct String interpolation and concatenation. It will also make the size of the Asciidoctor.js script much smaller.

There's one more change I need to make in Asciidoctor core to make that happen. I need to make the renderer pluggable so that I can have more control over how it is loaded. Once I make that change, Asciidoctor.js will at least be running the same code as when using Ruby. Then we can really do some head-to-head comparisons.

I definitely encourage you to proceed with the JavaScript option in AsciidoctorJ. I was thinking you may decide to make 3 JARs, one with just the API and utility classes, one with the JRuby integration and one with the Asciidoctor.js integration. If you aren't sure, perhaps others can chime in.

Cheers,

-Dan


On Sat, Feb 8, 2014 at 10:29 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,

I have been rendering the Asciidoctor-Chrome-Plugin documentation using three Javascript engines and the JRuby implementation. In all tests I have used the same options and the way of rendering docs, and here are the results:

DynJs: Doesn't work there is an opened issue about it, and we should wait until it is fixed.
Rhino: 1700ms to render all document.
Nashorn: 3740ms to render all document.

AsciidoctorJ with JRuby: 256ms

I have not counted the start up time, but of course starting JRuby environment is much expensive than ScriptEngine. So if DynJs doesn't offer a better performance I think for now using JRuby it is the best option.

Anyway if everybody agree we can create a version based on asciidoctorjs so some packages that having to download 20Mb of JRuby is not acceptable, they can still run asciidoctorj. But let me inform you that Dan has also discovered that people of JRuby wants to split the runtime, so in near future we may offer a package with less weight.

Should I say long love to Ruby?


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369p1389.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

asotobu
No problem, for now I was only playing around a bit to exactly know how it works, performance, ...

BTW one question is it possible to render a local file using asciidoctor.js (that is calling renderFile) or as I have done now I have to read first all content of the file and then pass to render method.

And also one thing I just discovered, if ScriptEngine is got by using "Javascript" label, in case of JDK 6 and 7 returns Rhino and JDK 8 Nashorn, so as you said with three jars (or four if we add DynJs) we can cover almost all cases.


2014-02-10 9:55 GMT+01:00 mojavelinux [via Asciidoctor :: Discussion] <[hidden email]>:
Hehehe. I'm not surprised that JRuby is out performing Rhino and Nashorn because JRuby is just that mature.

However, don't fret just yet. Part of the reason the JavaScript goes so much slower is because the backend in Asciidoctor.js is based on the ERB templates. Now that I've stripped out all the ERB from the built-in templates, we can also cut all that out from Asciidoctor.js so that the output is generated using only direct String interpolation and concatenation. It will also make the size of the Asciidoctor.js script much smaller.

There's one more change I need to make in Asciidoctor core to make that happen. I need to make the renderer pluggable so that I can have more control over how it is loaded. Once I make that change, Asciidoctor.js will at least be running the same code as when using Ruby. Then we can really do some head-to-head comparisons.

I definitely encourage you to proceed with the JavaScript option in AsciidoctorJ. I was thinking you may decide to make 3 JARs, one with just the API and utility classes, one with the JRuby integration and one with the Asciidoctor.js integration. If you aren't sure, perhaps others can chime in.

Cheers,

-Dan


On Sat, Feb 8, 2014 at 10:29 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
Hello,

I have been rendering the Asciidoctor-Chrome-Plugin documentation using three Javascript engines and the JRuby implementation. In all tests I have used the same options and the way of rendering docs, and here are the results:

DynJs: Doesn't work there is an opened issue about it, and we should wait until it is fixed.
Rhino: 1700ms to render all document.
Nashorn: 3740ms to render all document.

AsciidoctorJ with JRuby: 256ms

I have not counted the start up time, but of course starting JRuby environment is much expensive than ScriptEngine. So if DynJs doesn't offer a better performance I think for now using JRuby it is the best option.

Anyway if everybody agree we can create a version based on asciidoctorjs so some packages that having to download 20Mb of JRuby is not acceptable, they can still run asciidoctorj. But let me inform you that Dan has also discovered that people of JRuby wants to split the runtime, so in near future we may offer a package with less weight.

Should I say long love to Ruby?


If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369p1389.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML



--



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369p1405.html
To unsubscribe from Asciidoctor.js and Java, click here.
NAML



--
+----------------------------------------------------------+
  Alex Soto Bueno - Computer Engineer
  www.lordofthejars.com
+----------------------------------------------------------+
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

mojavelinux
Administrator

On Mon, Feb 10, 2014 at 2:12 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
BTW one question is it possible to render a local file using asciidoctor.js (that is calling renderFile) or as I have done now I have to read first all content of the file and then pass to render method.

This is one of the open questions I have about JavaScript in general. Is IO part of the standard library? I once asked this of the DynJS team and I didn't get a definitive answer. (It's one of the main reasons I think that JavaScript is still absurd outside of the browser context...though who can argue with its popularity?).

Nashorn examples seem to show that they import java.io.* into JavaScript. See http://download.java.net/jdk8/docs/technotes/guides/scripting/prog_guide/javascript.html

In order to get includes working in the browser extensions, I implemented File.read using XmlHttpRequest as you can see here:

https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/opal_ext/file.rb#L97

This obviously isn't going to work when running on JavaScript inside the JVM. We need to have a way to detect which JavaScript environment we're in so that we can do the right thing. I'm sure we'll sort it out in time. We can at least tell we are running in Java by testing for the existence of the "Java" constant.

```js
if (typeof Java !== 'undefined') {
  // we are inside a Java engine, Nashorn at least
}
```

-Dan
Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

LightGuardjp
Administrator
If you want to test if you're inside of a browser, test for the existence of the document or window object. 

Sent from Mailbox for iPhone


On Wed, Feb 12, 2014 at 6:37 PM, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> wrote:


On Mon, Feb 10, 2014 at 2:12 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
BTW one question is it possible to render a local file using asciidoctor.js (that is calling renderFile) or as I have done now I have to read first all content of the file and then pass to render method.

This is one of the open questions I have about JavaScript in general. Is IO part of the standard library? I once asked this of the DynJS team and I didn't get a definitive answer. (It's one of the main reasons I think that JavaScript is still absurd outside of the browser context...though who can argue with its popularity?).

Nashorn examples seem to show that they import java.io.* into JavaScript. See http://download.java.net/jdk8/docs/technotes/guides/scripting/prog_guide/javascript.html

In order to get includes working in the browser extensions, I implemented File.read using XmlHttpRequest as you can see here:

https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/opal_ext/file.rb#L97

This obviously isn't going to work when running on JavaScript inside the JVM. We need to have a way to detect which JavaScript environment we're in so that we can do the right thing. I'm sure we'll sort it out in time. We can at least tell we are running in Java by testing for the existence of the "Java" constant.

```js
if (typeof Java !== 'undefined') {
  // we are inside a Java engine, Nashorn at least
}
```

-Dan



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369p1459.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML

Reply | Threaded
Open this post in threaded view
|

Re: Asciidoctor.js and Java

mojavelinux
Administrator

Very true. Opal may proxy it though. We'd have to test it.

-Dan

On Feb 12, 2014 7:29 PM, "LightGuardjp [via Asciidoctor :: Discussion]" <[hidden email]> wrote:
If you want to test if you're inside of a browser, test for the existence of the document or window object. 

Sent from Mailbox for iPhone


On Wed, Feb 12, 2014 at 6:37 PM, mojavelinux [via Asciidoctor :: Discussion] <[hidden email]> wrote:


On Mon, Feb 10, 2014 at 2:12 AM, asotobu [via Asciidoctor :: Discussion] <[hidden email]> wrote:
BTW one question is it possible to render a local file using asciidoctor.js (that is calling renderFile) or as I have done now I have to read first all content of the file and then pass to render method.

This is one of the open questions I have about JavaScript in general. Is IO part of the standard library? I once asked this of the DynJS team and I didn't get a definitive answer. (It's one of the main reasons I think that JavaScript is still absurd outside of the browser context...though who can argue with its popularity?).

Nashorn examples seem to show that they import java.io.* into JavaScript. See http://download.java.net/jdk8/docs/technotes/guides/scripting/prog_guide/javascript.html

In order to get includes working in the browser extensions, I implemented File.read using XmlHttpRequest as you can see here:

https://github.com/asciidoctor/asciidoctor/blob/master/lib/asciidoctor/opal_ext/file.rb#L97

This obviously isn't going to work when running on JavaScript inside the JVM. We need to have a way to detect which JavaScript environment we're in so that we can do the right thing. I'm sure we'll sort it out in time. We can at least tell we are running in Java by testing for the existence of the "Java" constant.

```js
if (typeof Java !== 'undefined') {
  // we are inside a Java engine, Nashorn at least
}
```

-Dan



If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369p1459.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML




If you reply to this email, your message will be added to the discussion below:
http://discuss.asciidoctor.org/Asciidoctor-js-and-Java-tp1369p1460.html
To start a new topic under Asciidoctor :: Discussion, email [hidden email]
To unsubscribe from Asciidoctor :: Discussion, click here.
NAML