Skip to content

Commit 5d33396

Browse files
committed
Autorun opal scripts in browser
1 parent c21b1df commit 5d33396

File tree

1 file changed

+25
-2
lines changed

1 file changed

+25
-2
lines changed

stdlib/opal-parser.js.erb

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,30 @@
77
<%= Opal::RequireParser.parse File.read(File.join Opal.core_dir, '..', 'lib', "#{f}.rb") %>
88
<% end %>
99

10+
Opal.parse = function(str) {
11+
return Opal.Opal.Parser.$new().$parse(str);
12+
};
13+
1014
Opal.eval = function(str) {
11-
var js = Opal.Opal.Parser.$new().$parse(str);
12-
return eval(js);
15+
return eval(Opal.parse(str));
1316
};
17+
18+
function run_ruby_scripts() {
19+
console.log("findhing..");
20+
var tags = document.getElementsByTagName('script');
21+
22+
for (var i = 0, len = tags.length; i < len; i++) {
23+
if (tags[i].type === "text/ruby") {
24+
Opal.eval(tags[i].innerHTML);
25+
}
26+
}
27+
}
28+
29+
if (typeof(document) !== 'undefined') {
30+
if (window.addEventListener) {
31+
window.addEventListener('DOMContentLoaded', run_ruby_scripts, false);
32+
}
33+
else {
34+
window.attachEvent('onload', run_ruby_scripts);
35+
}
36+
}

0 commit comments

Comments
 (0)