-
Notifications
You must be signed in to change notification settings - Fork 22
/
html_generator.fy
54 lines (47 loc) · 902 Bytes
/
html_generator.fy
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
# simple html generator example
# this isn't to be taken very seriously but it shows some syntax &
# features of Fancy :)
def class String {
def but_last {
# same as: self from: 0 to: -2
# and: self from: 0 to: (self size - 2)
self[[0,-2]]
}
}
def class HTML {
def open_tag: name {
"<" ++ (name but_last) ++ ">"
}
def close_tag: name {
"</" ++ (name but_last) ++ ">"
}
def unknown_message: name with_params: params {
str = open_tag: name
body = params first call
body is_a?: Array . if_true: {
body = body join
}
str ++ body ++ (close_tag: name)
}
}
# lets generate some simple HTML output )
h = HTML new
h html: {
h body: {
[
h div: {
"hello, world!"
},
h div: {
h p: {
"OKIDOKI"
}
},
h div: {
h h3: {
"oh no!"
}
}
]
}
} . println