Skip to content

Commit

Permalink
Autorun opal scripts in browser
Browse files Browse the repository at this point in the history
  • Loading branch information
adambeynon committed Sep 19, 2013
1 parent c21b1df commit 5d33396
Showing 1 changed file with 25 additions and 2 deletions.
27 changes: 25 additions & 2 deletions stdlib/opal-parser.js.erb
Expand Up @@ -7,7 +7,30 @@
<%= Opal::RequireParser.parse File.read(File.join Opal.core_dir, '..', 'lib', "#{f}.rb") %>
<% end %>

Opal.parse = function(str) {
return Opal.Opal.Parser.$new().$parse(str);
};

Opal.eval = function(str) {
var js = Opal.Opal.Parser.$new().$parse(str);
return eval(js);
return eval(Opal.parse(str));
};

function run_ruby_scripts() {
console.log("findhing..");
var tags = document.getElementsByTagName('script');

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

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

0 comments on commit 5d33396

Please sign in to comment.