Biography page working with Text injection and rendering.
This commit is contained in:
parent
5975f5110b
commit
0998d1a11d
@ -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
|
||||
|
@ -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) {
|
||||
|
@ -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()
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -90,6 +90,8 @@ class MarkdownText implements Text {
|
||||
} else {
|
||||
this.parsed = markdownParser.parse(body)
|
||||
}
|
||||
} else {
|
||||
this.parsed = markdownParser.parse(completeSourceText)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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
|
||||
)
|
||||
}
|
||||
|
@ -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
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -9,5 +9,8 @@ package com.jessebrault.site
|
||||
<h1>$pageTitle</h1>
|
||||
<h2>$url</h2>
|
||||
<p>$greeting</p>
|
||||
<section>
|
||||
<%= biographyText.render() %>
|
||||
</section>
|
||||
</body>
|
||||
</html>
|
||||
|
3
test-ssg-project/texts/Biography.md
Normal file
3
test-ssg-project/texts/Biography.md
Normal file
@ -0,0 +1,3 @@
|
||||
# Biography
|
||||
|
||||
Hello! My name is Jesse Brault.
|
Loading…
Reference in New Issue
Block a user