Skip to content

Commit

Permalink
Allow default scaffold templates for namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
codeconsole committed Sep 11, 2024
1 parent 279d70a commit 0807fcd
Showing 1 changed file with 24 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,28 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource
viewCacheKey
}

private Resource resolveResource(Class controllerClass, shortViewName) {
Resource res = null
if (Environment.isDevelopmentMode()) {
res = new FileSystemResource(new File(BuildSettings.BASE_DIR, "src/main/templates/scaffolding/${shortViewName}.gsp"))
}

if (!res?.exists()) {
def url = IOUtils.findResourceRelativeToClass(controllerClass, "/META-INF/templates/scaffolding/${shortViewName}.gsp")
res = url ? new UrlResource(url) : null
}

if (!res.exists() && templateOverridePluginDescriptor) {
def url = IOUtils.findResourceRelativeToClass(templateOverridePluginDescriptor, "/META-INF/templates/scaffolding/${shortViewName}.gsp")
res = url ? new UrlResource(url) : null
}

if (!res.exists()) {
res = resourceLoader.getResource("classpath:META-INF/templates/scaffolding/${shortViewName}.gsp")
}
res
}

@Override
protected View loadView(String viewName, Locale locale) throws Exception {
def view = super.loadView(viewName, locale)
Expand All @@ -93,26 +115,10 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource

if (scaffoldValue instanceof Class) {
def shortViewName = viewName.substring(viewName.lastIndexOf('/') + 1)
Resource res = null

if (Environment.isDevelopmentMode()) {
res = new FileSystemResource(new File(BuildSettings.BASE_DIR, "src/main/templates/scaffolding/${shortViewName}.gsp"))
}

Resource res = controllerClass.namespace? resolveResource(controllerClass.clazz, "${controllerClass.namespace}/${shortViewName}") : null
if (!res?.exists()) {
def url = IOUtils.findResourceRelativeToClass(controllerClass.clazz, "/META-INF/templates/scaffolding/${shortViewName}.gsp")
res = url ? new UrlResource(url) : null
res = resolveResource(controllerClass.clazz, shortViewName)
}

if (!res.exists() && templateOverridePluginDescriptor) {
def url = IOUtils.findResourceRelativeToClass(templateOverridePluginDescriptor, "/META-INF/templates/scaffolding/${shortViewName}.gsp")
res = url ? new UrlResource(url) : null
}

if (!res.exists()) {
res = resourceLoader.getResource("classpath:META-INF/templates/scaffolding/${shortViewName}.gsp")
}

if (res.exists()) {
def model = model((Class) scaffoldValue)
def viewGenerator = new GStringTemplateEngine()
Expand All @@ -133,9 +139,7 @@ class ScaffoldingViewResolver extends GroovyPageViewResolver implements Resource
} else {
return view
}

}

}
}
return view
Expand Down

0 comments on commit 0807fcd

Please sign in to comment.