Skip to content

Commit

Permalink
Merge pull request #54 from theNewDynamic/52-where-slice
Browse files Browse the repository at this point in the history
Allow slice of strings as env/When context
  • Loading branch information
regisphilibert committed Jan 25, 2022
2 parents cd29a3a + 5867b45 commit 0e73153
Showing 1 changed file with 11 additions and 2 deletions.
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 }}

0 comments on commit 0e73153

Please sign in to comment.