简体   繁体   English

使用 Opal Ruby 访问 DOM:如何正确安装 gems?

[英]Accessing DOM using Opal Ruby : how to install gems properly?

I'd like to test some simple SVG animations with the help of Opal Ruby, that stands as a Ruby to Javascript transpiler.我想在 Opal Ruby 的帮助下测试一些简单的 SVG 动画,它代表 Ruby 到 Javascript 的转译器。

However my first steps in using Opal are awkward.然而,我使用 Opal 的第一步很尴尬。 I can't access the the dom (document object model) at all.我根本无法访问 dom(文档对象模型)。

It seems that my install (gems) is probably suspicious.看来我的安装(gems)可能是可疑的。 I missed something :我错过了一些东西:

opal --compile test.rb > app.js 

Returns :回报:

/home/jcll/.rvm/gems/opal/gems/opal-1.1.1/lib/opal/builder.rb:182:in `read': can't find file: "opal-browser" in: (Opal::Builder::MissingRequire) /home/jcll/.rvm/gems/opal/gems/opal-1.1.1/lib/opal/builder.rb:182:in `read': can't find file: "opal-browser" in: (Opal ::Builder::MissingRequire)

Here are the gem listed :以下是列出的宝石:

ls ~/.rvm/gems/opal/gems/ 

ast-2.4.2 opal-1.0.5 opal-1.1.1 opal-browser-0.2.0 opal-jquery-0.4.4 paggio-0.2.6 parser-2.7.2.0 parser-3.0.1.1 rake-13.0.4 ast-2.4.2 opal-1.0.5 opal-1.1.1 opal-browser-0.2.0 opal-jquery-0.4.4 paggio-0.2.6 parser-2.7.2.0 parser-3.0.1.1 rake-13.0.4

Here is my ruby test :这是我的红宝石测试:

require 'opal'
require 'opal-browser'

# prints ok on the browser console
puts "hello world".center(30,'=')

# prints ok on the browser console
(1..5).each{|i| puts "#{i*2}"}

#p $window.document.class

And finally my Html code :最后是我的 Html 代码:

<!DOCTYPE html>
<html>
  <head>
    <meta charset="utf-8">
    <title>SVG Animation with Opal Ruby</title>
  </head>
  <body>
    <script src="app.js"></script>
    <svg id="svg_root" width="800" height="600">
      <circle id="circle" cx="100" cy="200" r=10 fill="blue" />
    </svg>
  </body>
</html>

(My first intent was to move the SVG circle or react to browser events using Opal Ruby) (我的第一个意图是使用 Opal Ruby 移动 SVG 圆圈或对浏览器事件做出反应)

As of now, we can't release opal-browser as a Gem.截至目前,我们无法将 opal-browser 作为 Gem 发布。

Please use gem "opal-browser", github: "opal/opal-browser"请使用gem "opal-browser", github: "opal/opal-browser"

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

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