Created
May 16, 2012 07:51
-
-
Save pledbrook/2708457 to your computer and use it in GitHub Desktop.
Example map with enum keys
This file contains hidden or 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