Skip to content

Instantly share code, notes, and snippets.

@ylluminate
Created April 5, 2014 17:48
Show Gist options
  • Save ylluminate/7adfc35aeb07a03e018a to your computer and use it in GitHub Desktop.
Save ylluminate/7adfc35aeb07a03e018a to your computer and use it in GitHub Desktop.
<!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>
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);
}
}
puts "Test: from script.rb"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment