Skip to content

Instantly share code, notes, and snippets.

@pledbrook
Created May 16, 2012 07:51
Show Gist options
  • Save pledbrook/2708457 to your computer and use it in GitHub Desktop.
Save pledbrook/2708457 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