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
|
this.buildClosure = buildClosure
|
||||||
}
|
}
|
||||||
|
|
||||||
/* --- internal --- */
|
|
||||||
|
|
||||||
@ApiStatus.Internal
|
|
||||||
File getProjectRoot() {
|
File getProjectRoot() {
|
||||||
requireNonNull(this.projectRoot)
|
requireNonNull(this.projectRoot)
|
||||||
}
|
}
|
||||||
@ -56,6 +53,10 @@ abstract class BuildScriptBase extends Script {
|
|||||||
this.projectRoot = requireNonNull(projectRoot)
|
this.projectRoot = requireNonNull(projectRoot)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String getBuildName() {
|
||||||
|
return buildName
|
||||||
|
}
|
||||||
|
|
||||||
@ApiStatus.Internal
|
@ApiStatus.Internal
|
||||||
void setBuildName(String buildName) {
|
void setBuildName(String buildName) {
|
||||||
this.buildName = buildName
|
this.buildName = buildName
|
||||||
|
@ -5,6 +5,7 @@ import groovy.transform.NullCheck
|
|||||||
import groovy.transform.TupleConstructor
|
import groovy.transform.TupleConstructor
|
||||||
|
|
||||||
import java.util.function.Function
|
import java.util.function.Function
|
||||||
|
import java.util.function.Supplier
|
||||||
|
|
||||||
@NullCheck
|
@NullCheck
|
||||||
@TupleConstructor(includeFields = true)
|
@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<>()
|
final Deque<BuildScriptBase> buildHierarchy = new LinkedList<>()
|
||||||
buildHierarchy.push(buildScript)
|
buildHierarchy.push(buildScript)
|
||||||
String extending = buildScript.extending
|
String extending = buildScript.extending
|
||||||
@ -38,14 +39,14 @@ class BuildScriptToBuildSpecConverter {
|
|||||||
extending = from.extending
|
extending = from.extending
|
||||||
}
|
}
|
||||||
|
|
||||||
def delegate = this.buildDelegateFactory.apply(name)
|
def delegate = this.buildDelegateFactory.apply(buildScriptFqn)
|
||||||
while (!buildHierarchy.isEmpty()) {
|
while (!buildHierarchy.isEmpty()) {
|
||||||
def currentScript = buildHierarchy.pop()
|
def currentScript = buildHierarchy.pop()
|
||||||
currentScript.buildClosure.delegate = delegate
|
currentScript.buildClosure.delegate = delegate
|
||||||
currentScript.buildClosure()
|
currentScript.buildClosure()
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getFromDelegate(name, delegate)
|
this.getFromDelegate(buildScriptFqn, delegate)
|
||||||
}
|
}
|
||||||
|
|
||||||
BuildSpec convert(String buildScriptFqn) {
|
BuildSpec convert(String buildScriptFqn) {
|
||||||
|
@ -18,11 +18,10 @@ import java.util.function.Supplier
|
|||||||
|
|
||||||
final class BuildDelegate {
|
final class BuildDelegate {
|
||||||
|
|
||||||
static Supplier<BuildDelegate> withDefaults(String buildName, File projectDir) {
|
static BuildDelegate withDefaults(String buildName, File projectDir) {
|
||||||
return {
|
|
||||||
new BuildDelegate(projectDir).tap {
|
new BuildDelegate(projectDir).tap {
|
||||||
basePackages.convention = [] as Set<String>
|
basePackages.convention = [] as Set<String>
|
||||||
outputDir.convention = PathUtil.resolve(projectDir, Path.of('dist', buildName))
|
outputDir.convention = PathUtil.resolve(projectDir, Path.of('dist', buildName.split(/\\./)))
|
||||||
globals.convention = [:]
|
globals.convention = [:]
|
||||||
models.convention = [] as Set<Model>
|
models.convention = [] as Set<Model>
|
||||||
textsDirs.convention = [new File(projectDir, 'texts')] as Set<File>
|
textsDirs.convention = [new File(projectDir, 'texts')] as Set<File>
|
||||||
@ -30,7 +29,6 @@ final class BuildDelegate {
|
|||||||
objectFactoryBuilder.convention = DefaultRegistryObjectFactory.Builder.withDefaults()
|
objectFactoryBuilder.convention = DefaultRegistryObjectFactory.Builder.withDefaults()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
final File projectDir
|
final File projectDir
|
||||||
|
|
||||||
|
@ -90,6 +90,8 @@ class MarkdownText implements Text {
|
|||||||
} else {
|
} else {
|
||||||
this.parsed = markdownParser.parse(body)
|
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) {
|
Text convert(File textsDir, File textFile) {
|
||||||
new MarkdownText(
|
new MarkdownText(
|
||||||
ExtensionUtil.stripExtension(textFile.name),
|
ExtensionUtil.stripExtension(textFile.name),
|
||||||
PathUtil.relative(textsDir, textFile).toString(),
|
'/' + PathUtil.relative(textsDir, textFile).toString(),
|
||||||
textFile
|
textFile
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
@ -1,6 +1,8 @@
|
|||||||
package com.jessebrault.site
|
package com.jessebrault.site
|
||||||
|
|
||||||
|
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.view.WvcPageView
|
import com.jessebrault.ssg.view.WvcPageView
|
||||||
import jakarta.inject.Inject
|
import jakarta.inject.Inject
|
||||||
|
|
||||||
@ -9,9 +11,12 @@ class Biography extends WvcPageView {
|
|||||||
|
|
||||||
static final String greeting = 'Hello, World!'
|
static final String greeting = 'Hello, World!'
|
||||||
|
|
||||||
|
final Text biographyText
|
||||||
|
|
||||||
@Inject
|
@Inject
|
||||||
Biography() {
|
Biography(@InjectText('/Biography.md') Text biographyText) {
|
||||||
super(Biography.getResource('BiographyTemplate.wvc'))
|
super(Biography.getResource('BiographyTemplate.wvc'))
|
||||||
|
this.biographyText = biographyText
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -9,5 +9,8 @@ package com.jessebrault.site
|
|||||||
<h1>$pageTitle</h1>
|
<h1>$pageTitle</h1>
|
||||||
<h2>$url</h2>
|
<h2>$url</h2>
|
||||||
<p>$greeting</p>
|
<p>$greeting</p>
|
||||||
|
<section>
|
||||||
|
<%= biographyText.render() %>
|
||||||
|
</section>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</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