From d7f48e55a84bd179e645bc272f3e408f5edbe958 Mon Sep 17 00:00:00 2001 From: metalwolf Date: Fri, 29 Sep 2023 13:35:12 -0500 Subject: [PATCH] patch v2.2.1 --- v2/README.md | 6 +++++- v2/xcore.go | 8 ++++---- v2/xtemplate.go | 8 ++++++++ v2/xtemplate_test.go | 21 +++++++++++++++++++++ 4 files changed, 38 insertions(+), 5 deletions(-) diff --git a/v2/README.md b/v2/README.md index 4e5accc..37cc17e 100644 --- a/v2/README.md +++ b/v2/README.md @@ -14,7 +14,7 @@ For GO, the actual existing code includes: - XLanguage: language dependent text tables, thread safe - XTemplate: template system with meta language, thread safe cloning -Manuals are available on godoc.org [![GoDoc](https://godoc.org/github.com/webability-go/xcore?status.png)](https://godoc.org/github.com/webability-go/xcore) +Manuals are available on godoc.org [![GoDoc](https://godoc.org/github.com/webability-go/xcore/v2?status.png)](https://godoc.org/github.com/webability-go/xcore/v2) TO DO, maybe: @@ -31,6 +31,10 @@ Some improvements to check, later: Version Changes Control ======================= +v2.2.1 - 2023-09-29 +----------------------- +- Added the missing sub template .none for ?? meta language into XTemplate. + v2.2.0 - 2023-08-31 ----------------------- - Added the parameter status to xlanguage XML and function to get/set the parameter. diff --git a/v2/xcore.go b/v2/xcore.go index 8371ec9..9913974 100644 --- a/v2/xcore.go +++ b/v2/xcore.go @@ -24,7 +24,7 @@ // // 1. Declare a new XCache with NewXCache() function: // -// import "github.com/webability-go/xcore" +// import "github.com/webability-go/xcore/v2" // // // 50 items max // var myfiles = xcore.NewXCache("myfiles", 50, 0) @@ -237,7 +237,7 @@ // // Example: // -// import "github.com/webability-go/xcore" +// import "github.com/webability-go/xcore/v2" // // data := xcore.XDataset{} // data["data1"] = "DATA1" @@ -384,7 +384,7 @@ // // import ( // "fmt" -// "github.com/webability-go/xcore" +// "github.com/webability-go/xcore/v2" // ) // // func main() { @@ -879,7 +879,7 @@ package xcore // VERSION is the used version nombre of the XCore library. -const VERSION = "2.2.0" +const VERSION = "2.2.1" // 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. diff --git a/v2/xtemplate.go b/v2/xtemplate.go index f9a5cd6..16a22c7 100644 --- a/v2/xtemplate.go +++ b/v2/xtemplate.go @@ -449,6 +449,14 @@ func (t *XTemplate) injector(datacol XDatasetCollectionDef, language *XLanguage) datacol.Pop() } } + if value == nil || fmt.Sprint(value) == "" { + tmp := t.GetTemplate(subtemplateid + ".none") + if tmp != nil { + subt = tmp + } + substr := subt.injector(datacol, language) + injected = append(injected, substr) + } case MetaDump: if datacol != nil { if v.Data == "dump" || v.Data == "list" { diff --git a/v2/xtemplate_test.go b/v2/xtemplate_test.go index 0a6ad7e..df084c7 100644 --- a/v2/xtemplate_test.go +++ b/v2/xtemplate_test.go @@ -69,6 +69,27 @@ I love nothing
// I love nothing
} +func TestNewXTemplateEmptyCondition(t *testing.T) { + tmpl, _ := NewXTemplateFromString(` +TAGADA +??familyname?? +[[familyname]] +Hello {{familyname}}
+[[]] +[[familyname.none]] +I don't know you
+[[]] +`) + // 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", + } + + fmt.Println(tmpl.Execute(&data)) + // Output: + // I don't know you
+} + func TestNewXTemplateNilCollection(t *testing.T) { tmpl, _ := NewXTemplateFromString(`