Sha256: a5854b078ab44e3b699be9a8b24d9059ce97d6076f2db1bfc14a018e2d4d4487

Contents?: true

Size: 1.72 KB

Versions: 3

Compression:

Stored size: 1.72 KB

Contents

//= require opal/racc
//= require opal/strscan

// We need (some) of the libs from our real ruby parser (not in sprockets load path)
<% ['/grammar', '/lexer', '/parser', '/scope', ''].each do |f| %>
  <%= Opal.parse File.read(File.join Opal.core_dir, '..', '..', "opal#{f}.rb") %>
<% end %>

(function() {
  // quick exit if not insde browser
  if (typeof(window) === 'undefined' || typeof(document) === 'undefined') {
    return;
  }

  function findRubyScripts() {
    var all = document.getElementsByTagName('script');
    for (var i = 0, script; i < all.length; i++) {
      script = all[i];
      if (script.type === 'text/ruby') {
        if (script.src) {
          request(script.src, function(result) {
            runRuby(result);
          });
        }
        else {
          runRuby(script.innerHTML);
        }
      }
      else if (script.type === 'text/erb') {
        runERB(script.innerHTML);
      }
    }
  }

  function runRuby(source) {
    var js = Opal.Opal.Parser.$new().$parse(source);
    eval('(' + js + ')()');
  }

  function request(url, callback) {
    var xhr = new (window.ActiveXObject || XMLHttpRequest)('Microsoft.XMLHTTP');
    xhr.open('GET', url, true);
    if ('overrideMimeType' in xhr) {
      xhr.overrideMimeType('text/plain');
    }
    xhr.onreadystatechange = function() {
      if (xhr.readyState === 4) {
        if (xhr.status === 0 || xhr.status === 200) {
          callback(xhr.responseText);
        }
        else {
          throw new Error('Could not load ruby at: ' + url);
        }
      }
    };
    xhr.send(null);
  }

  if (window.addEventListener) {
    window.addEventListener('DOMContentLoaded', findRubyScripts, false);
  }
  else {
    window.attachEvent('onload', findRubyScripts);
  }
})();

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
opal-0.3.37 lib/assets/javascripts/opal-parser.js.erb
opal-0.3.36 lib/assets/javascripts/opal-parser.js.erb
opal-0.3.35 lib/assets/javascripts/opal-parser.js.erb