git.s-ol.nu mmm / 233291f
remove Editor remnants, fix inspector s-ol 4 months ago
4 changed file(s) with 54 addition(s) and 132 deletion(s). Raw diff Collapse all Expand all
3333
3434 @flags = opts.flags
3535
36 if @flags.rw == nil
37 @flags.rw = opts.host == 'localhost' or opts.host == '127.0.0.1'
38
3936 if @flags.unsafe == nil
40 @flags.unsafe = not @flags.rw or opts.host == 'localhost' or opts.host == '127.0.0.1'
37 @flags.unsafe = opts.host == 'localhost' or opts.host == '127.0.0.1'
4138
4239 if @flags.cache
43 assert not @flags.rw, "--rw and --cache are incompatible"
4440 @root = Fileder @store
4541 init_cache!
4642
9288 convert 'text/mermaid-graph', 'text/html', debugger\render!, fileder, facet.name
9389
9490 handle: (method, path, facet, value) =>
95 if not @flags.rw and method != 'GET' and method != 'HEAD'
96 return 403, 'editing not allowed'
97
98 switch method
99 when 'GET', 'HEAD'
100 root = @root or Fileder @store
101 export BROWSER
102 BROWSER = :path
103 fileder = root\walk path
104
105 if not fileder
106 -- fileder not found
107 return 404, "fileder '#{path}' not found"
108
109 val = switch facet.name
110 when '?index', '?tree'
111 -- serve fileder index
112 -- '?index': one level deep
113 -- '?tree': recursively
114 depth = if facet.name == '?tree' then -1 else 1
115 index = @store\get_index path, depth
116 convert 'table', facet.type, index, fileder, facet.name
117 else
118 if facet.type == '?'
119 facet.type = 'text/html'
120 current = fileder
121 while current
122 if type = current\get '_web_view: type'
123 facet.type = type\match '^%s*(.-)%s*$'
124 break
125
126 if current.path == ''
127 break
128
129 path, _ = dir_base current.path
130 current = root\walk path
131
132 if facet.type == 'text/html+interactive'
133 @handle_interactive fileder, facet
134 else if base = facet.type\match '^DEBUG %-> (.*)'
135 facet.type = base
136 @handle_debug fileder, facet
137 else if not fileder\has_facet facet.name
138 404, "facet '#{facet.name}' not found in fileder '#{path}'"
139 else
140 fileder\get facet
141
142 if val
143 200, val
91 if method != 'GET' and method != 'HEAD'
92 return 501, "not implemented"
93
94 root = @root or Fileder @store
95 export BROWSER
96 BROWSER = :path
97 fileder = root\walk path
98
99 if not fileder
100 -- fileder not found
101 return 404, "fileder '#{path}' not found"
102
103 val = switch facet.name
104 when '?index', '?tree'
105 -- serve fileder index
106 -- '?index': one level deep
107 -- '?tree': recursively
108 depth = if facet.name == '?tree' then -1 else 1
109 index = @store\get_index path, depth
110 convert 'table', facet.type, index, fileder, facet.name
111 else
112 if facet.type == '?'
113 facet.type = 'text/html'
114 current = fileder
115 while current
116 if type = current\get '_web_view: type'
117 facet.type = type\match '^%s*(.-)%s*$'
118 break
119
120 if current.path == ''
121 break
122
123 path, _ = dir_base current.path
124 current = root\walk path
125
126 if facet.type == 'text/html+interactive'
127 @handle_interactive fileder, facet
128 else if base = facet.type\match '^DEBUG %-> (.*)'
129 facet.type = base
130 @handle_debug fileder, facet
131 else if not fileder\has_facet facet.name
132 404, "facet '#{facet.name}' not found in fileder '#{path}'"
144133 else
145 406, "cant convert facet '#{facet.name}' to '#{facet.type}'"
146 when 'POST'
147 if facet
148 @store\create_facet path, facet.name, facet.type, value
149 200, 'ok'
150 else
151 200, @store\create_fileder dir_base path
152 when 'PUT'
153 if facet
154 @store\update_facet path, facet.name, facet.type, value
155 200, 'ok'
156 else
157 cmd, args = value\match '^([^\n]+)\n(.*)'
158 switch cmd
159 when 'swap'
160 child_a, child_b = args\match '^([^\n]+)\n([^\n]+)$'
161 assert child_a and child_b, "invalid arguments"
162
163 @store\swap_fileders path, child_a, child_b
164 200, 'ok'
165 when nil
166 400, "invalid request"
167 else
168 501, "unknown command #{cmd}"
169 when 'DELETE'
170 if facet
171 @store\remove_facet path, facet.name, facet.type
172 else
173 @store\remove_fileder path
174 200, 'ok'
175 else
176 501, "not implemented"
134 fileder\get facet
135
136 if val
137 200, val
138 else
139 406, "cant convert facet '#{facet.name}' to '#{facet.type}'"
177140
178141 err_and_trace = (msg) -> debug.traceback msg, 2
179142 stream: (sv, stream) =>
219182 -- usage:
220183 -- moon server.moon [FLAGS] [STORE] [host] [port]
221184 -- * FLAGS - any of the following:
222 -- --[no-]rw - enable/disable POST?PUT/DELETE operations (default: on if local)
223 -- --[no-]unsafe - enable/disable server-side code execution when writable is on (default: on if local or --no-rw)
185 -- --[no-]unsafe - enable/disable server-side code execution when writable is on (default: on if local)
224186 -- --[no-]cache - cache all fileder contents (default: off)
225187 -- * STORE - see mmm/mmmfs/stores/init.moon:get_store
226188 -- * host - interface to bind to (default localhost, set to 0.0.0.0 for public hosting)
2828 transform: (href) => span a (code href), :href
2929 }
3030 }
31 get_casts = -> combine casts, converts --, PLUGINS.editors
31 get_casts = -> combine casts, converts
3232
3333 export BROWSER
3434 class Browser
210210 key
211211
212212 @inspect_err = ReactiveVar!
213 @editor = ReactiveVar!
214213
215214 with div class: 'view inspector'
216215 -- nav
222221
223222 \append div {
224223 class: 'subnav'
225
226 ondrop: ->
227 print "dropped"
228
229 onpaste: ->
230 print "pasted"
231224
232225 @inspect_prop\map (current) ->
233226 current = current and current\tostring!
244237 for value in pairs fileder.facet_keys
245238 \append option value, :value, selected: value == current
246239
247 button 'rm', class: 'tight', onclick: (_, e) ->
248 if window\confirm "continuing will permanently remove the facet '#{@inspect_prop\get!}'."
249 fileder = @fileder\get!
250 fileder\set @inspect_prop\get!, nil
251 @refresh true
252
253 button 'add', class: 'tight', onclick: (_, e) ->
254 facet = window\prompt "please enter the facet string ('name: type' or 'type'):", 'text/markdown'
255 return if not facet or facet == '' or facet == js.null
256 fileder = @fileder\get!
257 fileder\set facet, ''
258 @inspect_prop\set Key facet
259 @refresh!
260
261240 div style: flex: '1'
262
263 @editor\map (e) -> e and e.saveBtn
264241 }
265242
266243 -- error / content
269246 \append @inspect_err
270247 \append with pre class: 'content'
271248 \append keep @inspect_prop\map (prop, old) ->
272 @get_content facet, @inspect_err, (fileder, facet) ->
249 @get_content prop, @inspect_err, (fileder, facet) ->
273250 value, key = fileder\get facet
274251 assert key, "couldn't @get #{facet}"
275252
276253 conversions = get_conversions fileder, 'mmm/dom', key.type, get_casts!
277254 assert conversions, "cannot cast '#{key.type}'"
278 with res = apply_conversions fileder, conversions, value, facet
279 @editor\set if res.EDITOR then res
255 apply_conversions fileder, conversions, value, facet
280256
281257 -- children
282258 \append nav {
300276 'justify-content': 'space-between'
301277
302278 span '- ', (link_to child, code name), style: flex: 1
303
304 button '↑', disabled: i == 1, onclick: (_, e) ->
305 fileder\swap_children i, i - 1
306 @refresh true
307
308 button '↓', disabled: i == num, onclick: (_, e) ->
309 fileder\swap_children i, i + 1
310 @refresh true
311
312 button 'rm', onclick: (_, e) ->
313 if window\confirm "continuing will permanently remove all content in '#{child.path}'."
314 fileder\remove_child i
315 @refresh true
316279 }
317280
318281
4343 str = str\gsub '%%|', '%%'
4444 str, cnt
4545
46 -- list of converts, editors, scripts
46 -- list of converts
4747 -- converts each have
4848 -- * inp - input type. can capture subtypes using `(.+)`
4949 -- * out - output type. can substitute subtypes from inp with %1, %2 etc.
+0
-3
root/static/$order less more
0 highlight-pack
1 style
2 fengari-web