简体   繁体   中英

How to write opal library?

I want to write opal library to provide nicer interface to some native javascript I have to use. 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?

Key seems to be to use Opal.append_path to add dir with opal code to the search path.

Following code borrowed from https://github.com/opal/opal-jquery/blob/master/lib/opal/jquery.rb seems to illustrate it nicely:

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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