class Opal::Context::Loader
Loader for v8 context
def find_lib(id)
def find_lib(id) @paths.each do |path| candidate = File.join path, "#{id}.rb" return candidate if File.exists? candidate candidate = File.join path, id return candidate if File.exists? candidate end return File.expand_path id if File.exists? id return File.expand_path(id + '.rb') if File.exists?(id + '.rb') nil end
def initialize(context, paths)
def initialize(context, paths) @context = context @paths = paths end
def resolve_lib(id)
def resolve_lib(id) resolved = find_lib id raise "Cannot find lib `#{id}'" unless resolved resolved end
def ruby_file_contents(filename)
def ruby_file_contents(filename) Opal::Parser.new.parse File.read(filename) end
def wrap(content, filename)
def wrap(content, filename) code = "(function($rb, self, __FILE__) { #{content} });" @context.eval code, filename # code end