Biography page working with Text injection and rendering.

This commit is contained in:
JesseBrault0709 2024-05-28 08:15:20 +02:00
parent 5975f5110b
commit 0998d1a11d
8 changed files with 32 additions and 19 deletions

View File

@ -44,9 +44,6 @@ abstract class BuildScriptBase extends Script {
this.buildClosure = buildClosure
}
/* --- internal --- */
@ApiStatus.Internal
File getProjectRoot() {
requireNonNull(this.projectRoot)
}
@ -56,6 +53,10 @@ abstract class BuildScriptBase extends Script {
this.projectRoot = requireNonNull(projectRoot)
}
String getBuildName() {
return buildName
}
@ApiStatus.Internal
void setBuildName(String buildName) {
this.buildName = buildName

View File

@ -5,6 +5,7 @@ import groovy.transform.NullCheck
import groovy.transform.TupleConstructor
import java.util.function.Function
import java.util.function.Supplier
@NullCheck
@TupleConstructor(includeFields = true)
@ -28,7 +29,7 @@ class BuildScriptToBuildSpecConverter {
)
}
protected BuildSpec doConvert(String name, BuildScriptBase buildScript) {
protected BuildSpec doConvert(String buildScriptFqn, BuildScriptBase buildScript) {
final Deque<BuildScriptBase> buildHierarchy = new LinkedList<>()
buildHierarchy.push(buildScript)
String extending = buildScript.extending
@ -38,14 +39,14 @@ class BuildScriptToBuildSpecConverter {
extending = from.extending
}
def delegate = this.buildDelegateFactory.apply(name)
def delegate = this.buildDelegateFactory.apply(buildScriptFqn)
while (!buildHierarchy.isEmpty()) {
def currentScript = buildHierarchy.pop()
currentScript.buildClosure.delegate = delegate
currentScript.buildClosure()
}
this.getFromDelegate(name, delegate)
this.getFromDelegate(buildScriptFqn, delegate)
}
BuildSpec convert(String buildScriptFqn) {

View File

@ -18,17 +18,15 @@ import java.util.function.Supplier
final class BuildDelegate {
static Supplier<BuildDelegate> withDefaults(String buildName, File projectDir) {
return {
new BuildDelegate(projectDir).tap {
basePackages.convention = [] as Set<String>
outputDir.convention = PathUtil.resolve(projectDir, Path.of('dist', buildName))
globals.convention = [:]
models.convention = [] as Set<Model>
textsDirs.convention = [new File(projectDir, 'texts')] as Set<File>
textConverters.convention = [new MarkdownTextConverter()] as Set<TextConverter>
objectFactoryBuilder.convention = DefaultRegistryObjectFactory.Builder.withDefaults()
}
static BuildDelegate withDefaults(String buildName, File projectDir) {
new BuildDelegate(projectDir).tap {
basePackages.convention = [] as Set<String>
outputDir.convention = PathUtil.resolve(projectDir, Path.of('dist', buildName.split(/\\./)))
globals.convention = [:]
models.convention = [] as Set<Model>
textsDirs.convention = [new File(projectDir, 'texts')] as Set<File>
textConverters.convention = [new MarkdownTextConverter()] as Set<TextConverter>
objectFactoryBuilder.convention = DefaultRegistryObjectFactory.Builder.withDefaults()
}
}

View File

@ -90,6 +90,8 @@ class MarkdownText implements Text {
} else {
this.parsed = markdownParser.parse(body)
}
} else {
this.parsed = markdownParser.parse(completeSourceText)
}
}

View File

@ -16,7 +16,7 @@ class MarkdownTextConverter implements TextConverter {
Text convert(File textsDir, File textFile) {
new MarkdownText(
ExtensionUtil.stripExtension(textFile.name),
PathUtil.relative(textsDir, textFile).toString(),
'/' + PathUtil.relative(textsDir, textFile).toString(),
textFile
)
}

View File

@ -1,6 +1,8 @@
package com.jessebrault.site
import com.jessebrault.ssg.di.InjectText
import com.jessebrault.ssg.page.PageSpec
import com.jessebrault.ssg.text.Text
import com.jessebrault.ssg.view.WvcPageView
import jakarta.inject.Inject
@ -9,9 +11,12 @@ class Biography extends WvcPageView {
static final String greeting = 'Hello, World!'
final Text biographyText
@Inject
Biography() {
Biography(@InjectText('/Biography.md') Text biographyText) {
super(Biography.getResource('BiographyTemplate.wvc'))
this.biographyText = biographyText
}
}

View File

@ -9,5 +9,8 @@ package com.jessebrault.site
<h1>$pageTitle</h1>
<h2>$url</h2>
<p>$greeting</p>
<section>
<%= biographyText.render() %>
</section>
</body>
</html>

View File

@ -0,0 +1,3 @@
# Biography
Hello! My name is Jesse Brault.