Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Dt 7256 ignored razor expressions environment variable only works from command line #264

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
157 changes: 157 additions & 0 deletions .cspell.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,157 @@
{
"ignoreWords": [
"abaabaaa",
"abaabaaabaaaa",
jocgir marked this conversation as resolved.
Show resolved Hide resolved
"abbrevboth",
"acarl",
"acosh",
"addf",
"addins",
"adipiscing",
"afterwhile",
"aindent",
"aliqua",
"amet",
"araneae",
"asinh",
"assertw",
"atanh",
"awrap",
"bclear",
"behaviour",
"bmatcuk",
"bxor",
"camelcase",
"cbrt",
"colorln",
"consectetur",
"copysign",
"cosinus",
"coveooss",
"coveord",
"criticalf",
"cutset",
"debugf",
"Debugf",
"defval",
"diffmatchpatch",
"divf",
"dolore",
"DONT",
"doublestar",
"drhodes",
"eiusmod",
"elit",
"endexpr",
"Envar",
"Envars",
"erfc",
"expm",
"extensionfiles",
"fatih",
"forgeround",
"frombits",
"funcs",
"genny",
"goerrors",
"gomod",
"goquery",
"gotemplate",
"HCLVALUE",
"hexa",
"htpasswd",
"hypot",
"IHCL",
"ilogb",
"incididunt",
"infof",
"Infof",
"Infoln",
"interpretated",
"kebabcase",
"Kenobi",
"keymap",
"keypair",
"kindis",
"kindof",
"labore",
"ldexp",
"ldflags",
"lenc",
"lgamma",
"logb",
"logrus",
"lshift",
"maxf",
"Metaclass",
"minf",
"missingkey",
"modf",
"mulf",
"multilines",
"multilogger",
"munerum",
"nadipiscing",
"naliqua",
"namet",
"nconsectetur",
"ndolore",
"neiusmod",
"nelit",
"nextafter",
"nincididunt",
"nindent",
"nlabore",
"noticef",
"nsed",
"ntempor",
"otherkey",
"pickv",
"puerkito",
"pwsh",
"reutils",
"rounddown",
"rshift",
"secode",
"semicolumn",
"sergi",
"signbit",
"simplifiable",
"sincos",
"sindent",
"sirupsen",
"sjoin",
"snakecase",
"splitn",
"sprintln",
"squote",
"storer",
"stretchr",
"stripansi",
"striptcolor",
"subf",
"subselection",
"substr",
"swapcase",
"tempfile",
"tempor",
"tfvars",
"TFVARS",
"tracef",
"Tracef",
"traiecta",
"trimall",
"tsed",
"typeis",
"unmanaged",
"unmatch",
"unsplit",
"untitle",
"urlquery",
"uuidv",
"varias",
"warningf",
"worktree",
"warnf"
]
}
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -45,3 +45,5 @@ gotemplate
gotemplate.exe

# End of https://www.gitignore.io/api/go,hugo,code

.DS_Store
2 changes: 2 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -69,3 +69,5 @@ gotemplate --var my_var2=value2 --import vars.json '{{ .my_var }} {{ .my_var2 }}
```

More examples and statement in the [documentation](https://coveooss.github.io/gotemplate/)

Library usage [documentation](https://pkg.go.dev/github.com/coveooss/gotemplate/v3/template)
25 changes: 15 additions & 10 deletions collections/implementation/base_helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -149,17 +149,22 @@ func (bh BaseHelper) tryAsDictionary(object interface{}, strict bool) (baseIDict
return result, nil
}

// TryAsList tries to convert any object to IGenericList object.
// TryAsList attempts to convert the given object to a baseIList.
// If the object is a pointer, it dereferences it first.
// If the object is already a baseIList, it returns it directly.
// If the object is nil, it creates a new list.
// If the object is a slice or array, it creates a new list and populates it with the elements of the slice or array.
// If the object can be converted to a baseList, it performs the conversion.
// If the object cannot be converted to a baseIList, it returns an error.
// If the resulting list needs conversion, it creates a new list and copies the elements to it.
//
// Parameters:
// - object: The object to be converted to a baseIList.
//
// Returns:
// - baseIList: The converted list.
// - error: An error if the object cannot be converted to a baseIList.
func (bh BaseHelper) TryAsList(object interface{}) (baseIList, error) {
return bh.tryAsList(object, false)
}

// TryAsListStrict tries to convert any object to IGenericList object.
func (bh BaseHelper) TryAsListStrict(object interface{}) (baseIList, error) {
return bh.tryAsList(object, true)
}

func (bh BaseHelper) tryAsList(object interface{}, strict bool) (baseIList, error) {
if object != nil && reflect.TypeOf(object).Kind() == reflect.Ptr {
object = reflect.ValueOf(object).Elem().Interface()
}
Expand Down
10 changes: 5 additions & 5 deletions collections/implementation/generic_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -697,7 +697,7 @@ func Test_dict_Default(t *testing.T) {
{"Empty", nil, args{"Foo", "Bar"}, "Bar"},
{"Map int", dictFixture, args{"int", 1}, 123},
{"Map float", dictFixture, args{"float", 1}, 1.23},
{"Map Non existant", dictFixture, args{"Foo", "Bar"}, "Bar"},
{"Map Non existent", dictFixture, args{"Foo", "Bar"}, "Bar"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -722,9 +722,9 @@ func Test_dict_Delete(t *testing.T) {
}{
{"Empty", nil, args{}, baseDict{}, "key <nil> not found"},
{"Map", dictFixture, args{}, dictFixture, "key <nil> not found"},
{"Non existant key", dictFixture, args{"Test", nil}, dictFixture, "key Test not found"},
{"Non existent key", dictFixture, args{"Test", nil}, dictFixture, "key Test not found"},
{"Map with keys", dictFixture, args{"int", []interface{}{"list"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), ""},
{"Map with keys + non existant", dictFixture, args{"int", []interface{}{"list", "Test"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), "key Test not found"},
{"Map with keys + non existent", dictFixture, args{"int", []interface{}{"list", "Test"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), "key Test not found"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -750,9 +750,9 @@ func Test_dict_Flush(t *testing.T) {
}{
{"Empty", nil, nil, baseDict{}},
{"Map", dictFixture, nil, baseDict{}},
{"Non existant key", dictFixture, []interface{}{"Test"}, dictFixture},
{"Non existent key", dictFixture, []interface{}{"Test"}, dictFixture},
{"Map with keys", dictFixture, []interface{}{"int", "list"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
{"Map with keys + non existant", dictFixture, []interface{}{"int", "list", "Test"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
{"Map with keys + non existent", dictFixture, []interface{}{"int", "list", "Test"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions hcl/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func Test_dict_Default(t *testing.T) {
{"Empty", nil, args{"Foo", "Bar"}, "Bar"},
{"Map int", dictFixture, args{"int", 1}, 123},
{"Map float", dictFixture, args{"float", 1}, 1.23},
{"Map Non existant", dictFixture, args{"Foo", "Bar"}, "Bar"},
{"Map Non existent", dictFixture, args{"Foo", "Bar"}, "Bar"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -726,9 +726,9 @@ func Test_dict_Delete(t *testing.T) {
}{
{"Empty", nil, args{}, hclDict{}, "key <nil> not found"},
{"Map", dictFixture, args{}, dictFixture, "key <nil> not found"},
{"Non existant key", dictFixture, args{"Test", nil}, dictFixture, "key Test not found"},
{"Non existent key", dictFixture, args{"Test", nil}, dictFixture, "key Test not found"},
{"Map with keys", dictFixture, args{"int", []interface{}{"list"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), ""},
{"Map with keys + non existant", dictFixture, args{"int", []interface{}{"list", "Test"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), "key Test not found"},
{"Map with keys + non existent", dictFixture, args{"int", []interface{}{"list", "Test"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), "key Test not found"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -754,9 +754,9 @@ func Test_dict_Flush(t *testing.T) {
}{
{"Empty", nil, nil, hclDict{}},
{"Map", dictFixture, nil, hclDict{}},
{"Non existant key", dictFixture, []interface{}{"Test"}, dictFixture},
{"Non existent key", dictFixture, []interface{}{"Test"}, dictFixture},
{"Map with keys", dictFixture, []interface{}{"int", "list"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
{"Map with keys + non existant", dictFixture, []interface{}{"int", "list", "Test"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
{"Map with keys + non existent", dictFixture, []interface{}{"int", "list", "Test"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
10 changes: 5 additions & 5 deletions json/generated_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -701,7 +701,7 @@ func Test_dict_Default(t *testing.T) {
{"Empty", nil, args{"Foo", "Bar"}, "Bar"},
{"Map int", dictFixture, args{"int", 1}, 123},
{"Map float", dictFixture, args{"float", 1}, 1.23},
{"Map Non existant", dictFixture, args{"Foo", "Bar"}, "Bar"},
{"Map Non existent", dictFixture, args{"Foo", "Bar"}, "Bar"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -726,9 +726,9 @@ func Test_dict_Delete(t *testing.T) {
}{
{"Empty", nil, args{}, jsonDict{}, "key <nil> not found"},
{"Map", dictFixture, args{}, dictFixture, "key <nil> not found"},
{"Non existant key", dictFixture, args{"Test", nil}, dictFixture, "key Test not found"},
{"Non existent key", dictFixture, args{"Test", nil}, dictFixture, "key Test not found"},
{"Map with keys", dictFixture, args{"int", []interface{}{"list"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), ""},
{"Map with keys + non existant", dictFixture, args{"int", []interface{}{"list", "Test"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), "key Test not found"},
{"Map with keys + non existent", dictFixture, args{"int", []interface{}{"list", "Test"}}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt"), "key Test not found"},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand All @@ -754,9 +754,9 @@ func Test_dict_Flush(t *testing.T) {
}{
{"Empty", nil, nil, jsonDict{}},
{"Map", dictFixture, nil, jsonDict{}},
{"Non existant key", dictFixture, []interface{}{"Test"}, dictFixture},
{"Non existent key", dictFixture, []interface{}{"Test"}, dictFixture},
{"Map with keys", dictFixture, []interface{}{"int", "list"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
{"Map with keys + non existant", dictFixture, []interface{}{"int", "list", "Test"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
{"Map with keys + non existent", dictFixture, []interface{}{"int", "list", "Test"}, dictFixture.Clone("float", "string", "listInt", "map", "mapInt")},
}
for _, tt := range tests {
t.Run(tt.name, func(t *testing.T) {
Expand Down
2 changes: 1 addition & 1 deletion json/json.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ func (d jsonDict) PrettyPrint() string {
func init() { collections.TypeConverters["!json"] = Unmarshal }

// Unmarshal calls the native Unmarshal but transform the results
// to returns Dictionary and GenerecList instead of go native collections.
// to returns Dictionary and GenericList instead of go native collections.
func Unmarshal(data []byte, out interface{}) (err error) {
if err = NativeUnmarshal(data, out); err != nil {
return
Expand Down
9 changes: 4 additions & 5 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,7 @@ import (
"github.com/sirupsen/logrus"
)

// Version is initialized at build time through -ldflags "-X main.Version=<version number>"
var version = "2.7.4"
var version = "major.minor.patch # locally built, should be replaced by the build process with -ldflags \"-X main.version=<version number>\""
var tempFolder = errors.Must(os.MkdirTemp("", "gotemplate-")).(string)

const (
Expand All @@ -34,7 +33,7 @@ const (
const description = `
An extended template processor for go.

See: https://coveo.github.io/gotemplate for complete documentation.
See: https://coveooss.github.io/gotemplate for complete documentation.
`

func runGotemplate() (exitCode int) {
Expand Down Expand Up @@ -89,7 +88,7 @@ func runGotemplate() (exitCode int) {
ignoreMissingImport = run.Flag("ignore-missing-import", "Exit with code 0 even if import does not exist").Bool()
ignoreMissingSource = run.Flag("ignore-missing-source", "Exit with code 0 even if source does not exist").Bool()
ignoreMissingPaths = run.Flag("ignore-missing-paths", "Exit with code 0 even if import or source do not exist").Bool()
ignoreRazor = run.Flag("ignore-razor", "Do not consider the list of excluded Razor name as razor expression").PlaceHolder("regex").Strings()
ignoreRazor = run.Flag("ignore-razor", "Do not consider the list of excluded Razor name as razor expression").PlaceHolder("regex").NoEnvar().Strings()
templates = run.Arg("templates", "Template files or commands to process").Strings()

list = app.Command("list", "Get detailed help on gotemplate functions").NoAutoShortcut()
Expand Down Expand Up @@ -259,7 +258,7 @@ func runGotemplate() (exitCode int) {
t.TempFolder(tempFolder)

if len(*ignoreRazor) > 0 {
t.IgnoreRazorExpression(*ignoreRazor...)
t.AppendIgnoreRazorExpression(*ignoreRazor...)
}

if command == list.FullCommand() {
Expand Down
2 changes: 1 addition & 1 deletion render-doc
Original file line number Diff line number Diff line change
Expand Up @@ -129,4 +129,4 @@ printf -- '---\nbookFlatSection: true\nweight: 5\n---' > $DOC_FOLDER/objects/_in

# Copy README as the main page
printf -- '---\ntype: docs\n---' > $CONTENT_FOLDER/_index.md
cat README.md >> $CONTENT_FOLDER/_index.md
cat README.md | grep -v "More examples and statement" >> $CONTENT_FOLDER/_index.md
12 changes: 12 additions & 0 deletions template/doc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
Package template provides extended functionalities for the base Go template library.
It includes additional features such as context management, custom delimiters, and
environment variable configurations for template processing.

The package imports several other packages to enhance its capabilities:
. fmt, os, filepath, reflect, strings, sync, and text/template from the standard library.
. collections and utils from github.com/coveooss/gotemplate/v3.
. multicolor from github.com/coveooss/multilogger/color.
*/

package template
2 changes: 1 addition & 1 deletion template/extra_math.go
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ var mathFuncsHelp = descriptions{
"sincos": "Returns Sin(x), Cos(x).\nSpecial cases are:\n sincos(±0) = ±0, 1\n sincos(±Inf) = NaN, NaN\n sincos(NaN) = NaN, NaN",
"sinh": "Returns the hyperbolic sine of x.\nSpecial cases are:\n sinh(±0) = ±0\n sinh(±Inf) = ±Inf\n sinh(NaN) = NaN",
"sqrt": "Returns the square root of x.\nSpecial cases are:\n sqrt(+Inf) = +Inf\n sqrt(±0) = ±0\n sqrt(x < 0) = NaN\n sqrt(NaN) = NaN",
"sub": "Returns the result of the substraction of the two arguments.",
"sub": "Returns the result of the subtraction of the two arguments.",
"tan": "Returns the tangent of the radian argument x.\nSpecial cases are:\n tan(±0) = ±0\n tan(±Inf) = NaN\n tan(NaN) = NaN",
"tanh": "Returns the hyperbolic tangent of x.\nSpecial cases are:\n tanh(±0) = ±0\n tanh(±Inf) = ±1\n tanh(NaN) = NaN",
"to": "Builds a range of integers starting with 1 by default and including the upper limit.",
Expand Down
Loading