Browse Source

renamed to konstrui

master
arnaucode 7 years ago
parent
commit
08b773e666
7 changed files with 21 additions and 20 deletions
  1. +7
    -6
      README.md
  2. +3
    -3
      fileOperations.go
  3. BIN
      konstrui
  4. +0
    -0
      konstrui.png
  5. +6
    -6
      main.go
  6. +5
    -5
      readKonstruiConfig.go
  7. BIN
      timmy

+ 7
- 6
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 @@ web templating engine for static websites, written in Go lang
```
webInput/
konstruiConfig.json
index.html
templates/
userTemplate.html
@ -29,7 +30,7 @@ webInput/
<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 @@ webInput/
]
```
- 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 @@ webInput/
```
- Execute Timmy
- Execute konstrui
```
./timmy
./konstrui
```
- Output:

+ 3
- 3
fileOperations.go

@ -59,8 +59,8 @@ func generateFromTemplateAndData(templateContent string, entries []dataEntry) st
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 @@ func putTemplates(folderPath string, filename string) string {
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 {

BIN
konstrui


timmy.png → konstrui.png


+ 6
- 6
main.go

@ -9,7 +9,7 @@ import (
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 parseDir(folderPath string, newDir string) {
}
}
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 startTemplating(folderPath string, newDir string) {
}
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)

readTimmyConfig.go → readKonstruiConfig.go

@ -6,8 +6,8 @@ import (
"io/ioutil"
)
//TimmyConfig is the configuration from the file timmyConfig.json, on the folder /webInput
type TimmyConfig struct {
//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"`
@ -15,13 +15,13 @@ type TimmyConfig struct {
Files []string `json:"files"`
}
var timmyConfig TimmyConfig
var konstruiConfig KonstruiConfig
func readTimmyConfig(path string) {
func readKonstruiConfig(path string) {
file, e := ioutil.ReadFile(path)
if e != nil {
fmt.Println("error:", e)
}
content := string(file)
json.Unmarshal([]byte(content), &timmyConfig)
json.Unmarshal([]byte(content), &konstruiConfig)
}

BIN
timmy


Loading…
Cancel
Save