-
-
Save ylluminate/7adfc35aeb07a03e018a to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!doctype html> | |
<html> | |
<head> | |
<script src="http://cdn.opalrb.org/opal/0.6.0/opal.js"></script> | |
<script src="http://cdn.opalrb.org/opal/0.6.0/opal-parser.js"></script> | |
<script src="run_ruby_scripts.js"></script> | |
<!-- | |
<script type="text/ruby"> | |
puts 'Test: in index.html' | |
</script> | |
--> | |
<script type="text/ruby" src="script.rb"></script> | |
</head> | |
<body> | |
<h1>Test</h1> | |
</body> | |
</html> | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function run_ruby_scripts() { | |
var tags = document.getElementsByTagName('script'), tag; | |
var load_remote_script = function(url) { | |
var r = new XMLHttpRequest(); | |
r.open("GET", url, false); | |
r.send(''); | |
return r.responseText; | |
} | |
for (var i = 0, len = tags.length; i < len; i++) { | |
tag = tags[i]; | |
if (tag.type === "text/ruby") { | |
if (tag.src) Opal.eval(load_remote_script(tag.src)); | |
if (tag.innerHTML) Opal.eval(tag.innerHTML); | |
} | |
} | |
} | |
if (typeof(document) !== 'undefined') { | |
if (window.addEventListener) { | |
window.addEventListener('DOMContentLoaded', run_ruby_scripts, false); | |
} | |
else { | |
window.attachEvent('onload', run_ruby_scripts); | |
} | |
} | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
puts "Test: from script.rb" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment