mirror of
https://github.com/arnaucube/konstrui.git
synced 2026-02-07 03:26:43 +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
|
web templating engine for static websites, written in Go lang
|
||||||
|
|
||||||
|
|
||||||

|

|
||||||
|
|
||||||
|
|
||||||
## Example
|
## Example
|
||||||
@@ -12,6 +12,7 @@ web templating engine for static websites, written in Go lang
|
|||||||
|
|
||||||
```
|
```
|
||||||
webInput/
|
webInput/
|
||||||
|
konstruiConfig.json
|
||||||
index.html
|
index.html
|
||||||
templates/
|
templates/
|
||||||
userTemplate.html
|
userTemplate.html
|
||||||
@@ -29,7 +30,7 @@ webInput/
|
|||||||
|
|
||||||
<p>My first paragraph.</p>
|
<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>
|
</body>
|
||||||
</html>
|
</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
|
```json
|
||||||
{
|
{
|
||||||
@@ -85,10 +86,10 @@ webInput/
|
|||||||
```
|
```
|
||||||
|
|
||||||
|
|
||||||
- Execute Timmy
|
- Execute konstrui
|
||||||
|
|
||||||
```
|
```
|
||||||
./timmy
|
./konstrui
|
||||||
```
|
```
|
||||||
|
|
||||||
- Output:
|
- Output:
|
||||||
|
|||||||
@@ -59,8 +59,8 @@ func generateFromTemplateAndData(templateContent string, entries []dataEntry) st
|
|||||||
func getTemplateParameters(line string) (string, string) {
|
func getTemplateParameters(line string) (string, string) {
|
||||||
var templatePath string
|
var templatePath string
|
||||||
var data string
|
var data string
|
||||||
line = strings.Replace(line, "<timmy-template ", "", -1)
|
line = strings.Replace(line, "<konstrui-template ", "", -1)
|
||||||
line = strings.Replace(line, "></timmy-template>", "", -1)
|
line = strings.Replace(line, "></konstrui-template>", "", -1)
|
||||||
attributes := strings.Split(line, " ")
|
attributes := strings.Split(line, " ")
|
||||||
//fmt.Println(attributes)
|
//fmt.Println(attributes)
|
||||||
for i := 0; i < len(attributes); i++ {
|
for i := 0; i < len(attributes); i++ {
|
||||||
@@ -90,7 +90,7 @@ func putTemplates(folderPath string, filename string) string {
|
|||||||
lineCount := 1
|
lineCount := 1
|
||||||
for scanner.Scan() {
|
for scanner.Scan() {
|
||||||
currentLine := scanner.Text()
|
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)
|
templatePath, data := getTemplateParameters(currentLine)
|
||||||
fileContent = fileContent + useTemplate(templatePath, data)
|
fileContent = fileContent + useTemplate(templatePath, data)
|
||||||
} else {
|
} 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 rawFolderPath = "./webInput"
|
||||||
const newFolderPath = "./webOutput"
|
const newFolderPath = "./webOutput"
|
||||||
const timmyConfigFile = "timmyConfig.json"
|
const konstruiConfigFile = "konstruiConfig.json"
|
||||||
|
|
||||||
func parseDir(folderPath string, newDir string) {
|
func parseDir(folderPath string, newDir string) {
|
||||||
files, _ := ioutil.ReadDir(folderPath)
|
files, _ := ioutil.ReadDir(folderPath)
|
||||||
@@ -34,8 +34,8 @@ func parseDir(folderPath string, newDir string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
func startTemplating(folderPath string, newDir string) {
|
func startTemplating(folderPath string, newDir string) {
|
||||||
for i := 0; i < len(timmyConfig.Files); i++ {
|
for i := 0; i < len(konstruiConfig.Files); i++ {
|
||||||
fName := timmyConfig.Files[i]
|
fName := konstruiConfig.Files[i]
|
||||||
fileNameSplitted := strings.Split(fName, ".")
|
fileNameSplitted := strings.Split(fName, ".")
|
||||||
extension := fileNameSplitted[len(fileNameSplitted)-1]
|
extension := fileNameSplitted[len(fileNameSplitted)-1]
|
||||||
if extension == "html" {
|
if extension == "html" {
|
||||||
@@ -49,10 +49,10 @@ func startTemplating(folderPath string, newDir string) {
|
|||||||
}
|
}
|
||||||
func main() {
|
func main() {
|
||||||
c.Green("getting files from /webInput")
|
c.Green("getting files from /webInput")
|
||||||
c.Green("getting conifg from file timmyConfig.json")
|
c.Green("getting conifg from file konstruiConfig.json")
|
||||||
readTimmyConfig(rawFolderPath + "/" + timmyConfigFile)
|
readKonstruiConfig(rawFolderPath + "/" + konstruiConfigFile)
|
||||||
c.Green("configuration:")
|
c.Green("configuration:")
|
||||||
fmt.Println(timmyConfig.Files)
|
fmt.Println(konstruiConfig.Files)
|
||||||
c.Green("templating")
|
c.Green("templating")
|
||||||
//parseDir(rawFolderPath, newFolderPath)
|
//parseDir(rawFolderPath, newFolderPath)
|
||||||
startTemplating(rawFolderPath, newFolderPath)
|
startTemplating(rawFolderPath, newFolderPath)
|
||||||
|
|||||||
@@ -6,8 +6,8 @@ import (
|
|||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
//TimmyConfig is the configuration from the file timmyConfig.json, on the folder /webInput
|
//KonstruiConfig is the configuration from the file konstruiConfig.json, on the folder /webInput
|
||||||
type TimmyConfig struct {
|
type KonstruiConfig struct {
|
||||||
Title string `json:"title"`
|
Title string `json:"title"`
|
||||||
Author string `json:"author"`
|
Author string `json:"author"`
|
||||||
Github string `json:"github"`
|
Github string `json:"github"`
|
||||||
@@ -15,13 +15,13 @@ type TimmyConfig struct {
|
|||||||
Files []string `json:"files"`
|
Files []string `json:"files"`
|
||||||
}
|
}
|
||||||
|
|
||||||
var timmyConfig TimmyConfig
|
var konstruiConfig KonstruiConfig
|
||||||
|
|
||||||
func readTimmyConfig(path string) {
|
func readKonstruiConfig(path string) {
|
||||||
file, e := ioutil.ReadFile(path)
|
file, e := ioutil.ReadFile(path)
|
||||||
if e != nil {
|
if e != nil {
|
||||||
fmt.Println("error:", e)
|
fmt.Println("error:", e)
|
||||||
}
|
}
|
||||||
content := string(file)
|
content := string(file)
|
||||||
json.Unmarshal([]byte(content), &timmyConfig)
|
json.Unmarshal([]byte(content), &konstruiConfig)
|
||||||
}
|
}
|
||||||
Reference in New Issue
Block a user