File tree Expand file tree Collapse file tree 2 files changed +41
-0
lines changed
grails-test-suite-web/src/test/groovy/org/codehaus/groovy/grails/web/pages
grails-web/src/main/groovy/org/codehaus/groovy/grails/web/pages Expand file tree Collapse file tree 2 files changed +41
-0
lines changed Original file line number Diff line number Diff line change 1+ package org.codehaus.groovy.grails.web.pages
2+
3+ import grails.test.AbstractGrailsEnvChangingSpec
4+
5+ import spock.lang.Specification
6+ import grails.test.mixin.TestFor
7+ import grails.util.Environment ;
8+ import grails.artefact.Artefact
9+
10+
11+ @TestFor (CustomTagLib )
12+ class OptionalTagBodySpec extends AbstractGrailsEnvChangingSpec {
13+ def " Test that the existence of a body can be tested with groovy truth" (grailsEnv) {
14+ when :
15+ changeGrailsEnv(grailsEnv)
16+ def content = applyTemplate(" <a:myBody />" )
17+ def content2 = applyTemplate(" <a:myBody>Hello</a:myBody>" )
18+ then :
19+ content == ' nobody'
20+ content2 == ' Hello'
21+ where :
22+ grailsEnv << grailsEnvs
23+ }
24+ }
25+ @Artefact (" TagLibrary" )
26+ class CustomTagLib {
27+ static namespace = " a"
28+
29+ def myBody = { attrs , body ->
30+ if (body) {
31+ out << body()
32+ } else {
33+ out << ' nobody'
34+ }
35+ }
36+ }
Original file line number Diff line number Diff line change 4747import org .codehaus .groovy .grails .web .taglib .exceptions .GrailsTagException ;
4848import org .codehaus .groovy .grails .web .util .CodecPrintWriter ;
4949import org .codehaus .groovy .grails .web .util .GrailsPrintWriter ;
50+ import org .codehaus .groovy .runtime .typehandling .DefaultTypeTransformation ;
5051
5152/**
5253 * NOTE: Based on work done by on the GSP standalone project (https://gsp.dev.java.net/)
@@ -152,6 +153,10 @@ public Object doCall(@SuppressWarnings("unused") Object[] args) {
152153 public Object call (Object ... args ) {
153154 return retval ;
154155 }
156+
157+ public boolean asBoolean () {
158+ return DefaultTypeTransformation .castToBoolean (retval );
159+ }
155160 }
156161
157162 protected static final Closure <?> EMPTY_BODY_CLOSURE = new ConstantClosure (BLANK_STRING );
You can’t perform that action at this time.
0 commit comments