Skip to content

Commit affbc4e

Browse files
ledsunkateinoigakukun
authored andcommitted
Enable src attribute in script tag.
Ruby scripts can be written in files with the rb extension. This is more compatible with editor support than Ruby scripts written inline in the script tag.
1 parent a64de62 commit affbc4e

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

packages/npm-packages/ruby-wasm-wasi/src/browser.script.ts

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,18 @@ export const main = async (pkg: { name: string, version: string }) => {
1515
runRubyScriptsInHtml(vm);
1616
};
1717

18-
const runRubyScriptsInHtml = (vm) => {
18+
const runRubyScriptsInHtml = async (vm) => {
1919
const tags = document.getElementsByTagName("script");
2020
for (var i = 0, len = tags.length; i < len; i++) {
2121
const tag = tags[i];
2222
if (tag.type === "text/ruby") {
23-
if (tag.innerHTML) {
23+
if (tag.hasAttribute('src')){
24+
const response = await fetch(
25+
tag.getAttribute('src')
26+
);
27+
const rubyScript = await response.text();
28+
vm.eval(rubyScript);
29+
} else if (tag.innerHTML) {
2430
vm.eval(tag.innerHTML);
2531
}
2632
}

0 commit comments

Comments
 (0)