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

Allow slice of strings as env/When context #54

Merged
merged 1 commit into from
Jan 25, 2022
Merged
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
13 changes: 11 additions & 2 deletions core/env/When.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@

@author @regisphilibert

@context Map (.)
@context String | Slice of Strings (.)

@access private

Expand All @@ -19,12 +19,21 @@
{{ end }}
*/}}
{{ $return := false }}

{{ $env := partialCached "huge/env/Get" "Get" }}

{{ if eq $ "never" }}
{{ $return = false }}
{{ else if eq $ "always" }}
{{ $return = true }}
{{ else }}
{{ $return = partialCached "huge/env/Is" $ $ }}
{{/* If the context is a Slice, we'll test all the slice's strings against the current environment */}}
{{ if reflect.IsSlice $ }}
{{ $return = in $ $env }}
{{/* Else, we just test the lone string */}}
{{ else }}
{{ $return = eq $ $env }}
{{ end }}
{{ end }}

{{ return $return }}