summaryrefslogtreecommitdiff
path: root/src/web/app/dev/router.ls
blob: ac408b36ed465d4d6a848cd7f9a285a362d78247 (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
# Router
#================================

route = require \page
page = null

module.exports = (me) ~>

	# Routing
	#--------------------------------

	route \/ index
	route \/apps apps
	route \/app/new new-app
	route \/app/:app app
	route \* not-found

	# Handlers
	#--------------------------------

	function index
		mount document.create-element \mk-index

	function apps
		mount document.create-element \mk-apps-page

	function new-app
		mount document.create-element \mk-new-app-page

	function app ctx
		document.create-element \mk-app-page
			..set-attribute \app ctx.params.app
			.. |> mount

	function not-found
		mount document.create-element \mk-not-found

	# Exec
	#--------------------------------

	route!

# Mount
#================================

riot = require \riot

function mount content
	if page? then page.unmount!
	body = document.get-element-by-id \app
	page := riot.mount body.append-child content .0