by

Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
Elia Schito
@elia
@jjgh also consider that the CSV library is quite extensive and made of many files…
image.png
I expect it will require some work for it to run, but that probably depends on how you plan to use it
jjgh
@jjgh
Ok @elia I ran your version of the command line and it produced a slightly smaller JS file (just a few kb less). Not sure why, but anyway I think the compilation went ok.
I still have the same problem though: if I do Opal.CSV.$new() from a webpage where I required opal.js and csv.js libs, I still get "Uncaught TypeError: Cannot read property '$new' of undefined".
Why do you think this happens? All other opal classes and methods are there and execute without any problem. It's kinda like as the csv.js is not compiled in a way that can be used.
In the JS console I also tried Opal.require("csv"); and it outputs "false". Do you have any ideas?
Elia Schito
@elia
@jjgh can you put the code somewhere I can try it, a github repo would be great for example
jjgh
@jjgh
@elia sure, I'll get back to this when I have some free time and I'll let you know, thanks!
Rolf
@dkgof
I have a question about Opal and usage of Native. If i have a class "A" in JS, that has a static method a(), how do i wrap A in ruby and call the method a. I tried Native(A).a(); but get undefined method 'a'.
I know i can call it by calling directly with JS wrapping it in backwards quotes, but that does not feel entirely "correct"
Elia Schito
@elia
@dkgof the problem is that a class is also a function, so it's recognized by Native as already being a Proc (in Ruby) and it refuses to wrap it with Native. You can work around this by using the .JS syntax as follows:
A = `class A { static a(){return 123} }`
A.JS.a # => 123
(I used the ES5 class syntax for brevity, but that's not different if you use the function keyword)
PS. feel free to join the new chat Slack workspace at http://slack.opalrb.com
bolandross
@bolandross
Hey guys, I am quite new to opal and currently a bit confused: Is opal-browser already a part of opal or do I have to install it separately? I tried it via gem install browser but this seems to be something different. Then I cloned the opal-browser repository, ran "bundle" in it, then tried to require_relative from my app.rb to the path of the browser.rb, but opal always gives me the message "can't find file: "browser" in:
  • /Library/Ruby/Gems/2.6.0/gems/opal-1.0.3/opal (etc.)" Couldn't find any steps to solve this. Any ideas?
Forrest Chang
@fkchang
@bolandross did you really type gem install browser instead of gem install opal-browser ?
bolandross
@bolandross
@fkchang I indeed did. In the README.md it said require 'browser', so I thought the name of the gem was just 'browser'. Having now installed the the correct gem 'opal-browser' I am unfortunately still getting the same error message, "can't find file: 'opal-browser'"
Forrest Chang
@fkchang
@bolandross the gem name for installation is opal-browser, but inside your opal code you just require 'browser'
bolandross
@bolandross
@fkchang Hey. I tried again, installed the correct gem (opal-browser) and then used require 'browser'. Unfortunately, the same error message remains (can't find file: "browser" in [...])
Toby Mao
@tobymao
hello, i'm trying to implement an incremental compiler and i think i'm pretty close, it seems like the code gen is correct, however, the running opal code cannot find my module

```Opal.modules["engine/game_error"] = function(Opal) {
var self = Opal.top, $nesting = [], nil = Opal.nil,

KaTeX parse error: Can't use function '$' in math mode at position 1: $̲ = Opal.const_g…: $ = Opal.const_get_qualified, 
= Opal.const_get_relative, $breaker = Opal.breaker, $slice = Opal.slice, $module = Opal.module, $klass = Opal.klass;

return (function($base, $parent_nesting) {
var self = $module($base, 'Engine');

var $nesting = [self].concat($parent_nesting);

(function($base, $super, $parent_nesting) {
  var self = $klass($base, $super, 'GameError');

  var $nesting = [self].concat($parent_nesting);

  return nil
})($nesting[0], $$($nesting, 'RuntimeError'), $nesting)

})($nesting[0], $nesting)
};

```

this is what one of the code gen snippets looks like, but when i go to the browser the Opal.Engine constant isn't loaded even though Opal.modules['engine'] is there
at a high level, what i'm doing is for every file that i want to incrementally compile, i create a javascript version of that file. then i concatenate all of them using a topological sort. then i require this javascript file in my main app
Toby Mao
@tobymao
ok i think it's because the require is not getting called, probably because it's a JS file and it has it's own build processor
Toby Mao
@tobymao
i think the solution is i need to make my own processor so that mark_as_required is not injected, then the code will get loaded as normal
lunarfyre7
@lunarfyre7
Should I target rubygems or npm for making an opal binding for a js library?
lunarfyre7
@lunarfyre7
I see, opal libraries seem to use gems mostly
Guillaume Grossetie
@Mogztter
What do you mean by Opal binding?
For Asciidoctor.js -- Asciidoctor (Ruby) transpiled to JavaScript using Opal -- the package is published on npm
lunarfyre7
@lunarfyre7
oh wow that definitely is worth looking into how they do their builds
By binding I mean making a wrapper for a js library
been looking into using opal-webpack-loader for it
Guillaume Grossetie
@Mogztter
Oh OK, in your case it's the other way around then, a Ruby library API on top of a JS library? In this case, it makes sense to publish a gem
Andy Maleh
@AndyObtiva
Hi, can someone pair with me on my new Opal open-source project: https://github.com/AndyObtiva/glimmer-dsl-opal ? I need help setting up opal-rspec and hooking JS listeners using opal-browser or an alternative. Thanks.
Andy Maleh
@AndyObtiva
In opal-browser, how do you hook an onchange listener to a select element? I tried a simple Ruby select(onchange: proc), but that literally hooked the proc object instead of converting it into a JavaScript anonymous function as I would have intuitively expected.
It seems it is time to upgrade from opal-browser to opal-jquery. It supports the event listener hook behavior I need (i.e. Ruby block/proc becoming a JS anonymous function as an event listener). Great!
Andy Maleh
@AndyObtiva
OK, I just realized event listening with Ruby blocks does exist in opal-browser too as an undocumented feature. I found it buried by digging deep down into the code: https://github.com/opal/opal-browser/blob/master/opal/browser/event/base.rb Sweet!!! I guess I'll stick to opal-browser for now.
Thanks all for being my Rubber Duck!
Benoit Daloze
@eregon
Hello, is there anyone around who could help me figure how the MSpec setup works in Opal? I'd like to add a new formatter or tweak one
Guillaume Grossetie
@Mogztter
I can try :)
(btw, I think the official chat is now: https://opalrb.slack.com)
Benoit Daloze
@eregon
I managed by basically running subset of specs, so didn't need modifications.
I tried to add a new formatter but would end up running in "constant not found" error even though I required the file defining that constant.
https://github.com/opal/opal#readme still points to Gitter
Toby Mao
@tobymao
how do we join the opal slack? are invites open?
Toby Mao
@tobymao
i have a large opal project and wanted to improve my compilation times so i built an incremental compiler for my workflow, wanted to discuss how to bring that into opal / if it's wanted
Toby Mao
@tobymao
found the link to the slack, the invite can be found on the opal home page https://opalrb.com/
Larry North
@LarryNorth
It seem that Gem i18n cannot be used with Opal because it depends on current-ruby, which has native extensions. Is that correct? If so, how is internationalization/localization done with Opal?
hmdne
@hmdne
@LarryNorth I will be certainly touching this topic in the future, but for now I see no immediate solution.
Just in case, we are mostly on Slack currently.
Full Stack Ruby on Rails Developer
@webdev778
Hi
image.png
Full Stack Ruby on Rails Developer
@webdev778
Ruby 2.5 Windows,bundle installed failed as you can see, it's all working on 2.4, 2.6 2.7
not sure what causing this issue