Skip to content

Commit

Permalink
Merge pull request #71 from webability-go/late-night
Browse files Browse the repository at this point in the history
patch v2.1.4
  • Loading branch information
metalwolf committed May 17, 2023
2 parents 2b9a8d6 + 19a145b commit d8798a1
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 2 deletions.
4 changes: 4 additions & 0 deletions v2/README.md
Expand Up @@ -33,6 +33,10 @@ Some improvements to check, later:
Version Changes Control
=======================

v2.1.4 - 2023-05-17
-----------------------
- Bug corrected on @@ loops subtemplates, the .none template was not reach when the array is set but empty

v2.1.3 - 2022-09-02
-----------------------
- Bug corrected on XDataset.GetString() and XDatasetCollection.GetDataString().
Expand Down
2 changes: 1 addition & 1 deletion v2/xcore.go
Expand Up @@ -868,7 +868,7 @@
package xcore

// VERSION is the used version nombre of the XCore library.
const VERSION = "2.1.3"
const VERSION = "2.1.4"

// LOG is the flag to activate logging on the library.
// if LOG is set to TRUE, LOG indicates to the XCore libraries to log a trace of functions called, with most important parameters.
Expand Down
2 changes: 1 addition & 1 deletion v2/xtemplate.go
Expand Up @@ -375,7 +375,7 @@ func (t *XTemplate) injector(datacol XDatasetCollectionDef, language *XLanguage)
if subt != nil {
if datacol != nil {
cl, _ := datacol.GetCollection(subdataid)
if cl != nil {
if cl != nil && cl.Count() > 0 {
for i := 0; i < cl.Count(); i++ {
var tmp *XTemplate
tmp = t.GetTemplate(subtemplateid + ".key." + strconv.Itoa(i))
Expand Down
28 changes: 28 additions & 0 deletions v2/xtemplate_test.go
Expand Up @@ -41,6 +41,34 @@ I love {{name}}<br />
// I love Videogames<br />
}

func ExampleNewXTemplateEmptyLoop() {
tmpl, _ := NewXTemplateFromString(`
%-- This is a comment. It will not appear in the final code. --%
Let's put your name here: {{clientname}}<br />
And lets put your hobbies here:<br />
%-- note the 1rst id is the entry into the data to inject and the second one is the name of the sub-template to use --%
@@hobbies@@
%-- And you need the template for each hobby:--%
[[hobbies]]
I love {{name}}<br />
[[]]
[[hobbies.none]]
I love nothing<br />
[[]]
`)
// The creation of the data is obviously tedious here, in real life it should come from a JSON, a Database, etc
data := XDataset{
"clientname": "Fred",
"hobbies": &XDatasetCollection{},
}

fmt.Println(tmpl.Execute(&data))
// Output:
// Let's put your name here: Fred<br />
// And lets put your hobbies here:<br />
// I love nothing<br />
}

func TestNewXTemplateFromString(t *testing.T) {
tmpl, _ := NewXTemplateFromString(`
%-- This is a comment. It will not appear in the final code. --%
Expand Down

0 comments on commit d8798a1

Please sign in to comment.