OSDN Git Service

【変更内容】
[ring-lang-081/ring.git] / website-obsoleted / build.ring
1 /*
2         Ring programming language - Simple Website Generator
3         Version 1.0
4         http://ring-lang.net
5         2016, Mahmoud Fayed <msfclipper@yahoo.com>
6         2018, isVowel
7 */
8
9 # Load the pages list from the pages.data file!
10 eval(read("pages.data"))
11
12 # Message after finishing an operation
13 C_DONE = "\8f\88\97\9d\8a®\97¹..." + nl
14
15 # The main function generate the HTML files using the aPages list
16 Func Main
17         about()
18         checkfile(C_HEADER) checkfile(C_FOOTER)
19         See "\83w\83b\83_\82Ì\93Ç\82Ý\8d\9e\82Ý : " + C_HEADER  + nl
20         cHeader = read(C_HEADER) + nl
21         See "\83t\83b\83^\82Ì\93Ç\82Ý\8d\9e\82Ý : " + C_FOOTER  + nl
22         cFooter = read(C_FOOTER)
23         for x in aPages 
24                 checkfile(x)
25                 createPage(cHeader,x,cFooter,
26                            substr(x,".template",".html"))
27         next
28         See C_DONE
29
30 # the createPage function generate html file 
31 # The function add the header and the footer to the content
32 Func createPage cHeader,cContent,cFooter,cOutput
33         See "\8bL\8e\96\83t\83@\83C\83\8b : " + cContent + nl
34         See "\83w\83b\83_\82ð\92Ç\89Á..." + nl
35         cStr = cHeader  
36         See "\93à\97e\82ð\92Ç\89Á..."  + nl
37         # Using template() then template2() to support using template() in the template file
38         # As we have in the download16.template
39         cContent = template(cContent,NULL)
40         cStr += template2(cContent,NULL) + nl
41         See "\83t\83b\83^\82ð\92Ç\89Á..." + nl
42         cStr += cFooter
43         See "\83t\83@\83C\83\8b\82ð\8fo\97Í : " + cOutput  + nl
44         write(cOutput,cStr)
45
46 # The function check if the file exist or not before using it
47 Func checkfile cFileName
48         if not fexists(cFileName) raise("Error, File " + cFileName + " doesn't exist!") ok
49
50 # The function print the application information
51 Func about
52         See "
53 ========================================================
54 Simple Website Generator - Version 1.0
55 2016, Mahmoud Fayed <msfclipper@yahoo.com>
56 2018, isVowel (Japanization)
57 ========================================================
58 "
59
60 # The function execute Ring code inside template files
61 # Then put the result/output from Ring code in the template content
62 Func Template cFile,oObject
63         ? "\83e\83\93\83v\83\8c\81[\83g\82ð\93W\8aJ\82µ\82Ä\82¢\82Ü\82·..."
64         cStr = Read(cFile)
65         return Template2(cStr,oObject)
66
67 Func Template2 cStr,oObject
68         aList = []
69         cResult = ""
70         cCode = ""
71         nPos = substr(cStr,"<%")
72         if nPos = 0
73                 aList + cStr
74                 cCode += "cResult += aList[" + len(aList) + "]" + nl
75         ok
76         while nPos > 0
77                 cText = left(cStr,nPos-1)
78                 if cText != ""
79                         aList + cText
80                         cCode += "cResult += aList[" + len(aList) + "]" + nl
81                 ok
82                 cStr = substr(cStr,nPos+2)
83                 nPos = substr(cStr,"%>")
84                 if nPos > 0                                     
85                         if left(cStr,1) = "="
86                                 cCode += "cResult += (" + substr(cStr,2,nPos-2) + ")" + nl      
87                         else
88                                 cCode += left(cStr,nPos-1) + nl                                         
89                         ok
90                         cStr = substr(cStr,nPos+2)
91                 ok
92                 nPos = substr(cStr,"<%")
93                 if nPos = 0
94                         aList + cStr
95                         cCode += "cResult += aList[" + len(aList) + "]" + nl
96                 ok
97         end
98         if not isnull(oObject)
99                 oObject { 
100                         eval(cCode)
101                 }
102         else
103                 eval(cCode)
104         ok
105         return cResult