These are chat archives for opal/opal

22nd
Mar 2018
Mitch VanDuyn
@catmando
Mar 22 2018 16:01
Can anybody help me with this?
I have a gem hyper-spec
that adds rspec (server side) helpers one of which does this:
page = "<%= javascript_include_tag 'time_cop' %>\n#{page}"
(i.e. it creates a html header for the code under test that includes the above time_cop link.)
the time_cop file is an opal code file.
I have placed it in the lib/assets/javascripts/ directory, and made the gem an engine so that the time_cop.js asset should automatically be found by the rails app.
I am 99% sure that this was (a) working last year, and (b) that if I make time_cop.js.rb into time_cop.js (but precompile the code) it will work.
So it seems like for whatever reason the rails sprockets and preprocessing equipment is not realizing that time_cop.js.rb is an asset to be compiled.
Mitch VanDuyn
@catmando
Mar 22 2018 16:07
I can fix this by adding config.assets.precompile += %w( time_cop.js ) either to the application config or to a rails engine in the gem, but this seems very klunky.
any ideas?
Elia Schito
@elia
Mar 22 2018 16:36
@catmando adding it to the precompile list sounds fine, maybe just in the test env?
if it's just for test you can also try to play with stuff like Rails.application.assets['time_cop.js'] to embed the code directly into a script tag
or have a custom route that serves it
Mitch VanDuyn
@catmando
Mar 22 2018 16:39
thanks
Mitch VanDuyn
@catmando
Mar 22 2018 21:02
I spoke a little too soon... I can successfully load the asset directly by calling Rails.application.assets['time_cop.js'] but it doesn't actually seem to load the contained opal code.
is there some additional magic needed?
Jan Biedermann
@janbiedermann
Mar 22 2018 23:48

@/all , especially @mistergibson might be interested

gem 'hyper-vis', '~> 1.0.1'

https://github.com/janbiedermann/hyper-vis
A Opal Ruby wrapper for Vis.js with Ruby-Hyperloop Components.
Wraps complete vis.js, for graph graphs, charts in 2d and 3d, and timelines.