Now using gst-lib.
This commit is contained in:
parent
f5697fb99b
commit
bc28a00cfc
@ -7,6 +7,9 @@ repositories {
|
|||||||
}
|
}
|
||||||
|
|
||||||
dependencies {
|
dependencies {
|
||||||
|
// https://archiva.jessebrault.com/#artifact/com.jessebrault.gst/lib
|
||||||
|
implementation 'com.jessebrault.gst:lib:0.0.1'
|
||||||
|
|
||||||
// https://mvnrepository.com/artifact/org.apache.groovy/groovy-templates
|
// https://mvnrepository.com/artifact/org.apache.groovy/groovy-templates
|
||||||
implementation 'org.apache.groovy:groovy-templates:4.0.12'
|
implementation 'org.apache.groovy:groovy-templates:4.0.12'
|
||||||
|
|
||||||
|
@ -19,20 +19,14 @@ final class GspPageRenderer implements PageRenderer {
|
|||||||
RenderContext context
|
RenderContext context
|
||||||
) {
|
) {
|
||||||
def diagnostics = []
|
def diagnostics = []
|
||||||
try {
|
def result = this.gspRenderer.render(specialPage.text, context) {
|
||||||
def result = this.gspRenderer.render(specialPage.text, context) {
|
it.diagnosticsConsumer = diagnostics.&addAll
|
||||||
it.diagnosticsConsumer = diagnostics.&addAll
|
it.loggerName = "GspSpecialPage(${ specialPage.path })"
|
||||||
it.loggerName = "GspSpecialPage(${ specialPage.path })"
|
}
|
||||||
}
|
if (result.hasDiagnostics()) {
|
||||||
Result.of(diagnostics, result.toString())
|
Result.ofDiagnostics(diagnostics + result.diagnostics)
|
||||||
} catch (Exception e) {
|
} else {
|
||||||
Result.of(
|
Result.of(diagnostics, result.get())
|
||||||
[*diagnostics, new Diagnostic(
|
|
||||||
"An exception occurred while rendering specialPage ${ specialPage.path }:\n${ e }",
|
|
||||||
e
|
|
||||||
)],
|
|
||||||
''
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -26,24 +26,18 @@ final class GspPartRenderer implements PartRenderer {
|
|||||||
requireNonNull(binding)
|
requireNonNull(binding)
|
||||||
requireNonNull(context)
|
requireNonNull(context)
|
||||||
def diagnostics = []
|
def diagnostics = []
|
||||||
try {
|
def result = this.gspRenderer.render(part.text, context) {
|
||||||
def result = this.gspRenderer.render(part.text, context) {
|
it.putCustom('binding', binding)
|
||||||
it.putCustom('binding', binding)
|
it.diagnosticsConsumer = diagnostics.&addAll
|
||||||
it.diagnosticsConsumer = diagnostics.&addAll
|
it.loggerName = "GspPart(${ part.path })"
|
||||||
it.loggerName = "GspPart(${ part.path })"
|
if (text) {
|
||||||
if (text) {
|
it.text = text
|
||||||
it.text = text
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
Result.of(diagnostics, result.toString())
|
}
|
||||||
} catch (Exception e) {
|
if (result.hasDiagnostics()) {
|
||||||
Result.of(
|
Result.ofDiagnostics(diagnostics + result.diagnostics)
|
||||||
[*diagnostics, new Diagnostic(
|
} else {
|
||||||
"An exception occurred while rendering part ${ part.path }:\n${ e }",
|
Result.of(diagnostics, result.get())
|
||||||
e
|
|
||||||
)],
|
|
||||||
''
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,28 +1,39 @@
|
|||||||
package com.jessebrault.ssg.render
|
package com.jessebrault.ssg.render
|
||||||
|
|
||||||
|
import com.jessebrault.gst.TemplateCreator
|
||||||
|
import com.jessebrault.gst.groovy.GroovyTemplateCreator
|
||||||
|
import com.jessebrault.gst.parser.ExtendedGstParser
|
||||||
import com.jessebrault.ssg.dsl.StandardDslMap
|
import com.jessebrault.ssg.dsl.StandardDslMap
|
||||||
import groovy.text.GStringTemplateEngine
|
import com.jessebrault.ssg.util.Diagnostic
|
||||||
import groovy.text.TemplateEngine
|
import com.jessebrault.ssg.util.Result
|
||||||
import org.codehaus.groovy.control.CompilerConfiguration
|
|
||||||
|
|
||||||
import java.util.function.Consumer
|
import java.util.function.Consumer
|
||||||
|
|
||||||
final class StandardGspRenderer {
|
final class StandardGspRenderer {
|
||||||
|
|
||||||
private final TemplateEngine engine
|
private final TemplateCreator templateCreator
|
||||||
|
|
||||||
StandardGspRenderer(ClassLoader parentClassLoader) {
|
StandardGspRenderer(ClassLoader parentClassLoader) {
|
||||||
def cc = new CompilerConfiguration() // TODO: investigate if this makes any difference on the ultimate template
|
this.templateCreator = new GroovyTemplateCreator(ExtendedGstParser::new, [], parentClassLoader, true)
|
||||||
def gcl = new GroovyClassLoader(parentClassLoader, cc)
|
|
||||||
this.engine = new GStringTemplateEngine(gcl)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
String render(
|
Result<String> render(
|
||||||
String template,
|
String templateText,
|
||||||
RenderContext context,
|
RenderContext context,
|
||||||
Consumer<StandardDslMap.Builder> dslMapBuilderConsumer
|
Consumer<StandardDslMap.Builder> dslMapBuilderConsumer
|
||||||
) {
|
) {
|
||||||
this.engine.createTemplate(template).make(StandardDslMap.get(context, dslMapBuilderConsumer)).toString()
|
try {
|
||||||
|
def templateCreateResult = this.templateCreator.create(templateText)
|
||||||
|
if (templateCreateResult.hasDiagnostics()) {
|
||||||
|
Result.ofDiagnostics(templateCreateResult.diagnostics.collect {
|
||||||
|
new Diagnostic(it.message, it.exception)
|
||||||
|
})
|
||||||
|
} else {
|
||||||
|
Result.of(templateCreateResult.get().make(StandardDslMap.get(context, dslMapBuilderConsumer)))
|
||||||
|
}
|
||||||
|
} catch (Exception e) {
|
||||||
|
Result.ofDiagnostics([new Diagnostic(e.message, e)])
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,21 +21,15 @@ final class GspTemplateRenderer implements TemplateRenderer {
|
|||||||
RenderContext context
|
RenderContext context
|
||||||
) {
|
) {
|
||||||
def diagnostics = []
|
def diagnostics = []
|
||||||
try {
|
def result = this.gspRenderer.render(template.text, context) {
|
||||||
def result = this.gspRenderer.render(template.text, context) {
|
it.diagnosticsConsumer = diagnostics.&addAll
|
||||||
it.diagnosticsConsumer = diagnostics.&addAll
|
it.loggerName = "GspTemplate(${ template.path })"
|
||||||
it.loggerName = "GspTemplate(${ template.path })"
|
it.text = text
|
||||||
it.text = text
|
}
|
||||||
}
|
if (result.hasDiagnostics()) {
|
||||||
Result.of(diagnostics, result)
|
Result.ofDiagnostics(diagnostics + result.diagnostics)
|
||||||
} catch (Exception e) {
|
} else {
|
||||||
Result.of(
|
Result.of(diagnostics, result.get())
|
||||||
[*diagnostics, new Diagnostic(
|
|
||||||
"An exception occurred while rendering Template ${ template.path }:\n${ e }",
|
|
||||||
e
|
|
||||||
)],
|
|
||||||
''
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,3 +1,27 @@
|
|||||||
plugins {
|
plugins {
|
||||||
id 'groovy-gradle-plugin'
|
id 'groovy-gradle-plugin'
|
||||||
}
|
}
|
||||||
|
|
||||||
|
repositories {
|
||||||
|
maven {
|
||||||
|
url 'https://archiva.jessebrault.com/repository/internal/'
|
||||||
|
|
||||||
|
credentials {
|
||||||
|
username System.getenv('JBARCHIVA_USERNAME')
|
||||||
|
password System.getenv('JBARCHIVA_PASSWORD')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
maven {
|
||||||
|
url 'https://archiva.jessebrault.com/repository/snapshots/'
|
||||||
|
|
||||||
|
credentials {
|
||||||
|
username System.getenv('JBARCHIVA_USERNAME')
|
||||||
|
password System.getenv('JBARCHIVA_PASSWORD')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
dependencies {
|
||||||
|
implementation 'com.jessebrault.jbarchiva:jbarchiva:0.1.0'
|
||||||
|
}
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
plugins {
|
plugins {
|
||||||
|
id 'com.jessebrault.jbarchiva'
|
||||||
id 'groovy'
|
id 'groovy'
|
||||||
id 'java-library'
|
id 'java-library'
|
||||||
id 'java-test-fixtures'
|
id 'java-test-fixtures'
|
||||||
|
Loading…
Reference in New Issue
Block a user