-
Notifications
You must be signed in to change notification settings - Fork 0
/
web.r
executable file
·122 lines (107 loc) · 2.94 KB
/
web.r
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
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
REBOL [
Title: "Web Library"
About: "A library for web pages."
Version: 0.1
Creator: "Andy"
]
sanitizeString: func [ str ] [
newstr: ""
clear newstr
foreach os str [
temp: os
switch temp [
"&" [ temp: "&" ]
"'" [ temp: "'" ]
{"} [ temp: """ ]
append newstr temp
]
]
get newstr
]
makeAttribs: func [ atts ] [
full: ""
clear full
if (even? length? atts) and (block? atts) and (not zero? length? atts) [
count: 0
att: ""
clear att
foreach el atts [
either zero? count [
count: 1
att: join " " el
] [
count: 0
append full join att [{="} either word? el [ get el ] [ el ] {"}]
]
]
]
return full
]
makeTag: func [ tag attList ] [
newtag: ""
clear newtag
newtag: tag
if not zero? length? attList [ append newtag makeAttribs attList ]
clear attList
return newtag
]
makeOpenTag: func [ tagOpen /attributes attribs ] [
join "<" [makeTag tagOpen either attributes [ attribs ] [ [] ] ">"]
]
makeSingleTag: func [tagOpen /attributes attribs ] [
join "<" [makeTag tagOpen either attributes [ attribs ] [ [] ] " />"]
]
makeCloseTag: func [tagClose] [
join "</" [tagClose ">"]
]
makeLink: func [linkText link] [
join makeOpenTag/attributes "a" [{href} link] [linkText makeCloseTag "a"]
]
makeImage: func [ src /alt altText ] [
alt-text: ""
clear alt-text
alt-text: either alt [ altText ] [ src ]
makeSingleTag/attributes "img" [{src} src {alt} alt-text]
]
headTag: func [ titleText ] [
title: ""
clear title
title: join makeOpenTag "title" [titleText makeCloseTag "title"]
join (makeOpenTag/attributes "head" [{lang} {en}]) [title makeCloseTag "head"]
]
generalTag: func [ type tagText attribs ] [
either not zero? length? attribs [
join makeOpenTag/attributes type attribs [tagText (makeCloseTag type)]
] [
join makeOpenTag type [tagText (makeCloseTag type)]
]
]
pTag: func[ pText /style pAttribs ] [
either style [ generalTag "p" pText [{style} pAttribs] ] [ generalTag "p" pText [] ]
]
h1Tag: func[ h1Text /style h1Attribs ] [
either style [ generalTag "h1" h1Text [{style} h1Attribs] ] [ generalTag "h1" h1Text [] ]
]
listItem: func [item] [
switch/default to-string (type? item) [
"block" [
either (length? item) > 1 [
join (listItem item/1) (ulTag skip item 1)
] [
listItem item/1
]
]
"word" [ get item ]
"string" [ item ]
] [ to-string item ]
]
ulTag: func [ list ] [
generalTag "ul" (liTag list) []
]
liTag: func [ list ] [
either (length? list) > 1 [
join (generalTag "li" (listItem list/1) []) (liTag skip list 1)
] [
generalTag "li" (listItem list/1) []
]
]