arnaucube
arnaucube/konstruiPublic Self-hosted repository
renamed to konstrui
arnaucode idoctnef@openmailbox.org
Mon, 22 May 2017 21:45:48 +0200
commit

08b773e666803884cb408d12f4071355ae61e028

parent

11f2b576a5bce3abb81ba35a33c77b44021c6413

8 files changed, 43 insertions(+), 42 deletions(-)

jump to
M README.md → README.md

@@ -1,9 +1,9 @@

-# Timmy [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucode/timmy)](https://goreportcard.com/report/github.com/arnaucode/timmy) +# Konstrui [![Go Report Card](https://goreportcard.com/badge/github.com/arnaucode/konstrui)](https://goreportcard.com/report/github.com/arnaucode/konstrui) web templating engine for static websites, written in Go lang -![timmy](https://raw.githubusercontent.com/arnaucode/timmy/master/timmy.png "timmy") +![konstrui](https://raw.githubusercontent.com/arnaucode/konstrui/master/konstrui.png "konstrui") ## Example

@@ -12,6 +12,7 @@ - Simple project structure example:

``` webInput/ + konstruiConfig.json index.html templates/ userTemplate.html

@@ -29,7 +30,7 @@ <h1>My First Heading</h1>

<p>My first paragraph.</p> -<timmy-template html="templates/userTemplate.html" data="templates/userTemplate.json"></timmy-template> +<konstrui-template html="templates/userTemplate.html" data="templates/userTemplate.json"></konstrui-template> </body> </html>

@@ -68,7 +69,7 @@ }

] ``` -- Set the configuration file timmyConfig.json in the webInput directory: +- Set the configuration file konstruiConfig.json in the webInput directory: ```json {

@@ -85,10 +86,10 @@ }

``` -- Execute Timmy +- Execute konstrui ``` -./timmy +./konstrui ``` - Output:
M fileOperations.go → fileOperations.go

@@ -59,8 +59,8 @@ }

func getTemplateParameters(line string) (string, string) { var templatePath string var data string - line = strings.Replace(line, "<timmy-template ", "", -1) - line = strings.Replace(line, "></timmy-template>", "", -1) + line = strings.Replace(line, "<konstrui-template ", "", -1) + line = strings.Replace(line, "></konstrui-template>", "", -1) attributes := strings.Split(line, " ") //fmt.Println(attributes) for i := 0; i < len(attributes); i++ {

@@ -90,7 +90,7 @@ scanner := bufio.NewScanner(f)

lineCount := 1 for scanner.Scan() { currentLine := scanner.Text() - if strings.Contains(currentLine, "<timmy-template") && strings.Contains(currentLine, "</timmy-template>") { + if strings.Contains(currentLine, "<konstrui-template") && strings.Contains(currentLine, "</konstrui-template>") { templatePath, data := getTemplateParameters(currentLine) fileContent = fileContent + useTemplate(templatePath, data) } else {
M main.go → main.go

@@ -9,7 +9,7 @@ )

const rawFolderPath = "./webInput" const newFolderPath = "./webOutput" -const timmyConfigFile = "timmyConfig.json" +const konstruiConfigFile = "konstruiConfig.json" func parseDir(folderPath string, newDir string) { files, _ := ioutil.ReadDir(folderPath)

@@ -34,8 +34,8 @@ }

} } func startTemplating(folderPath string, newDir string) { - for i := 0; i < len(timmyConfig.Files); i++ { - fName := timmyConfig.Files[i] + for i := 0; i < len(konstruiConfig.Files); i++ { + fName := konstruiConfig.Files[i] fileNameSplitted := strings.Split(fName, ".") extension := fileNameSplitted[len(fileNameSplitted)-1] if extension == "html" {

@@ -49,10 +49,10 @@ }

} func main() { c.Green("getting files from /webInput") - c.Green("getting conifg from file timmyConfig.json") - readTimmyConfig(rawFolderPath + "/" + timmyConfigFile) + c.Green("getting conifg from file konstruiConfig.json") + readKonstruiConfig(rawFolderPath + "/" + konstruiConfigFile) c.Green("configuration:") - fmt.Println(timmyConfig.Files) + fmt.Println(konstruiConfig.Files) c.Green("templating") //parseDir(rawFolderPath, newFolderPath) startTemplating(rawFolderPath, newFolderPath)
A readKonstruiConfig.go

@@ -0,0 +1,27 @@

+package main + +import ( + "encoding/json" + "fmt" + "io/ioutil" +) + +//KonstruiConfig is the configuration from the file konstruiConfig.json, on the folder /webInput +type KonstruiConfig struct { + Title string `json:"title"` + Author string `json:"author"` + Github string `json:"github"` + Website string `json:"website"` + Files []string `json:"files"` +} + +var konstruiConfig KonstruiConfig + +func readKonstruiConfig(path string) { + file, e := ioutil.ReadFile(path) + if e != nil { + fmt.Println("error:", e) + } + content := string(file) + json.Unmarshal([]byte(content), &konstruiConfig) +}
D readTimmyConfig.go

@@ -1,27 +0,0 @@

-package main - -import ( - "encoding/json" - "fmt" - "io/ioutil" -) - -//TimmyConfig is the configuration from the file timmyConfig.json, on the folder /webInput -type TimmyConfig struct { - Title string `json:"title"` - Author string `json:"author"` - Github string `json:"github"` - Website string `json:"website"` - Files []string `json:"files"` -} - -var timmyConfig TimmyConfig - -func readTimmyConfig(path string) { - file, e := ioutil.ReadFile(path) - if e != nil { - fmt.Println("error:", e) - } - content := string(file) - json.Unmarshal([]byte(content), &timmyConfig) -}
D timmy