简体   繁体   English

如何编写蛋白石库?

[英]How to write opal library?

I want to write opal library to provide nicer interface to some native javascript I have to use.我想编写 opal 库来为我必须使用的一些本机 javascript 提供更好的界面。 However, I have no idea where to start.但是,我不知道从哪里开始。 I have some of the stuff wrapped in my current code, but dunno how to make it into separate "module" or what term doesn't opal use.我在我当前的代码中包含了一些东西,但不知道如何将它变成单独的“模块”或蛋白石不使用什么术语。

What is common blueprint to start such a thing?启动这种事情的共同蓝图是什么? Or should I just dig through opal-browser and figure it out from there?或者我应该通过opal-browser挖掘并从那里弄清楚?

Key seems to be to use Opal.append_path to add dir with opal code to the search path.关键似乎是使用Opal.append_path将带有 opal 代码的 dir 添加到搜索路径中。

Following code borrowed from https://github.com/opal/opal-jquery/blob/master/lib/opal/jquery.rb seems to illustrate it nicely:以下从https://github.com/opal/opal-jquery/blob/master/lib/opal/jquery.rb借来的代码似乎很好地说明了这一点:

if RUBY_ENGINE == 'opal'
  require 'opal/jquery/window'
  require 'opal/jquery/document'
  require 'opal/jquery/element'
  require 'opal/jquery/event'
  require 'opal/jquery/http'
  require 'opal/jquery/kernel'
else
  require 'opal'
  require 'opal/jquery/version'

  Opal.append_path File.expand_path('../..', __FILE__).untaint
end

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

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