Browse Source

implemented konstruiRepeatElem, need to repeat multi repeat

master
arnaucode 7 years ago
parent
commit
484d84ce63
2 changed files with 33 additions and 12 deletions
  1. +2
    -2
      fileOperations.go
  2. +31
    -10
      templating.go

+ 2
- 2
fileOperations.go

@ -66,8 +66,8 @@ func jsonGabs(path string) *gabs.Container {
file, err := ioutil.ReadFile(path)
check(err)
jsonParsed, err := gabs.ParseJSON(file)
img := "img"
fmt.Println(jsonParsed.S(img))
//img := "img"
//fmt.Println(jsonParsed.S(img))
return jsonParsed
}

+ 31
- 10
templating.go

@ -6,7 +6,6 @@ import (
"strings"
"github.com/Jeffail/gabs"
"github.com/fatih/color"
)
func duplicateText(original string, count int) string {
@ -39,15 +38,13 @@ func replaceEntryOLD(templateContent string, entry dataEntry, jsonData *gabs.Con
return templateContent
}
func replaceEntry(templateContent string, entry dataEntry, jsonData *gabs.Container, elemName string) string {
fmt.Println(jsonData)
//fmt.Println(jsonData)
children, _ := jsonData.S().ChildrenMap()
//_, ok := jsonData.S().Children()
color.Green("AAAAAAAAAA")
for parameter, child := range children {
//subchildren, _ := child.S().ChildrenMap()
_, ok := child.S().Children()
if ok != nil {
color.Blue(child.Data().(string))
templateContent = strings.Replace(templateContent, "{{"+parameter+"}}", child.Data().(string), -1)
} else {
/*for subparameter, subchild := range subchildren {
@ -76,7 +73,6 @@ func konstruiRepeatJSONPartTwo(templateContent string, entries []dataEntry, json
children, _ := jsonData.S().Children()
for _, child := range children {
var entry dataEntry
color.Red("BBBBB")
replaced = replaced + replaceEntry(extracted, entry, child, elemName)
}
fragmentLines := getLines(replaced)
@ -103,18 +99,43 @@ func konstruiRepeatJSON(templateContent string) string {
func konstruiRepeatElem(templateContent string, entry dataEntry, jsonData *gabs.Container) string {
if strings.Contains(templateContent, "<konstrui-repeatElem") {
elemName, _ := getTagParameters(templateContent, "konstrui-repeatElem", "repeatElem", "nil")
color.Red(elemName)
elemEntries := getElemFromObj(entry, elemName)
templateContent = konstruiRepeatJSONPartTwo(templateContent, elemEntries, jsonData, elemName)
//elemEntries := getElemFromObj(entry, 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
}
func getElemFromObj(entry dataEntry, elemName string) []dataEntry {
/*func getElemFromObj(entry dataEntry, elemName string) []dataEntry {
var elemEntries []dataEntry
fmt.Println(elemName)
fmt.Println(entry)
return elemEntries
}
}*/
func konstruiSimpleVars(template string, entries []dataEntry, jsonData *gabs.Container) string {
//now, replace simple templating variables {{vars}}
/*for _, entry := range entries {

Loading…
Cancel
Save