5

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.

ylluminate
  • 12,102
  • 17
  • 78
  • 152
  • Coffeescript seems to do many of the same things as OpalRb. It's also going to be a lot less error-prone than Javascript, and has Meteor support. Why do things the hard way? – Andrew Mao Aug 16 '13 at 00:19
  • 5
    Because I believe that it makes things easier and more maintainable, particularly in the long run. Having worked with CoffeeScript, I have to say that Ruby is superior to CoffeeScript and less error prone than even CS in my experience. It seems like a very worthwhile endeavor and would be worth the exploration. – ylluminate Aug 16 '13 at 00:59
  • 1
    you should probably get that supported in the Meteor bundler then, and maybe eventually submit a pull request. You can follow the model of how the coffeescript compiler is set up. – Andrew Mao Aug 16 '13 at 01:56
  • I like your thought process there. Very interesting. – ylluminate Aug 16 '13 at 03:11
  • Any ideas on where I'd start digging into making smart packages that would be similar to how CS is made @AndrewMao? – ylluminate Aug 16 '13 at 03:55

3 Answers3

2

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

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.

Andrew Mao
  • 35,740
  • 23
  • 143
  • 224
2

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...

Marc-André Lafortune
  • 78,216
  • 16
  • 166
  • 166
  • Amazing, great news! It will be truly fantastic to be able to have a full ruby'fied meteor similar in robustness to jquery (https://github.com/opal/opal-jquery) or taken further. – ylluminate Dec 17 '13 at 19:02
  • This package is no longer available after Meteor 0.9 was released with their official package system. Any chance of an update Marc-André? – David Backeus Sep 23 '14 at 07:57
2

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