mirror of
https://github.com/arnaucube/konstrui.git
synced 2026-02-07 03:26:43 +01:00
multi repeatElem
This commit is contained in:
@@ -1,6 +1,7 @@
|
|||||||
package main
|
package main
|
||||||
|
|
||||||
import (
|
import (
|
||||||
|
"fmt"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/Jeffail/gabs"
|
"github.com/Jeffail/gabs"
|
||||||
@@ -96,8 +97,11 @@ func konstruiRepeatJSON(templateContent string) string {
|
|||||||
return templateContent
|
return templateContent
|
||||||
}
|
}
|
||||||
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") {
|
for strings.Contains(templateContent, "<konstrui-repeatElem") {
|
||||||
elemName, _ := getTagParameters(templateContent, "konstrui-repeatElem", "repeatElem", "nil")
|
tlines := getLines(templateContent)
|
||||||
|
tp := locateStringInArray(tlines, "konstrui-repeatElem")
|
||||||
|
elemName, _ := getTagParameters(tlines[tp[0]], "konstrui-repeatElem", "repeatElem", "nil")
|
||||||
|
|
||||||
extracted := extractText(templateContent, "<konstrui-repeatElem", "</konstrui-repeatElem>")
|
extracted := extractText(templateContent, "<konstrui-repeatElem", "</konstrui-repeatElem>")
|
||||||
fragmentLines := getLines(extracted)
|
fragmentLines := getLines(extracted)
|
||||||
fragmentLines = deleteArrayElementsWithString(fragmentLines, "konstrui-repeatElem")
|
fragmentLines = deleteArrayElementsWithString(fragmentLines, "konstrui-repeatElem")
|
||||||
@@ -105,18 +109,19 @@ func konstruiRepeatElem(templateContent string, entry dataEntry, jsonData *gabs.
|
|||||||
children, _ := jsonData.S(elemName).Children()
|
children, _ := jsonData.S(elemName).Children()
|
||||||
var replaced string
|
var replaced string
|
||||||
for _, child := range children {
|
for _, child := range children {
|
||||||
//fmt.Println(child.Data().(string))
|
fmt.Println(child)
|
||||||
|
fmt.Println(child.Data().(string))
|
||||||
replacedElem := strings.Replace(f, "{{"+elemName+"}}", child.Data().(string), -1)
|
replacedElem := strings.Replace(f, "{{"+elemName+"}}", child.Data().(string), -1)
|
||||||
replaced = replaced + replacedElem
|
replaced = replaced + replacedElem
|
||||||
}
|
}
|
||||||
fragmentLines = getLines(replaced)
|
fragmentLines = getLines(replaced)
|
||||||
|
fmt.Println(replaced)
|
||||||
|
|
||||||
lines := getLines(templateContent)
|
/*lines := getLines(templateContent)
|
||||||
p := locateStringInArray(lines, "konstrui-repeatElem")
|
p := locateStringInArray(lines, "konstrui-repeatElem")*/
|
||||||
lines = deleteLinesBetween(lines, p[0], p[1])
|
tlines = deleteLinesBetween(tlines, tp[0], tp[1])
|
||||||
lines = addElementsToArrayPosition(lines, fragmentLines, p[0])
|
tlines = addElementsToArrayPosition(tlines, fragmentLines, tp[0])
|
||||||
templateContent = concatStringsWithJumps(lines)
|
templateContent = concatStringsWithJumps(tlines)
|
||||||
|
|
||||||
}
|
}
|
||||||
return templateContent
|
return templateContent
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user