Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decouple grails-plugin-controllers from Sitemesh #13624

Merged
merged 1 commit into from
Sep 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion grails-plugin-controllers/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ dependencies {
project(':grails-plugin-domain-class')

api("org.springframework.boot:spring-boot-autoconfigure:$springBootVersion")
api "org.grails:grails-web-sitemesh:$gspVersion"
runtimeOnly project(':grails-plugin-i18n')

testRuntimeOnly "jline:jline:$jlineVersion"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ import org.grails.web.servlet.mvc.GrailsWebRequest
import org.grails.web.servlet.mvc.exceptions.ControllerExecutionException
import org.grails.web.servlet.view.CompositeViewResolver
import org.grails.web.servlet.view.GroovyPageView
import org.grails.web.sitemesh.GroovyPageLayoutFinder
import org.grails.plugins.web.controllers.ControllersGrailsPlugin
import org.grails.web.util.GrailsApplicationAttributes
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.beans.factory.annotation.Qualifier
Expand Down Expand Up @@ -296,7 +296,7 @@ trait ResponseRenderer extends WebAttributes {
}


boolean renderWithLayout = (explicitSiteMeshLayout || webRequest.getCurrentRequest().getAttribute(GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE))
boolean renderWithLayout = (explicitSiteMeshLayout || webRequest.getCurrentRequest().getAttribute(ControllersGrailsPlugin.LAYOUT_ATTRIBUTE))
// if automatic decoration occurred unwrap, since this is a partial

if (renderWithLayout) {
Expand Down Expand Up @@ -533,13 +533,13 @@ trait ResponseRenderer extends WebAttributes {
}

private void applySiteMeshLayout(HttpServletRequest request, boolean renderView, String explicitSiteMeshLayout) {
if(explicitSiteMeshLayout == null && request.getAttribute(GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE) != null) {
if(explicitSiteMeshLayout == null && request.getAttribute(ControllersGrailsPlugin.LAYOUT_ATTRIBUTE) != null) {
// layout has been set already
return
}
String siteMeshLayout = explicitSiteMeshLayout != null ? explicitSiteMeshLayout : (renderView ? null : GroovyPageLayoutFinder.NONE_LAYOUT)
String siteMeshLayout = explicitSiteMeshLayout != null ? explicitSiteMeshLayout : (renderView ? null : ControllersGrailsPlugin.NONE_LAYOUT)
if(siteMeshLayout != null) {
request.setAttribute GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE, siteMeshLayout
request.setAttribute ControllersGrailsPlugin.LAYOUT_ATTRIBUTE, siteMeshLayout
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@ class ControllersGrailsPlugin extends Plugin {
def observe = ['domainClass']
def dependsOn = [core: version, i18n: version, urlMappings: version]

// Although they are specific to Sitemesh, these properties need
// a new home that is not coupled to any sitemesh dependency
static final String LAYOUT_ATTRIBUTE = "org.grails.layout.name";
static final String NONE_LAYOUT = "_none_";

@Override
Closure doWithSpring(){ { ->
def application = grailsApplication
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package org.grails.web.servlet.mvc

import org.grails.plugins.web.controllers.ControllersGrailsPlugin
import grails.testing.web.controllers.ControllerUnitTest
import org.grails.web.sitemesh.GroovyPageLayoutFinder
import spock.lang.Specification
import grails.artefact.Artefact
import org.grails.buffer.FastStringWriter
Expand All @@ -15,7 +15,7 @@ class RenderDynamicMethodTests extends Specification implements ControllerUnitTe
then:
response.contentType == response.contentType
response.contentAsString == response.contentAsString
request.getAttribute(GroovyPageLayoutFinder.LAYOUT_ATTRIBUTE) == "bar"
request.getAttribute(ControllersGrailsPlugin.LAYOUT_ATTRIBUTE) == "bar"
}

void testRenderView() {
Expand Down
6 changes: 1 addition & 5 deletions grails-web-mvc/build.gradle
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
dependencies {
api project(":grails-web-common"),
project(":grails-web-url-mappings")

compileOnly "org.grails:grails-web-sitemesh:$gspVersion", {
exclude group:'org.grails', module:'grails-web-common'
}
project(":grails-web-url-mappings")
}
Loading