aboutsummaryrefslogtreecommitdiffstats
path: root/render.moon
blob: 499845207c777d933c309f72bb98fec02fcb13ab (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
require 'mmm'
import render from require 'mmm.mmmfs'

-- usage:
-- moon render.moon <path_to_root>
{ root } = arg

assert root, "please specify the relative root path as an argument"

require 'lfs'
cwd = lfs.currentdir!
path = ''

while root\find '^%.%./'
  root = root\match '^%.%./(.*)'
  cwd, trimmed = cwd\match '(.*)(/[^/]+)$'
  path = trimmed .. path

root = dofile '$bundle.lua'
assert root, "couldn't load $bundle.lua"
root\mount path, true

content, rehydrate = render root, path
assert content, "no content"

with io.open 'index.html', 'w'
  \write "<!DOCTYPE html>
<html>
  <head>
    <meta charset=\"UTF-8\">
    <title>MMM: lunar low-gravity scripting playground</title>
    <link rel=\"stylesheet\" type=\"text/css\" href=\"/main.css\" />
    <!--
    <link rel=\"preload\" as=\"fetch\" href=\"/mmm/dom/init.lua\" />
    <link rel=\"preload\" as=\"fetch\" href=\"/mmm/component/init.lua\" />
    <link rel=\"preload\" as=\"fetch\" href=\"/mmm/mmmfs/init.lua\" />
    <link rel=\"preload\" as=\"fetch\" href=\"/mmm/mmmfs/fileder.lua\" />
    <link rel=\"preload\" as=\"fetch\" href=\"/mmm/mmmfs/browser.lua\" />
    -->
  </head>
  <body>
    #{content}

    <script src=\"/highlight.pack.js\"></script>
    <script src=\"//cdnjs.cloudflare.com/ajax/libs/marked/0.5.1/marked.min.js\"></script>
    <script src=\"//cdnjs.cloudflare.com/ajax/libs/svg.js/2.6.6/svg.min.js\"></script>
    <script src=\"/fengari-web.js\"></script>
    <script type=\"application/lua\" src=\"/mmm.bundle.lua\"></script>
    <script type=\"application/lua\">require 'mmm'</script>

    #{rehydrate}
  </body>
</html>"
  \close!