Permalink
Browse files

Merge branch 'master' of github.com:grails/grails-core

  • Loading branch information...
2 parents a3b5432 + cd9a6e6 commit aa2be4b4a74b91ede38185cd656b0513e56df0c4 @jeffbrown jeffbrown committed May 4, 2012
@@ -0,0 +1,36 @@
+package org.codehaus.groovy.grails.web.pages
+
+import grails.test.AbstractGrailsEnvChangingSpec
+
+import spock.lang.Specification
+import grails.test.mixin.TestFor
+import grails.util.Environment;
+import grails.artefact.Artefact
+
+
+@TestFor(CustomTagLib)
+class OptionalTagBodySpec extends AbstractGrailsEnvChangingSpec {
+ def "Test that the existence of a body can be tested with groovy truth"(grailsEnv) {
+ when:
+ changeGrailsEnv(grailsEnv)
+ def content = applyTemplate("<a:myBody />")
+ def content2 = applyTemplate("<a:myBody>Hello</a:myBody>")
+ then:
+ content == 'nobody'
+ content2 == 'Hello'
+ where:
+ grailsEnv << grailsEnvs
+ }
+}
+@Artefact("TagLibrary")
+class CustomTagLib {
+ static namespace = "a"
+
+ def myBody = { attrs, body ->
+ if(body) {
+ out << body()
+ } else {
+ out << 'nobody'
+ }
+ }
+}
@@ -47,6 +47,7 @@
import org.codehaus.groovy.grails.web.taglib.exceptions.GrailsTagException;
import org.codehaus.groovy.grails.web.util.CodecPrintWriter;
import org.codehaus.groovy.grails.web.util.GrailsPrintWriter;
+import org.codehaus.groovy.runtime.typehandling.DefaultTypeTransformation;
/**
* NOTE: Based on work done by on the GSP standalone project (https://gsp.dev.java.net/)
@@ -154,6 +155,10 @@ public Object doCall(@SuppressWarnings("unused") Object[] args) {
public Object call(Object... args) {
return retval;
}
+
+ public boolean asBoolean() {
+ return DefaultTypeTransformation.castToBoolean(retval);
+ }
}
protected static final Closure<?> EMPTY_BODY_CLOSURE = new ConstantClosure(BLANK_STRING);

0 comments on commit aa2be4b

Please sign in to comment.