mirror of
https://github.com/arnaucube/konstrui.git
synced 2026-02-07 11:36:40 +01:00
implemented konstruiRepeatElem, need to repeat multi repeat
This commit is contained in:
@@ -66,8 +66,8 @@ func jsonGabs(path string) *gabs.Container {
|
|||||||
file, err := ioutil.ReadFile(path)
|
file, err := ioutil.ReadFile(path)
|
||||||
check(err)
|
check(err)
|
||||||
jsonParsed, err := gabs.ParseJSON(file)
|
jsonParsed, err := gabs.ParseJSON(file)
|
||||||
img := "img"
|
//img := "img"
|
||||||
fmt.Println(jsonParsed.S(img))
|
//fmt.Println(jsonParsed.S(img))
|
||||||
return jsonParsed
|
return jsonParsed
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Jeffail/gabs"
|
"github.com/Jeffail/gabs"
|
||||||
"github.com/fatih/color"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
func duplicateText(original string, count int) string {
|
func duplicateText(original string, count int) string {
|
||||||
@@ -39,15 +38,13 @@ func replaceEntryOLD(templateContent string, entry dataEntry, jsonData *gabs.Con
|
|||||||
return templateContent
|
return templateContent
|
||||||
}
|
}
|
||||||
func replaceEntry(templateContent string, entry dataEntry, jsonData *gabs.Container, elemName string) string {
|
func replaceEntry(templateContent string, entry dataEntry, jsonData *gabs.Container, elemName string) string {
|
||||||
fmt.Println(jsonData)
|
//fmt.Println(jsonData)
|
||||||
children, _ := jsonData.S().ChildrenMap()
|
children, _ := jsonData.S().ChildrenMap()
|
||||||
//_, ok := jsonData.S().Children()
|
//_, ok := jsonData.S().Children()
|
||||||
color.Green("AAAAAAAAAA")
|
|
||||||
for parameter, child := range children {
|
for parameter, child := range children {
|
||||||
//subchildren, _ := child.S().ChildrenMap()
|
//subchildren, _ := child.S().ChildrenMap()
|
||||||
_, ok := child.S().Children()
|
_, ok := child.S().Children()
|
||||||
if ok != nil {
|
if ok != nil {
|
||||||
color.Blue(child.Data().(string))
|
|
||||||
templateContent = strings.Replace(templateContent, "{{"+parameter+"}}", child.Data().(string), -1)
|
templateContent = strings.Replace(templateContent, "{{"+parameter+"}}", child.Data().(string), -1)
|
||||||
} else {
|
} else {
|
||||||
/*for subparameter, subchild := range subchildren {
|
/*for subparameter, subchild := range subchildren {
|
||||||
@@ -76,7 +73,6 @@ func konstruiRepeatJSONPartTwo(templateContent string, entries []dataEntry, json
|
|||||||
children, _ := jsonData.S().Children()
|
children, _ := jsonData.S().Children()
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
var entry dataEntry
|
var entry dataEntry
|
||||||
color.Red("BBBBB")
|
|
||||||
replaced = replaced + replaceEntry(extracted, entry, child, elemName)
|
replaced = replaced + replaceEntry(extracted, entry, child, elemName)
|
||||||
}
|
}
|
||||||
fragmentLines := getLines(replaced)
|
fragmentLines := getLines(replaced)
|
||||||
@@ -103,18 +99,43 @@ func konstruiRepeatJSON(templateContent string) string {
|
|||||||
func konstruiRepeatElem(templateContent string, entry dataEntry, jsonData *gabs.Container) string {
|
func konstruiRepeatElem(templateContent string, entry dataEntry, jsonData *gabs.Container) string {
|
||||||
if strings.Contains(templateContent, "<konstrui-repeatElem") {
|
if strings.Contains(templateContent, "<konstrui-repeatElem") {
|
||||||
elemName, _ := getTagParameters(templateContent, "konstrui-repeatElem", "repeatElem", "nil")
|
elemName, _ := getTagParameters(templateContent, "konstrui-repeatElem", "repeatElem", "nil")
|
||||||
color.Red(elemName)
|
//elemEntries := getElemFromObj(entry, elemName)
|
||||||
elemEntries := getElemFromObj(entry, elemName)
|
//templateContent = konstruiRepeatJSONPartTwo(templateContent, elemEntries, jsonData, elemName)
|
||||||
templateContent = konstruiRepeatJSONPartTwo(templateContent, elemEntries, jsonData, elemName)
|
extracted := extractText(templateContent, "<konstrui-repeatElem", "</konstrui-repeatElem>")
|
||||||
|
children, _ := jsonData.S(elemName).Children()
|
||||||
|
/*for _, child := range children {
|
||||||
|
//var entry dataEntry
|
||||||
|
fmt.Println(child)
|
||||||
|
//replaced = replaced + replaceEntry(extracted, entry, child, elemName)
|
||||||
|
replaced = replaced + extracted
|
||||||
|
}*/
|
||||||
|
fragmentLines := getLines(extracted)
|
||||||
|
fragmentLines = deleteArrayElementsWithString(fragmentLines, "konstrui-repeatElem")
|
||||||
|
f := concatStringsWithJumps(fragmentLines)
|
||||||
|
|
||||||
|
var replaced string
|
||||||
|
for _, child := range children {
|
||||||
|
replacedElem := strings.Replace(f, "{{"+elemName+"}}", child.Data().(string), -1)
|
||||||
|
replaced = replaced + replacedElem
|
||||||
|
}
|
||||||
|
fragmentLines = getLines(replaced)
|
||||||
|
|
||||||
|
lines := getLines(templateContent)
|
||||||
|
p := locateStringInArray(lines, "konstrui-repeatElem")
|
||||||
|
lines = deleteLinesBetween(lines, p[0], p[1])
|
||||||
|
lines = addElementsToArrayPosition(lines, fragmentLines, p[0])
|
||||||
|
templateContent = concatStringsWithJumps(lines)
|
||||||
|
|
||||||
}
|
}
|
||||||
return templateContent
|
return templateContent
|
||||||
}
|
}
|
||||||
func getElemFromObj(entry dataEntry, elemName string) []dataEntry {
|
|
||||||
|
/*func getElemFromObj(entry dataEntry, elemName string) []dataEntry {
|
||||||
var elemEntries []dataEntry
|
var elemEntries []dataEntry
|
||||||
fmt.Println(elemName)
|
fmt.Println(elemName)
|
||||||
fmt.Println(entry)
|
fmt.Println(entry)
|
||||||
return elemEntries
|
return elemEntries
|
||||||
}
|
}*/
|
||||||
func konstruiSimpleVars(template string, entries []dataEntry, jsonData *gabs.Container) string {
|
func konstruiSimpleVars(template string, entries []dataEntry, jsonData *gabs.Container) string {
|
||||||
//now, replace simple templating variables {{vars}}
|
//now, replace simple templating variables {{vars}}
|
||||||
/*for _, entry := range entries {
|
/*for _, entry := range entries {
|
||||||
|
|||||||
Reference in New Issue
Block a user