git.s-ol.nu mmm / 762d3a8
thin out build folder s-ol 3 years ago
4 changed file(s) with 42 addition(s) and 61 deletion(s). Raw diff Collapse all Expand all
77 add '?/init.server'
88
99 require 'mmm'
10 import tohtml from require 'mmm.component'
11 import Browser from require 'mmm.mmmfs.browser'
10 import load_tree from require 'mmm.mmmfs.fileder'
1211 import render from require 'mmm.mmmfs.layout'
1312 import SQLStore from require 'mmm.mmmfs.drivers.sql'
14 import load_tree from require 'build.util'
1513
1614 -- usage:
1715 -- moon render_all.moon [db.sqlite3] [startpath]
1816 { file, startpath } = arg
1917
20 export BROWSER, STATIC
18 export STATIC
2119 STATIC = true
2220
2321 tree = load_tree SQLStore :file
2725 print "rendering '#{fileder.path}'..."
2826 os.execute "mkdir -p 'out/#{fileder.path}'"
2927
30 BROWSER = Browser fileder
3128 with io.open "out/#{fileder.path}/index.html", 'w'
32 \write render (tohtml BROWSER), fileder
29 \write render (fileder\get 'text/html'), fileder
3330 \close!
88
99 require 'mmm'
1010
11 import dir_base, load_tree from require 'build.util'
12 import Key from require 'mmm.mmmfs.fileder'
11 import Key, dir_base, load_tree from require 'mmm.mmmfs.fileder'
1312 import SQLStore from require 'mmm.mmmfs.drivers.sql'
1413 import decodeURI from require 'http.util'
1514
+0
-53
build/util.moon less more
0 require 'lfs'
1 import Fileder, Key from require 'mmm.mmmfs.fileder'
2
3 get_path = (root) ->
4 cwd = lfs.currentdir!
5 path = ''
6
7 while root\find '^%.%./'
8 root = root\match '^%.%./(.*)'
9 cwd, trimmed = cwd\match '(.*)(/[^/]+)$'
10 path = trimmed .. path
11
12 path
13
14 -- split filename into dirname + basename
15 dir_base = (path) ->
16 dir, base = path\match '(.-)([^/]-)$'
17 if dir and #dir > 0
18 dir = dir\sub 1, #dir - 1
19
20 dir, base
21
22 load_tree = (store, root='') ->
23 fileders = setmetatable {},
24 __index: (path) =>
25 with val = Fileder {}
26 .path = path
27 rawset @, path, val
28
29 root = fileders[root]
30 root.facets['name: alpha'] = ''
31 for fn, ft in store\list_facets root.path
32 val = store\load_facet root.path, fn, ft
33 root.facets[Key fn, ft] = val
34
35 for path in store\list_all_fileders root.path
36 fileder = fileders[path]
37
38 parent, name = dir_base path
39 fileder.facets['name: alpha'] = name
40 table.insert fileders[parent].children, fileder
41
42 for fn, ft in store\list_facets path
43 val = store\load_facet path, fn, ft
44 fileder.facets[Key fn, ft] = val
45
46 root
47
48 {
49 :get_path
50 :dir_base
51 :load_tree
52 }
181181
182182 __tostring: => "Fileder:#{@path}"
183183
184 -- split filename into dirname + basename
185 dir_base = (path) ->
186 dir, base = path\match '(.-)([^/]-)$'
187 if dir and #dir > 0
188 dir = dir\sub 1, #dir - 1
189
190 dir, base
191
192 -- load tree from a driver instance
193 -- optionally load subtree starting at 'root' path
194 load_tree = (store, root='') ->
195 fileders = setmetatable {},
196 __index: (path) =>
197 with val = Fileder {}
198 .path = path
199 rawset @, path, val
200
201 root = fileders[root]
202 root.facets['name: alpha'] = ''
203 for fn, ft in store\list_facets root.path
204 val = store\load_facet root.path, fn, ft
205 root.facets[Key fn, ft] = val
206
207 for path in store\list_all_fileders root.path
208 fileder = fileders[path]
209
210 parent, name = dir_base path
211 fileder.facets['name: alpha'] = name
212 table.insert fileders[parent].children, fileder
213
214 for fn, ft in store\list_facets path
215 val = store\load_facet path, fn, ft
216 fileder.facets[Key fn, ft] = val
217
218 root
219
184220 {
185221 :Key
186222 :Fileder
223 :dir_base
224 :load_tree
187225 }