git.s-ol.nu mmm / d9eafa2
add sandbox s-ol 2 years ago
13 changed file(s) with 93 addition(s) and 4 deletion(s). Raw diff Collapse all Expand all
1515 RUN tup init && tup generate --config tup.docker.config build-static.sh && ./build-static.sh
1616
1717 EXPOSE 8000
18 ENTRYPOINT ["moon", "build/server.moon", "fs", "0.0.0.0", "8000"]
18 ENTRYPOINT ["moon", "build/server.moon", "fs", "0.0.0.0", "8000", "^/sandbox/"]
2727 opts.port = 8000 unless opts.port
2828 opts.onstream = @\stream
2929 opts.onerror = @\error
30
31 @editable_paths = opts.editable_paths
3032
3133 @server = server.listen opts
3234
7981 if not fileder
8082 -- fileder not found
8183 404, "fileder '#{path}' not found"
84
85 if method != 'GET' and method != 'HEAD'
86 if not @editable_paths or not path\match @editable_paths
87 return 403, 'editing not allowed'
8288
8389 switch method
8490 when 'GET', 'HEAD'
152158 msg = "#{msg}: #{err}" if err
153159
154160 -- usage:
155 -- moon server.moon [STORE] [host] [port]
156 { store, host, port } = arg
161 -- moon server.moon [STORE] [host] [port] [editable-paths]
162 -- * STORE: see mmm/mmmfs/stores/init.moon:get_store
163 -- * host: interface to bind to (default localhost, set to 0.0.0.0 for public hosting)
164 -- * port: port to serve from, default 8000
165 -- * editable-paths: Lua pattern to match paths in which editing is allowed, default none
166 { store, host, port, editable_paths } = arg
157167
158168 store = get_store store
159 server = Server store, :host, port: port and tonumber port
169 server = Server store, :host, :editable_paths, port: port and tonumber port
160170 server\listen!
0 Everything in this Fileder is world-editable on the internet.
1 It will be reset to its' default state whenever I push my repository.
2 Please behave.
3
4 Here is a list of this fileders content:
0 dynamically embedding children fileders with Lua
0 local d = require 'mmm.dom'
1 local u = require('mmm.mmmfs.util')(d)
2
3 -- we need to return a function to get access to the current fileder
4 -- (thats why there is the '-> fn ->' in the type)
5 return function(self)
6 local children = {}
7 for i, child in ipairs(self.children) do
8 table.insert(children, d.li {
9 'child ' .. i .. ': ',
10 u.link_to(child),
11 })
12 end
13
14 return d.article {
15 d.h1 'The Children are:',
16 d.ul(children),
17 }
18 end
0 an example of how to use JS to create (dynamic) DOM / mmmfs content
0 // a little helper function for creating DOM elements
1 const e = (elem, children) => {
2 const node = document.createElement(elem);
3
4 if (typeof children === 'string')
5 node.innerText = children;
6 else
7 children.forEach(child => node.appendChild(child));
8
9 return node;
10 };
11
12 /* creating the equivalent of the following HTML directly as DOM content:
13 *
14 * <article>
15 * <h1>JavaScript</h1>
16 * <p>...</p>
17 * </article>
18 */
19
20 return e('article', [
21 e('h1', 'JavaScript'),
22 e('p', 'JavaScript is supported natively in the browser but is not currently pre-rendered on the server.'),
23 ]);
0 an example of how to use Lua to create (dynamic) DOM / mmmfs content
0 -- see /meta/mmm.dom for documentation
1 local d = require 'mmm.dom'
2
3 local lua = d.a { 'Lua', href = 'https://www.lua.org/' }
4 local fengari = d.a { 'fengari.io', href = 'https://fengari.io/' }
5
6 return d.article {
7 d.h1 'Lua',
8 d.p { lua, ' is fully supported using ', fengari, ' on the Client.' }
9 }
0 local d = require 'mmm.dom'
1 local u = require('mmm.mmmfs.util')(d)
2
3 return function(self)
4 local children = {}
5 for i, child in ipairs(self.children) do
6 table.insert(
7 children,
8 d.li(u.link_to(child), ': ', (child:get('description: mmm/dom')))
9 )
10 end
11
12 return d.div({
13 d.h3(u.link_to(self)),
14 self:gett('description: mmm/dom'),
15 d.ul(children),
16 })
17 end