forked from ring-lang/ring
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbuild.ring
99 lines (91 loc) · 2.41 KB
/
build.ring
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
/*
Ring programming language - Simple Website Generator
Version 1.0
http://ring-lang.net
2016, Mahmoud Fayed <[email protected]>
*/
# Load the pages list from the pages.data file!
eval(read("pages.data"))
# Message after finishing an operation
C_DONE = "Done..." + nl
# The main function generate the HTML files using the aPages list
Func Main
about()
checkfile(C_HEADER) checkfile(C_FOOTER)
See "Reading header : " + C_HEADER + nl
cHeader = read(C_HEADER) + nl
See "Reading footer : " + C_FOOTER + nl
cFooter = read(C_FOOTER)
for x in aPages
checkfile(x)
createPage(cHeader,x,cFooter,
substr(x,".template",".html"))
next
See C_DONE
# the createPage function generate html file
# The function add the header and the footer to the content
Func createPage cHeader,cContent,cFooter,cOutput
See "Content File : " + cContent + nl
See "Add header..." + nl
cStr = cHeader
See "Add content..." + nl
cStr += template(cContent,NULL) + nl
See "Add Footer..." + nl
cStr += cFooter
See "Writing file : " + cOutput + nl
write(cOutput,cStr)
# The function check if the file exist or not before using it
Func checkfile cFileName
if not fexists(cFileName) raise("Error, File " + cFileName + " doesn't exist!") ok
# The function print the application information
Func about
See "
========================================================
Simple Website Generator
Version 1.0
http://ring-lang.net
2016, Mahmoud Fayed <[email protected]>
========================================================
"
# The function execute Ring code inside template files
# Then put the result/output from Ring code in the template content
Func Template cFile,oObject
cStr = Read(cFile)
aList = []
cResult = ""
cCode = ""
nPos = substr(cStr,"<%")
if nPos = 0
aList + cStr
cCode += "cResult += aList[" + len(aList) + "]" + nl
ok
while nPos > 0
cText = left(cStr,nPos-1)
if cText != ""
aList + cText
cCode += "cResult += aList[" + len(aList) + "]" + nl
ok
cStr = substr(cStr,nPos+2)
nPos = substr(cStr,"%>")
if nPos > 0
if left(cStr,1) = "="
cCode += "cResult += (" + substr(cStr,2,nPos-2) + ")" + nl
else
cCode += left(cStr,nPos-1) + nl
ok
cStr = substr(cStr,nPos+2)
ok
nPos = substr(cStr,"<%")
if nPos = 0
aList + cStr
cCode += "cResult += aList[" + len(aList) + "]" + nl
ok
end
if not isnull(oObject)
oObject {
eval(cCode)
}
else
eval(cCode)
ok
return cResult