voltrb / volt

A Ruby web framework where your Ruby runs on both server and client
MIT License
3.22k stars 196 forks source link

require error from opal #246

Closed rubydesign closed 9 years ago

rubydesign commented 9 years ago

I added a gem to my gemfile and required it in the main_controller When i load the page i get

Opal::Builder::MissingRequire: A file required by "app.rb" wasn't found. A file required by "main/lib/main_view" wasn't found. can't find file: "salama" in ["//opal-0.7.2/opal", "//opal-0.7.2/stdlib", "//opal-0.7.2/lib", "/Users/raisa/salama/opal-pixi/lib", "/Users/raisa/salama/salama-debugger/app", "//volt-0.9.4/app", "//volt-0.9.4/lib", "//volt-bootstrap-0.0.10/app", "//volt-bootstrap-0.0.10/lib", "//volt-mongo-0.1.1/app", "//volt-mongo-0.1.1/lib"] //opal-0.7.2/lib/opal/builder.rb:45:in rescue in build_str' //opal-0.7.2/lib/opal/builder.rb:38:inbuild_str' //volt-0.9.4/lib/volt/server/component_handler.rb:31:in `compile_for_component'

(ps, shortened paths for readability)

The reason i think this is a bug, is that i have the same procedure with opal-pixi, and that works. The trace mentiones opal-pixi in the load path, but not my gem, which is salama.

The code is here: https://github.com/salama/salama-debugger just the normal bundle, volt s

Thanks for any help. I read all the docs but couldn't find anything

PS: tried on gitter, but gitter was down or wobly (or the net) and my timezone window is closing.

ryanstout commented 9 years ago

@dancinglightning salama looks like an interesting project. You would know better than me if it will compile on the client side. You probably need to get it's lib on the opal load path. Try doing this in app/main/config/initializers/boot.rb

unless RUBY_PLATFORM == 'opal'
  lib_path = Gem.loaded_specs['salama'].full_gem_path + '/lib'
 Opal.append_path(lib_path)
end

That should add it to opal's load path. (I need a better way of doing this obviously :-) Let me know if that works. Thanks

ryanstout commented 9 years ago

@dancinglightning totally unrelated, but have you seen github.com/whitequark/parser Its a full ruby parser written in ruby with almost no dependencies.

rubydesign commented 9 years ago

@ryanstout thanks for the tip, i had found as far as Opal.append_path.

Part of the reason i opened this as an issue was the fact that i had read all the docs and still got this. So i think you should either put this in the docs, or auto-append or find some mechanism in the dependencies where one could just say (eg) client_gem("salama") and it would go through the dependencies and do this for all.

Thanks for the project comment, and yes it is very interesting. Reinventing "the way", just like you are. And yes i know about the whitequark parser, which i find cryptic, so i didn't want to use it.

ryanstout commented 9 years ago

@dancinglightning yea, I tried to auto include all gems in the opal path, but thats a bad idea for a few reasons. I'll probably add a gem option to dependencies.

rubydesign commented 9 years ago

great.

And i would think some docs update quite soon, because this behaviour is contrary to what docs say and may put many people who just try volt out off.

If you want a hand, i could spend an hour for all this time you're helping others like me :-)

rubydesign commented 9 years ago

just for completeness, the code works.

but not in the initializer (or in the controller). But if i put it in config/app.rb it works.