简体   繁体   English

OpalRb与MeteorJS?

[英]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. 我对Opal提供的使用纯Ruby与CoffeeScript,当然还有JS的方式所提供的力量和优雅感兴趣。

How would one go about leveraging Opal for Meteor as the primary language for development? 如何利用Opal for Meteor作为开发的主要语言?

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. 更新 :只是想分享一下,我们已经将焦点转移到Volt,以便在同构环境中实现我们的实时需求,从而提供从下到上的Ruby。 It has been a fantastic experience and even Matz has tweeted about it a few times now. 这是一次非常棒的体验,甚至Matz 现在已经发了几次关于它推文

Yes, check out how the coffeescript package is implemented in Meteor in order to compile .coffee to .js . 是的,请查看如何在Meteor中实现coffeescript包,以便将.coffee编译为.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. 如果一切都设计得非常好,您可能不必触摸捆绑器来创建将构建OpalRb文件的智能包。 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! 现在,预处理器单独处理所有文件,这可能是您的语言无法实现的(我不确定。)但是,在此过程中,您将有助于使Meteor对其他JS方言和编译器的支持更加出色!

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. 我将重申我的观点,如果你想要某种高级语言来编写JS,Coffeescript似乎是理想的,特别是因为它支持用于调试的浏览器内源映射。

I just released an initial version . 我刚刚发布了一个初始版本

This will compile Ruby files to Javascript, but there is nothing meteor specific (yet). 这会将Ruby文件编译为Javascript,但没有特定的流星(尚未)。

I plan on porting Meteor to a Ruby class at some point, stay tuned or even better submit pull requests... 我计划在某个时候将Meteor移植到Ruby类,请继续关注甚至更好地提交拉取请求......

Maybe a little late on the boat: I wrote a build plugin for Opal in Meteor. 也许船上有点晚了:我在Meteor中为Opal写了一个构建插件。
You can find it on atmosphere https://atmospherejs.com/massimoronca/opal https://atmospherejs.com/mikamai/opal 你可以在气氛上找到它 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. .rb.js.rb结尾的每个文件都将自动编译。

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 你将不得不包装Meteor内置对象,直到我发布一个这样做的包,你可以在这个要点中找到一个关于如何做到这一点的小例子https://gist.github.com/wstucco/42392ee21b76dfa3ef83

For example the Meteor global Object can be wrapped in Opal like this 例如, Meteor全局对象可以像这样包装在Opal中

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 编辑:在Mikamai帐户下移动插件

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM