-
Notifications
You must be signed in to change notification settings - Fork 11
Expand file tree
/
Copy pathmain.io
More file actions
90 lines (77 loc) · 2.11 KB
/
main.io
File metadata and controls
90 lines (77 loc) · 2.11 KB
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
doFile("lib/backpacking.io")
MyApp := BackPacking clone
People := DBSrc clone do(
with("people",{name = "varchar", age = "integer"})
setDB(SQLite3 clone open("people.db"))
unlessTable(
generateTable
insert({name = "Chris", age = 16})
)
)
UsersList := MyApp controller("/people") do(
get := method(
self people := People findAll
render_view("index")
)
post := method(
People insert(input)
self get
)
)
Views := MyApp views do(
index := method(controller,
# Within a view method, undefined slot accesses are turned into html tags.
html(
head(
title("People")
)
body(
# Multiple child tags are defined one per statement
h3("Some people:")
table(border 1,
tr(
th("Name")
th("Age")
)
# When a list is returned, it is assumed to be a list of inner html
# strings and is joined.
controller people map(x,
# TODO: This tag is lost due to being called from map, so not picked
# up by the tag() nesting. Only the return value from the map
# block will be used.
ignoredtag("Some ignored text")
tr(
td(b(x at("name")))
td(x at("age"))
)
)
)
# An example of tag option.
a(href "http://www.google.com"
some_option "some option value",
"here is a useful link"
)
h3("Add a user")
form(method "post"; action "/people",
# TODO: Currently, these have to be in the right order, which is
# pretty silly.
label(for "name", "Name: ")
input(name "name", nil)
br
label(for "age", "Age: ")
input(name "age", nil)
br
input(type "submit"; value "submit", nil)
)
)
)
)
)
Style := MyApp static("scaffold.css","/style.css")
Delete := MyApp controller("/delete/(\\d+)") do(
get := method(
People delete(params at(1))
redirect(UsersList)
)
)
BackPackServer clone with(8000,MyApp) serve