class Opal::Environment::FS
runtime.
writing, etc. FS plays an intermediate role betweeen opal and the ruby
Server side opal aims to offer much of what Ruby offers.. reading and
access/dir access simply to support require(), Dir.glob() and File.join().
File system access. The browser build of opal has simple methods of FS
def getwd
def getwd proc do Dir.getwd end end
def glob
def glob proc do |glob| Dir.glob(glob) end end
def initialize(env)
def initialize(env) super # a hash of required files - filename => true????? er,, why not array? @required_files = {} self['require'] = require self['getwd'] = getwd setup_load_paths end
def require
def require proc do |path| # no extension? add .rb path = "#{path}.rb" unless /.*\.(rb|js)$/.match(path) # puts "need to require: #{path}" file_path = nil @load_paths.each do |load_path| proposed = File.join load_path, path # puts "trying: #{propos/ed}" if File.exist? proposed file_path = proposed unless @required_files[file_path] @required_files[file_path] = true @environment.load_required_file file_path end break end end return true if file_path false end end
def setup_load_paths
def setup_load_paths @load_paths = [] %w{spec}.each do |opal| @load_paths << File.join(OPALS_PATH, 'opal', opal, 'lib') end # current dir is also in the load path.. @load_paths << Dir.getwd @load_paths << "" end