Skip to content

Commit 9efae6b

Browse files
committed
load markdown readme inside the page
1 parent 569bae4 commit 9efae6b

File tree

2 files changed

+38
-6
lines changed

2 files changed

+38
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
# Ruby.wasm quickstart - WASI GEM Example
2-
## for the rest of us
2+
3+
## For the rest of us
34

45
Ruby.wasm lets you run the Ruby Programming Language in the Browser using Webassembly.
56
This projects makes it easier to get started with a wasm binary that included the Javascript bridge. You can also add your own gems from Rubygems into the webassembly file or use ruby code files on your website.

index.html

Lines changed: 36 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
background: #212121;
1111
font-size: 30px;
1212
color: whitesmoke;
13+
padding: 20px;
1314
}
14-
a, a:link, a:visited {
15+
a, a:link, a:visited {
16+
color: #FF0000;
17+
}
18+
.examples a, .examples a:link, .examples a:visited {
1519
display: block;
1620
color: #FF0000;
1721
margin: 20px;
@@ -22,15 +26,42 @@
2226
<body>
2327
<h1>Ruby.wasm Quickstart</h1>
2428
<script type="text/ruby" data-eval="async">
29+
require 'kramdown'
2530
$window = JS.global
2631
$d = $window.document
32+
33+
$d.createElement("h2").tap {|e|
34+
e.innerText = "Examples"
35+
$d.body.appendChild(e)
36+
}
37+
38+
examplesDiv = $d.createElement("div").tap {|div|
39+
div.classList.add("examples")
40+
$d.body.appendChild(div)
41+
}
2742
examples = %w(heartbeat canvas kramdown require run-code shoppingList)
2843
examples.each do |example|
29-
link = $d.createElement("a")
30-
link.href = "#{example}.html"
31-
link.innerText = example
32-
$d.body.appendChild(link)
44+
$d.createElement("a").tap {|link|
45+
link.href = "#{example}.html"
46+
link.innerText = example
47+
examplesDiv.appendChild(link)
48+
}
49+
end
50+
51+
readmeUrl = "README.md"
52+
response = JS.global.fetch(readmeUrl).await
53+
if response.status.to_i == 200
54+
readmeMarkdown = response.text.await.to_s
3355
end
56+
57+
if readmeMarkdown
58+
$d.createElement("div").tap {|e|
59+
e.classList.add("explanation")
60+
e.innerHTML = Kramdown::Document.new(readmeMarkdown).to_html
61+
$d.body.appendChild(e)
62+
}
63+
end
64+
3465
</script>
3566
</body>
3667
</html>

0 commit comments

Comments
 (0)