Skip to content

Instantly share code, notes, and snippets.

@ppazos
Forked from pledbrook/CommonTagLib.groovy
Created January 21, 2024 16:29
Show Gist options
  • Save ppazos/a611e9b44c18988573a2921b2969758b to your computer and use it in GitHub Desktop.
Save ppazos/a611e9b44c18988573a2921b2969758b to your computer and use it in GitHub Desktop.
Example map with enum keys
import org.grails.common.ApprovalStatus
import static org.grails.common.ApprovalStatus.*
class CommonTagLib {
static namespace = "common"
static final STATUS_TO_CSS_CLASS = [
(PENDING): "warning",
(REJECTED): "important",
(APPROVED): "success" ].asImmutable()
def approvalStatus = { attrs ->
def status = asEnum(attrs.status)
def type = attrs.type ?: 'label'
def labelClass = STATUS_TO_CSS_CLASS[status] ?: "inverse"
...
}
private asEnum(String value) { ApprovalStatus.valueOf(ApprovalStatus, value) }
private asEnum(ApprovalStatus value) { return value }
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment