mirror of
https://github.com/arnaucube/konstrui.git
synced 2026-02-06 19:16:41 +01:00
renamed to konstrui
This commit is contained in:
13
README.md
13
README.md
@@ -1,9 +1,9 @@
|
||||
# Timmy [](https://goreportcard.com/report/github.com/arnaucode/timmy)
|
||||
# Konstrui [](https://goreportcard.com/report/github.com/arnaucode/konstrui)
|
||||
|
||||
web templating engine for static websites, written in Go lang
|
||||
|
||||
|
||||

|
||||

|
||||
|
||||
|
||||
## 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:
|
||||
|
||||
@@ -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 {
|
||||
|
||||
|
Before Width: | Height: | Size: 72 KiB After Width: | Height: | Size: 72 KiB |
12
main.go
12
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)
|
||||
|
||||
@@ -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)
|
||||
}
|
||||
Reference in New Issue
Block a user