blob: 1135d2735b5e88144a9550fcff89b3f624c0e571 (
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
55
56
57
|
add = (tmpl) ->
package.path ..= ";#{tmpl}.lua"
package.moonpath ..= ";#{tmpl}.moon"
add '?'
add '?.server'
add '?/init'
add '?/init.server'
-- usage:
-- moon render_all.moon [STORE] [output] [URL-prefix]
{ store, output, prefix } = arg
require 'mmm'
import Fileder, dir_base from require 'mmm.mmmfs.fileder'
import get_store from require 'mmm.mmmfs.stores'
export UNSAFE, STATIC, BROWSER
UNSAFE = true
STATIC = {
spit: (path, val) ->
path = "#{output}/#{path}"
os.execute "mkdir -p '#{dir_base path}'"
with io.open path, 'w'
\write val
\close!
root: prefix
}
require 'mmm.mmmfs'
store = get_store store
root = Fileder store
BROWSER = :root
print "rendering to #{output}"
style_url = (root\walk '/static/style')\gett 'URL -> text/css'
hljs_url = (root\walk '/static/highlight-pack')\gett 'URL -> text/javascript'
STATIC.style = "<link rel=\"stylesheet\" type=\"text/css\" href=\"#{style_url}\" />"
STATIC.scripts = "
<script type=\"text/javascript\" src=\"#{hljs_url}\"></script>
<script type=\"text/javascript\">hljs.initHighlighting()</script>"
tree = root\walk startpath or ''
for fileder in coroutine.wrap tree\iterate
print "rendering '#{fileder.path}'..."
ok, val = pcall fileder.gett, fileder, 'text/html'
if not ok
warn "WARN: couldn't render #{fileder}:"
warn val
STATIC.spit "#{fileder.path}/index.html", val
|