Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

OpalRb with MeteorJS?

I have been intrigued by the power and elegance that Opal offers in the way of using pure Ruby vs CoffeeScript or, of course, JS.

How would one go about leveraging Opal for Meteor as the primary language for development?

UPDATE: just wanted to share that we have shifted focus over to Volt for our realtime needs in an isomorphic environment that offers Ruby from bottom to top. It has been a fantastic experience and even Matz has tweeted about it a few times now.

like image 343
ylluminate Avatar asked Aug 15 '13 15:08

ylluminate


3 Answers

I just released an initial version.

This will compile Ruby files to Javascript, but there is nothing meteor specific (yet).

I plan on porting Meteor to a Ruby class at some point, stay tuned or even better submit pull requests...

like image 74
Marc-André Lafortune Avatar answered Nov 02 '22 00:11

Marc-André Lafortune


Yes, check out how the coffeescript package is implemented in Meteor in order to compile .coffee to .js. Specifically, the following

  • https://github.com/meteor/meteor/blob/devel/packages/coffeescript/package.js - The undocumented _transitional_registerBuildPlugin function which tells meteor how to turn coffeescript files into js files
  • https://github.com/meteor/meteor/blob/devel/packages/coffeescript/plugin/compile-coffeescript.js - The script that compiles files and generates source maps.
  • https://github.com/meteor/meteor/blob/devel/tools/bundler.js for how compiled files are served.

If everything is super well designed, you probably shouldn't have to touch the bundler to create a smart package that will build OpalRb files. However, I'm guessing that you are probably going to have to fire off a pull request or two to core in the bundler area in order to get it to play well with your package. Right now, the preprocessor treats all files individually, which may not be possible with your language (I'm not sure.) In the process, however, you'll be contributing to make Meteor's support of other JS dialects and compilers even better!

I'll reiterate my point that Coffeescript seems ideal if you want some sort of high level language for writing JS, especially since it supports in-browser source maps for debugging now.

like image 24
Andrew Mao Avatar answered Nov 02 '22 01:11

Andrew Mao


Maybe a little late on the boat: I wrote a build plugin for Opal in Meteor.
You can find it on atmosphere https://atmospherejs.com/massimoronca/opal https://atmospherejs.com/mikamai/opal

You can install the plugin using

meteor add massimoronca:opal
meteor add mikamai:opal

Every file ending in .rb or .js.rb will be automatically compiled.

You'll have to wrap Meteor builtin Objects, until I'll release a package that does that, you can find a small example on how to do it in this gist https://gist.github.com/wstucco/42392ee21b76dfa3ef83

For example the Meteor global Object can be wrapped in Opal like this

class Meteor
  def self.server?
    `Meteor.isServer`
  end

  def self.client?
    `Meteor.isClient`
  end

  def self.cordova?
    `Meteor.isCordova`
  end

  def self.startup(&block)
    `#{block.call if block_given?}`
  end
end

and used this way

puts "Hello from server" if Meteor.server?

EDIT: moved the plugin under the Mikamai account

like image 2
Massimo Ronca Avatar answered Nov 02 '22 00:11

Massimo Ronca