-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Add basic string functions to templates #514
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
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good! I'm surprised these aren't included by default.
Would be good to have a test for this, to make sure it doesn't panic, would you be willing to try and write a test?
Will also need a changelog entry please
templates.go
Outdated
"ToUpper": strings.ToUpper, | ||
"ToLower": strings.ToLower, | ||
} | ||
logger.Printf("using custom template directory %q", dir) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This log line is duplicated with line 15
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I’ll take a stab at a test. Not sure how I missed that duplicate logging entry...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Tests added... PTAL
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
CHANGELOG entry added
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
sorry about the lint error.. I used gitpod and my editor settings weren't configured there to format on save
* add gitea to auth config docs * PR feedback Co-authored-by: Joel Speed <Joel.speed@hotmail.co.uk>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Description
Adds the ability to add functions to templates. Currently supports modifying a variable to all uppercase or all lowercase.
Usage:
{{.ProviderName | ToLower}} {{.ProviderName | ToUpper}}
Motivation and Context
I designed a template for oauth2-proxy which dynamically displays the provider login button based on the provider name using standard external CSS libraries. The required class names are btn-{{lowercaseProvider}}. Rather than create new variables to pass in to the template, the better solution seemed to be to allow the template engine to use basic string functions like ToUpper and ToLower.
HTML templates using external libraries may need to use the provider name in a class. As classes generally cannot be renamed unless a pre-processor like SASS or LESS is used, modifying the variable in the template is the best option.
How Has This Been Tested?
A template has been created which requires lowercase class names for the provider to display the provider logo using font-awesome.
Checklist: