Skip to content

Commit

Permalink
add AllEnum() function (#1079)
Browse files Browse the repository at this point in the history
  • Loading branch information
stephenafamo authored Feb 1, 2022
1 parent d5757fd commit d6e9344
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion templates/main/singleton/boil_types.go.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,11 @@ It only titlecases the EnumValue portion if it's snake-cased.
-}}

{{- if $enumFirstIter -}}
{{$enumType := "string" }}
{{$allvals := "\n"}}

{{if $.AddEnumTypes}}
{{- $enumType = $enumName -}}
type {{$enumName}} string
{{end}}

Expand All @@ -100,9 +104,14 @@ It only titlecases the EnumValue portion if it's snake-cased.
{{- if shouldTitleCaseEnum $valStripped -}}
{{$enumValue = titleCase $valStripped}}
{{- end -}}
{{$enumName}}{{$enumValue}} {{if $.AddEnumTypes}}{{$enumName}}{{end}} = "{{$val}}"
{{$enumName}}{{$enumValue}} {{$enumType}} = "{{$val}}"
{{$allvals = printf "%s%s%s,\n" $allvals $enumName $enumValue -}}
{{end -}}
)

func All{{$enumName}}() []{{$enumType}} {
return []{{$enumType}}{ {{$allvals}} }
}
{{- end -}}

{{if $.AddEnumTypes}}
Expand Down

0 comments on commit d6e9344

Please sign in to comment.