-
-
Save ppazos/a611e9b44c18988573a2921b2969758b to your computer and use it in GitHub Desktop.
Example map with enum keys
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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