OSDN Git Service

【変更内容】
[ring-lang-081/ring.git] / website-obsoleted / build.ring
diff --git a/website-obsoleted/build.ring b/website-obsoleted/build.ring
new file mode 100644 (file)
index 0000000..ff77225
--- /dev/null
@@ -0,0 +1,105 @@
+/*
+       Ring programming language - Simple Website Generator
+       Version 1.0
+       http://ring-lang.net
+       2016, Mahmoud Fayed <msfclipper@yahoo.com>
+       2018, isVowel
+*/
+
+# Load the pages list from the pages.data file!
+eval(read("pages.data"))
+
+# Message after finishing an operation
+C_DONE = "\8f\88\97\9d\8a®\97¹..." + nl
+
+# The main function generate the HTML files using the aPages list
+Func Main
+       about()
+       checkfile(C_HEADER) checkfile(C_FOOTER)
+       See "\83w\83b\83_\82Ì\93Ç\82Ý\8d\9e\82Ý : " + C_HEADER  + nl
+       cHeader = read(C_HEADER) + nl
+       See "\83t\83b\83^\82Ì\93Ç\82Ý\8d\9e\82Ý : " + 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 "\8bL\8e\96\83t\83@\83C\83\8b : " + cContent + nl
+       See "\83w\83b\83_\82ð\92Ç\89Á..." + nl
+       cStr = cHeader  
+       See "\93à\97e\82ð\92Ç\89Á..."  + nl
+       # Using template() then template2() to support using template() in the template file
+       # As we have in the download16.template
+       cContent = template(cContent,NULL)
+       cStr += template2(cContent,NULL) + nl
+       See "\83t\83b\83^\82ð\92Ç\89Á..." + nl
+       cStr += cFooter
+       See "\83t\83@\83C\83\8b\82ð\8fo\97Í : " + 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
+2016, Mahmoud Fayed <msfclipper@yahoo.com>
+2018, isVowel (Japanization)
+========================================================
+"
+
+# The function execute Ring code inside template files
+# Then put the result/output from Ring code in the template content
+Func Template cFile,oObject
+       ? "\83e\83\93\83v\83\8c\81[\83g\82ð\93W\8aJ\82µ\82Ä\82¢\82Ü\82·..."
+       cStr = Read(cFile)
+       return Template2(cStr,oObject)
+
+Func Template2 cStr,oObject
+       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