SciRuby / iruby

Official gem repository: Ruby kernel for Jupyter/IPython Notebook
https://github.com/SciRuby/iruby
MIT License
890 stars 27 forks source link

Support `%%javascript` directive #258

Closed rstammer closed 4 years ago

rstammer commented 4 years ago

Jupyter supports executing JavaScript code inline by the directive %%javascript, i.e. a a cell with

%%javascript
// JS code goes here
alert("Hey");

should execute the JS code and produce the alert message box.

However, maybe I have overseen something - but I think unfortunately this does not work together with iruby yet: Bildschirmfoto 2019-10-25 um 16 39 24

Here's how it should look like, as it does work with python3 kernel: Bildschirmfoto 2019-10-25 um 16 40 27

kojix2 commented 4 years ago

Hi @neumanrq

Thank you for your request.

IRuby dose not support magic commands. Magic commands have been discussed several times in the past. But for now, we're not going to support magic commands into IRuby.

The reason is that there are not many people to maintain IRuby and my skills are low. Other Jupyter kernels, such as IJulia, do not support magic commands too.

Another reason why we don't want to support magic commands is that in Ruby, sometimes line start with "%".

%w[apple banana orange strawberry]
%i[cat dog]

But, you can run simple Javascript like this.

IRuby.display('alert("Hey");', mime: "text/javascript")

image

rstammer commented 4 years ago

Hi @kojix2,

thanks for your feedback and sharing your thoughts on that topic. The decision makes totally sense to me - I just did not know about the scope IRuby covers in this direction. The arguments against supporting the magic directives are really reasonable.

Also, thanks for your work on the project - I really appreciate this!