Sha256: 4f6212bfc09dd7b4509daf615bd1d8389b26a822b4797f76058392a4d4d5af90

Contents?: true

Size: 1.16 KB

Versions: 7

Compression:

Stored size: 1.16 KB

Contents

require 'opal/compiler'
require 'opal/erb'
require 'opal/version'
require 'encoding'

module Kernel
  def eval(str)
    code = Opal.compile str, file: '(eval)'
    `eval(#{code})`
  end

  def require_remote url
    %x{
      var r = new XMLHttpRequest();
      r.open("GET", url, false);
      r.send('');
    }
    eval `r.responseText`
  end
end

%x{
  Opal.compile = function(str, options) {
    if (options) {
      options = Opal.hash(options);
    }
    return Opal.Opal.$compile(str, options);
  };

  Opal.eval = function(str, options) {
   return eval(Opal.compile(str, options));
  };

  function run_ruby_scripts() {
    var tag, tags = document.getElementsByTagName('script');

    for (var i = 0, len = tags.length; i < len; i++) {
      tag = tags[i];
      if (tag.type === "text/ruby") {
        if (tag.src)       Opal.Kernel.$require_remote(tag.src);
        if (tag.innerHTML) Opal.Kernel.$eval(tag.innerHTML);
      }
    }
  }

  if (typeof(document) !== 'undefined') {
    if (window.addEventListener) {
      window.addEventListener('DOMContentLoaded', run_ruby_scripts, false);
    }
    else {
      window.attachEvent('onload', run_ruby_scripts);
    }
  }
}

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
opal-0.8.1 stdlib/opal-parser.rb
opal-0.8.1.rc1 stdlib/opal-parser.rb
opal-0.8.0 stdlib/opal-parser.rb
opal-0.8.0.rc3 stdlib/opal-parser.rb
opal-0.8.0.rc2 stdlib/opal-parser.rb
opal-0.8.0.rc1 stdlib/opal-parser.rb
opal-0.8.0.beta1 stdlib/opal-parser.rb