Sha256: e35cb7192d9ad2086a7e69e0332c56e8043279fb7639a961f9b50bbc32c0112c

Contents?: true

Size: 847 Bytes

Versions: 1

Compression:

Stored size: 847 Bytes

Contents

module RubyOnRuby
  class FileLoader
    def self.setup(context)
      context.eval <<-JS
        XMLHttpRequest = function() {
          this.open = function(type, url) {
            this.responseText = loadFile(url);
          };
          this.send = function() {};
          this.status = 200;
          this.responseText = "";
          return this;
        };
      JS

      context['loadFile'] = lambda do |this, url|
        begin
          if url && url =~ /\A\.\/lib\/([\w\_\-\/]+\.rb)\Z/i
            file_name = $1
            File.read(File.expand_path("../../../vendor/javascripts/emscripted-ruby/lib/#{file_name}", __FILE__), :encoding => "binary")
          else
            nil
          end
        rescue => e
          puts "Exception when loading #{url}: #{e.message}"
          raise
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
ruby_on_ruby-0.0.1 lib/ruby_on_ruby/file_loader.rb