Fixes to groovy class loading mechanisms.
This commit is contained in:
parent
d32ac97caf
commit
31a6c79929
@ -15,7 +15,12 @@ import com.jessebrault.ssg.view.PageView
|
|||||||
import com.jessebrault.ssg.view.WvcPageView
|
import com.jessebrault.ssg.view.WvcPageView
|
||||||
import groovy.transform.TupleConstructor
|
import groovy.transform.TupleConstructor
|
||||||
import groowt.util.di.RegistryObjectFactory
|
import groowt.util.di.RegistryObjectFactory
|
||||||
|
import groowt.view.component.compiler.DefaultComponentTemplateCompilerConfiguration
|
||||||
|
import groowt.view.component.compiler.SimpleComponentTemplateClassFactory
|
||||||
|
import groowt.view.component.compiler.source.ComponentTemplateSource
|
||||||
import groowt.view.component.web.DefaultWebViewComponentContext
|
import groowt.view.component.web.DefaultWebViewComponentContext
|
||||||
|
import groowt.view.component.web.DefaultWebViewComponentScope
|
||||||
|
import groowt.view.component.web.compiler.DefaultWebViewComponentTemplateCompileUnit
|
||||||
import io.github.classgraph.ClassGraph
|
import io.github.classgraph.ClassGraph
|
||||||
import org.slf4j.Logger
|
import org.slf4j.Logger
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
@ -142,7 +147,10 @@ class DefaultStaticSiteGenerator implements StaticSiteGenerator {
|
|||||||
pageSpec.name(),
|
pageSpec.name(),
|
||||||
pageSpec.path(),
|
pageSpec.path(),
|
||||||
pageSpec.fileExtension(),
|
pageSpec.fileExtension(),
|
||||||
(Class<? extends PageView>) pageViewInfo.loadClass()
|
(Class<? extends PageView>) pageViewInfo.loadClass(),
|
||||||
|
!pageSpec.templateResource().empty
|
||||||
|
? pageSpec.templateResource()
|
||||||
|
: pageViewInfo.simpleName + 'Template.wvc'
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -172,6 +180,9 @@ class DefaultStaticSiteGenerator implements StaticSiteGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
def diagnostics = [] as Collection<Diagnostic>
|
def diagnostics = [] as Collection<Diagnostic>
|
||||||
|
def wvcCompilerConfiguration = new DefaultComponentTemplateCompilerConfiguration()
|
||||||
|
wvcCompilerConfiguration.groovyClassLoader = this.groovyClassLoader
|
||||||
|
def componentTemplateClassFactory = new SimpleComponentTemplateClassFactory(this.groovyClassLoader)
|
||||||
|
|
||||||
pages.each {
|
pages.each {
|
||||||
// instantiate PageView
|
// instantiate PageView
|
||||||
@ -191,7 +202,33 @@ class DefaultStaticSiteGenerator implements StaticSiteGenerator {
|
|||||||
pageView.pageTitle = it.name
|
pageView.pageTitle = it.name
|
||||||
pageView.url = buildSpec.baseUrl.get() + it.path
|
pageView.url = buildSpec.baseUrl.get() + it.path
|
||||||
if (pageView instanceof WvcPageView) {
|
if (pageView instanceof WvcPageView) {
|
||||||
pageView.context = new DefaultWebViewComponentContext()
|
pageView.context = new DefaultWebViewComponentContext().tap {
|
||||||
|
configureRootScope {
|
||||||
|
// TODO: scan components in same package, add them to the scope with factories which
|
||||||
|
// use the object factory to construct the component
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pageView.componentTemplate == null) {
|
||||||
|
def templateUrl = pageView.class.getResource(it.templateResource)
|
||||||
|
if (templateUrl == null) {
|
||||||
|
diagnostics.add(new Diagnostic(
|
||||||
|
"Could not find templateResource: $it.templateResource"
|
||||||
|
))
|
||||||
|
return
|
||||||
|
}
|
||||||
|
def source = ComponentTemplateSource.of(templateUrl)
|
||||||
|
def compileUnit = new DefaultWebViewComponentTemplateCompileUnit(
|
||||||
|
source.descriptiveName,
|
||||||
|
pageView.class,
|
||||||
|
source,
|
||||||
|
pageView.class.packageName
|
||||||
|
)
|
||||||
|
def compileResult = compileUnit.compile(wvcCompilerConfiguration)
|
||||||
|
def templateClass = componentTemplateClassFactory.getTemplateClass(compileResult)
|
||||||
|
def componentTemplate = templateClass.getConstructor().newInstance()
|
||||||
|
pageView.componentTemplate = componentTemplate
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// Render the page
|
// Render the page
|
||||||
|
@ -14,10 +14,11 @@ class DefaultPage implements Page {
|
|||||||
final String path
|
final String path
|
||||||
final String fileExtension
|
final String fileExtension
|
||||||
final Class<? extends PageView> viewType
|
final Class<? extends PageView> viewType
|
||||||
|
final String templateResource
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
String toString() {
|
String toString() {
|
||||||
"SimplePage(name: $name, path: $path, fileExtension: $fileExtension)"
|
"SimplePage(name: $name, path: $path, fileExtension: $fileExtension, templateResource: $templateResource)"
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,5 @@ interface Page {
|
|||||||
String getPath()
|
String getPath()
|
||||||
String getFileExtension()
|
String getFileExtension()
|
||||||
Class<? extends PageView> getViewType()
|
Class<? extends PageView> getViewType()
|
||||||
|
String getTemplateResource()
|
||||||
}
|
}
|
||||||
|
@ -10,5 +10,6 @@ import java.lang.annotation.Target
|
|||||||
@interface PageSpec {
|
@interface PageSpec {
|
||||||
String name()
|
String name()
|
||||||
String path()
|
String path()
|
||||||
|
String templateResource() default ''
|
||||||
String fileExtension() default '.html'
|
String fileExtension() default '.html'
|
||||||
}
|
}
|
||||||
|
@ -13,6 +13,8 @@ abstract class WvcPageView extends BaseWebViewComponent implements PageView, Wit
|
|||||||
String pageTitle
|
String pageTitle
|
||||||
String url
|
String url
|
||||||
|
|
||||||
|
WvcPageView() {}
|
||||||
|
|
||||||
WvcPageView(ComponentTemplate template) {
|
WvcPageView(ComponentTemplate template) {
|
||||||
super(template)
|
super(template)
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,14 @@
|
|||||||
|
package com.jessebrault.site
|
||||||
|
|
||||||
|
import groowt.view.component.web.BaseWebViewComponent
|
||||||
|
|
||||||
|
class Head extends BaseWebViewComponent {
|
||||||
|
|
||||||
|
final String title
|
||||||
|
|
||||||
|
Head(Map attr) {
|
||||||
|
super(Head.getResource('HeadTemplate.wvc'))
|
||||||
|
this.title = attr.title()
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -0,0 +1,6 @@
|
|||||||
|
---
|
||||||
|
package com.jessebrault.site
|
||||||
|
---
|
||||||
|
<head>
|
||||||
|
<title>$title</title>
|
||||||
|
</head>
|
@ -4,6 +4,7 @@ import com.jessebrault.ssg.di.InjectText
|
|||||||
import com.jessebrault.ssg.page.PageSpec
|
import com.jessebrault.ssg.page.PageSpec
|
||||||
import com.jessebrault.ssg.text.Text
|
import com.jessebrault.ssg.text.Text
|
||||||
import com.jessebrault.ssg.view.WvcPageView
|
import com.jessebrault.ssg.view.WvcPageView
|
||||||
|
import groowt.view.component.web.WebViewComponentScope
|
||||||
import jakarta.inject.Inject
|
import jakarta.inject.Inject
|
||||||
|
|
||||||
@PageSpec(name = 'Biography', path = '/biography')
|
@PageSpec(name = 'Biography', path = '/biography')
|
||||||
@ -15,8 +16,14 @@ class Biography extends WvcPageView {
|
|||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Biography(@InjectText('/Biography.md') Text biographyText) {
|
Biography(@InjectText('/Biography.md') Text biographyText) {
|
||||||
super(Biography.getResource('BiographyTemplate.wvc'))
|
|
||||||
this.biographyText = biographyText
|
this.biographyText = biographyText
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected void beforeRender() {
|
||||||
|
context.configureRootScope(WebViewComponentScope) {
|
||||||
|
addWithAttr(Head)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -2,9 +2,7 @@
|
|||||||
package com.jessebrault.site
|
package com.jessebrault.site
|
||||||
---
|
---
|
||||||
<html lang="en">
|
<html lang="en">
|
||||||
<head>
|
<Head title={pageTitle} />
|
||||||
<title>$pageTitle</title>
|
|
||||||
</head>
|
|
||||||
<body>
|
<body>
|
||||||
<h1>$pageTitle</h1>
|
<h1>$pageTitle</h1>
|
||||||
<h2>$url</h2>
|
<h2>$url</h2>
|
||||||
|
Loading…
Reference in New Issue
Block a user