Changed onDiagnostics Closure<Void> to diagnosticsConsumer Consumer<Collection<Diagnostic>>.
This commit is contained in:
parent
2af6eeddec
commit
958d3ca0ff
@ -3,9 +3,12 @@ package com.jessebrault.ssg.dsl
|
|||||||
import com.jessebrault.ssg.part.Part
|
import com.jessebrault.ssg.part.Part
|
||||||
import com.jessebrault.ssg.render.RenderContext
|
import com.jessebrault.ssg.render.RenderContext
|
||||||
import com.jessebrault.ssg.text.Text
|
import com.jessebrault.ssg.text.Text
|
||||||
|
import com.jessebrault.ssg.util.Diagnostic
|
||||||
import groovy.transform.EqualsAndHashCode
|
import groovy.transform.EqualsAndHashCode
|
||||||
import org.jetbrains.annotations.Nullable
|
import org.jetbrains.annotations.Nullable
|
||||||
|
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull
|
import static java.util.Objects.requireNonNull
|
||||||
|
|
||||||
@EqualsAndHashCode(includeFields = true)
|
@EqualsAndHashCode(includeFields = true)
|
||||||
@ -13,7 +16,7 @@ final class EmbeddablePart {
|
|||||||
|
|
||||||
private final Part part
|
private final Part part
|
||||||
private final RenderContext context
|
private final RenderContext context
|
||||||
private final Closure<Void> onDiagnostics
|
private final Consumer<Collection<Diagnostic>> diagnosticsConsumer
|
||||||
|
|
||||||
@Nullable
|
@Nullable
|
||||||
private final Text text
|
private final Text text
|
||||||
@ -21,24 +24,24 @@ final class EmbeddablePart {
|
|||||||
EmbeddablePart(
|
EmbeddablePart(
|
||||||
Part part,
|
Part part,
|
||||||
RenderContext context,
|
RenderContext context,
|
||||||
Closure<Void> onDiagnostics,
|
Consumer<Collection<Diagnostic>> diagnosticsConsumer,
|
||||||
@Nullable Text text
|
@Nullable Text text
|
||||||
) {
|
) {
|
||||||
this.part = requireNonNull(part)
|
this.part = requireNonNull(part)
|
||||||
this.context = requireNonNull(context)
|
this.context = requireNonNull(context)
|
||||||
this.onDiagnostics = requireNonNull(onDiagnostics)
|
this.diagnosticsConsumer = requireNonNull(diagnosticsConsumer)
|
||||||
this.text = text
|
this.text = text
|
||||||
}
|
}
|
||||||
|
|
||||||
String render(Map binding = [:]) {
|
String render(Map binding = [:]) {
|
||||||
def result = part.type.renderer.render(
|
def result = this.part.type.renderer.render(
|
||||||
this.part,
|
this.part,
|
||||||
binding,
|
binding,
|
||||||
this.context,
|
this.context,
|
||||||
this.text
|
this.text
|
||||||
)
|
)
|
||||||
if (result.hasDiagnostics()) {
|
if (result.hasDiagnostics()) {
|
||||||
this.onDiagnostics.call(result.diagnostics)
|
this.diagnosticsConsumer.accept(result.diagnostics)
|
||||||
''
|
''
|
||||||
} else {
|
} else {
|
||||||
result.get()
|
result.get()
|
||||||
|
@ -2,9 +2,12 @@ package com.jessebrault.ssg.dsl
|
|||||||
|
|
||||||
import com.jessebrault.ssg.render.RenderContext
|
import com.jessebrault.ssg.render.RenderContext
|
||||||
import com.jessebrault.ssg.text.Text
|
import com.jessebrault.ssg.text.Text
|
||||||
|
import com.jessebrault.ssg.util.Diagnostic
|
||||||
import groovy.transform.EqualsAndHashCode
|
import groovy.transform.EqualsAndHashCode
|
||||||
import org.jetbrains.annotations.Nullable
|
import org.jetbrains.annotations.Nullable
|
||||||
|
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
import static java.util.Objects.requireNonNull
|
import static java.util.Objects.requireNonNull
|
||||||
|
|
||||||
@EqualsAndHashCode(includeFields = true)
|
@EqualsAndHashCode(includeFields = true)
|
||||||
@ -15,13 +18,13 @@ final class EmbeddablePartsMap {
|
|||||||
|
|
||||||
EmbeddablePartsMap(
|
EmbeddablePartsMap(
|
||||||
RenderContext context,
|
RenderContext context,
|
||||||
Closure<Void> onDiagnostics,
|
Consumer<Collection<Diagnostic>> diagnosticsConsumer,
|
||||||
@Nullable Text text = null
|
@Nullable Text text = null
|
||||||
) {
|
) {
|
||||||
requireNonNull(context)
|
requireNonNull(context)
|
||||||
requireNonNull(onDiagnostics)
|
requireNonNull(diagnosticsConsumer)
|
||||||
context.parts.each {
|
context.parts.each {
|
||||||
this.put(it.path, new EmbeddablePart(it, context, onDiagnostics, text))
|
this[it.path] = new EmbeddablePart(it, context, diagnosticsConsumer, text)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -2,24 +2,27 @@ package com.jessebrault.ssg.dsl
|
|||||||
|
|
||||||
import com.jessebrault.ssg.text.FrontMatter
|
import com.jessebrault.ssg.text.FrontMatter
|
||||||
import com.jessebrault.ssg.text.Text
|
import com.jessebrault.ssg.text.Text
|
||||||
|
import com.jessebrault.ssg.util.Diagnostic
|
||||||
import groovy.transform.EqualsAndHashCode
|
import groovy.transform.EqualsAndHashCode
|
||||||
import groovy.transform.Memoized
|
import groovy.transform.Memoized
|
||||||
import groovy.transform.NullCheck
|
import groovy.transform.NullCheck
|
||||||
import groovy.transform.TupleConstructor
|
import groovy.transform.TupleConstructor
|
||||||
|
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
@TupleConstructor(includeFields = true, defaults = false)
|
@TupleConstructor(includeFields = true, defaults = false)
|
||||||
@NullCheck(includeGenerated = true)
|
@NullCheck(includeGenerated = true)
|
||||||
@EqualsAndHashCode(includeFields = true)
|
@EqualsAndHashCode(includeFields = true)
|
||||||
final class EmbeddableText {
|
final class EmbeddableText {
|
||||||
|
|
||||||
private final Text text
|
private final Text text
|
||||||
private final Closure<Void> onDiagnostics
|
private final Consumer<Collection<Diagnostic>> diagnosticsConsumer
|
||||||
|
|
||||||
@Memoized
|
@Memoized
|
||||||
String render() {
|
String render() {
|
||||||
def result = this.text.type.renderer.render(this.text)
|
def result = this.text.type.renderer.render(this.text)
|
||||||
if (result.diagnostics.size() > 0) {
|
if (result.diagnostics.size() > 0) {
|
||||||
this.onDiagnostics.call(result.diagnostics)
|
this.diagnosticsConsumer.accept(result.diagnostics)
|
||||||
''
|
''
|
||||||
} else {
|
} else {
|
||||||
result.get()
|
result.get()
|
||||||
@ -30,7 +33,7 @@ final class EmbeddableText {
|
|||||||
FrontMatter getFrontMatter() {
|
FrontMatter getFrontMatter() {
|
||||||
def result = this.text.type.frontMatterGetter.get(this.text)
|
def result = this.text.type.frontMatterGetter.get(this.text)
|
||||||
if (result.hasDiagnostics()) {
|
if (result.hasDiagnostics()) {
|
||||||
this.onDiagnostics.call(result.diagnostics)
|
this.diagnosticsConsumer.accept(result.diagnostics)
|
||||||
new FrontMatter(this.text, [:])
|
new FrontMatter(this.text, [:])
|
||||||
} else {
|
} else {
|
||||||
result.get()
|
result.get()
|
||||||
@ -41,7 +44,7 @@ final class EmbeddableText {
|
|||||||
String getExcerpt(int limit) {
|
String getExcerpt(int limit) {
|
||||||
def result = this.text.type.excerptGetter.getExcerpt(this.text, limit)
|
def result = this.text.type.excerptGetter.getExcerpt(this.text, limit)
|
||||||
if (result.hasDiagnostics()) {
|
if (result.hasDiagnostics()) {
|
||||||
this.onDiagnostics.call(result.diagnostics)
|
this.diagnosticsConsumer.accept(result.diagnostics)
|
||||||
''
|
''
|
||||||
} else {
|
} else {
|
||||||
result.get()
|
result.get()
|
||||||
|
@ -1,9 +1,12 @@
|
|||||||
package com.jessebrault.ssg.dsl
|
package com.jessebrault.ssg.dsl
|
||||||
|
|
||||||
import com.jessebrault.ssg.text.Text
|
import com.jessebrault.ssg.text.Text
|
||||||
|
import com.jessebrault.ssg.util.Diagnostic
|
||||||
import groovy.transform.EqualsAndHashCode
|
import groovy.transform.EqualsAndHashCode
|
||||||
import groovy.transform.NullCheck
|
import groovy.transform.NullCheck
|
||||||
|
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
@NullCheck
|
@NullCheck
|
||||||
@EqualsAndHashCode(includeFields = true)
|
@EqualsAndHashCode(includeFields = true)
|
||||||
final class EmbeddableTextsCollection {
|
final class EmbeddableTextsCollection {
|
||||||
@ -11,9 +14,9 @@ final class EmbeddableTextsCollection {
|
|||||||
@Delegate
|
@Delegate
|
||||||
private final Collection<EmbeddableText> embeddableTexts = []
|
private final Collection<EmbeddableText> embeddableTexts = []
|
||||||
|
|
||||||
EmbeddableTextsCollection(Collection<Text> texts, Closure<Void> onDiagnostics) {
|
EmbeddableTextsCollection(Collection<Text> texts, Consumer<Collection<Diagnostic>> diagnosticsConsumer) {
|
||||||
texts.each {
|
texts.each {
|
||||||
this << new EmbeddableText(it, onDiagnostics)
|
this << new EmbeddableText(it, diagnosticsConsumer)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,11 +4,12 @@ import com.jessebrault.ssg.dsl.tagbuilder.DynamicTagBuilder
|
|||||||
import com.jessebrault.ssg.dsl.urlbuilder.PathBasedUrlBuilder
|
import com.jessebrault.ssg.dsl.urlbuilder.PathBasedUrlBuilder
|
||||||
import com.jessebrault.ssg.render.RenderContext
|
import com.jessebrault.ssg.render.RenderContext
|
||||||
import com.jessebrault.ssg.text.Text
|
import com.jessebrault.ssg.text.Text
|
||||||
|
import com.jessebrault.ssg.util.Diagnostic
|
||||||
import groovy.transform.NullCheck
|
import groovy.transform.NullCheck
|
||||||
import groovy.transform.stc.ClosureParams
|
|
||||||
import groovy.transform.stc.SimpleType
|
|
||||||
import org.slf4j.LoggerFactory
|
import org.slf4j.LoggerFactory
|
||||||
|
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
final class StandardDslMap {
|
final class StandardDslMap {
|
||||||
|
|
||||||
@NullCheck(includeGenerated = true)
|
@NullCheck(includeGenerated = true)
|
||||||
@ -16,8 +17,8 @@ final class StandardDslMap {
|
|||||||
|
|
||||||
private final Map<String, Object> custom = [:]
|
private final Map<String, Object> custom = [:]
|
||||||
|
|
||||||
|
Consumer<Collection<Diagnostic>> diagnosticsConsumer = { }
|
||||||
String loggerName = ''
|
String loggerName = ''
|
||||||
Closure<Void> onDiagnostics = { }
|
|
||||||
Text text = null
|
Text text = null
|
||||||
|
|
||||||
void putCustom(String key, Object value) {
|
void putCustom(String key, Object value) {
|
||||||
@ -32,17 +33,10 @@ final class StandardDslMap {
|
|||||||
|
|
||||||
static Map<String, Object> get(
|
static Map<String, Object> get(
|
||||||
RenderContext context,
|
RenderContext context,
|
||||||
@DelegatesTo(value = Builder, strategy = Closure.DELEGATE_FIRST)
|
Consumer<Builder> builderConsumer
|
||||||
@ClosureParams(
|
|
||||||
value = SimpleType,
|
|
||||||
options = ['com.jessebrault.ssg.dsl.StandardDslMap.Builder']
|
|
||||||
)
|
|
||||||
Closure<Void> builderClosure
|
|
||||||
) {
|
) {
|
||||||
def b = new Builder()
|
def b = new Builder()
|
||||||
builderClosure.resolveStrategy = Closure.DELEGATE_FIRST
|
builderConsumer.accept(b)
|
||||||
builderClosure.delegate = b
|
|
||||||
builderClosure(b)
|
|
||||||
|
|
||||||
[:].tap {
|
[:].tap {
|
||||||
// standard variables
|
// standard variables
|
||||||
@ -51,7 +45,7 @@ final class StandardDslMap {
|
|||||||
it.models = new ModelCollection<Object>(context.models)
|
it.models = new ModelCollection<Object>(context.models)
|
||||||
it.parts = new EmbeddablePartsMap(
|
it.parts = new EmbeddablePartsMap(
|
||||||
context,
|
context,
|
||||||
b.onDiagnostics,
|
b.diagnosticsConsumer,
|
||||||
b.text
|
b.text
|
||||||
)
|
)
|
||||||
it.siteSpec = context.siteSpec
|
it.siteSpec = context.siteSpec
|
||||||
@ -61,11 +55,11 @@ final class StandardDslMap {
|
|||||||
it.tasks = new TaskCollection(context.tasks)
|
it.tasks = new TaskCollection(context.tasks)
|
||||||
it.text = b.text ? new EmbeddableText(
|
it.text = b.text ? new EmbeddableText(
|
||||||
b.text,
|
b.text,
|
||||||
b.onDiagnostics
|
b.diagnosticsConsumer
|
||||||
) : null
|
) : null
|
||||||
it.texts = new EmbeddableTextsCollection(
|
it.texts = new EmbeddableTextsCollection(
|
||||||
context.texts,
|
context.texts,
|
||||||
b.onDiagnostics
|
b.diagnosticsConsumer
|
||||||
)
|
)
|
||||||
it.urlBuilder = new PathBasedUrlBuilder(
|
it.urlBuilder = new PathBasedUrlBuilder(
|
||||||
context.targetPath,
|
context.targetPath,
|
||||||
|
@ -21,9 +21,8 @@ final class GspPageRenderer implements PageRenderer {
|
|||||||
def diagnostics = []
|
def diagnostics = []
|
||||||
try {
|
try {
|
||||||
def result = this.gspRenderer.render(specialPage.text, context) {
|
def result = this.gspRenderer.render(specialPage.text, context) {
|
||||||
|
it.diagnosticsConsumer = diagnostics.&addAll
|
||||||
it.loggerName = "GspSpecialPage(${ specialPage.path })"
|
it.loggerName = "GspSpecialPage(${ specialPage.path })"
|
||||||
it.onDiagnostics = diagnostics.&addAll
|
|
||||||
return
|
|
||||||
}
|
}
|
||||||
Result.of(diagnostics, result.toString())
|
Result.of(diagnostics, result.toString())
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -1,10 +1,10 @@
|
|||||||
package com.jessebrault.ssg.part
|
package com.jessebrault.ssg.part
|
||||||
|
|
||||||
import com.jessebrault.ssg.render.StandardGspRenderer
|
|
||||||
import com.jessebrault.ssg.util.Diagnostic
|
|
||||||
import com.jessebrault.ssg.render.RenderContext
|
import com.jessebrault.ssg.render.RenderContext
|
||||||
import com.jessebrault.ssg.util.Result
|
import com.jessebrault.ssg.render.StandardGspRenderer
|
||||||
import com.jessebrault.ssg.text.Text
|
import com.jessebrault.ssg.text.Text
|
||||||
|
import com.jessebrault.ssg.util.Diagnostic
|
||||||
|
import com.jessebrault.ssg.util.Result
|
||||||
import groovy.transform.EqualsAndHashCode
|
import groovy.transform.EqualsAndHashCode
|
||||||
import org.jetbrains.annotations.Nullable
|
import org.jetbrains.annotations.Nullable
|
||||||
|
|
||||||
@ -29,12 +29,11 @@ final class GspPartRenderer implements PartRenderer {
|
|||||||
try {
|
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.loggerName = "GspPart(${ part.path })"
|
it.loggerName = "GspPart(${ part.path })"
|
||||||
it.onDiagnostics = diagnostics.&addAll
|
|
||||||
if (text) {
|
if (text) {
|
||||||
it.text = text
|
it.text = text
|
||||||
}
|
}
|
||||||
return
|
|
||||||
}
|
}
|
||||||
Result.of(diagnostics, result.toString())
|
Result.of(diagnostics, result.toString())
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
@ -5,6 +5,8 @@ import groovy.text.GStringTemplateEngine
|
|||||||
import groovy.text.TemplateEngine
|
import groovy.text.TemplateEngine
|
||||||
import org.codehaus.groovy.control.CompilerConfiguration
|
import org.codehaus.groovy.control.CompilerConfiguration
|
||||||
|
|
||||||
|
import java.util.function.Consumer
|
||||||
|
|
||||||
final class StandardGspRenderer {
|
final class StandardGspRenderer {
|
||||||
|
|
||||||
private final TemplateEngine engine
|
private final TemplateEngine engine
|
||||||
@ -18,10 +20,9 @@ final class StandardGspRenderer {
|
|||||||
String render(
|
String render(
|
||||||
String template,
|
String template,
|
||||||
RenderContext context,
|
RenderContext context,
|
||||||
@DelegatesTo(value = StandardDslMap.Builder, strategy = Closure.DELEGATE_FIRST)
|
Consumer<StandardDslMap.Builder> dslMapBuilderConsumer
|
||||||
Closure<Void> dslMapBuilderClosure
|
|
||||||
) {
|
) {
|
||||||
this.engine.createTemplate(template).make(StandardDslMap.get(context, dslMapBuilderClosure)).toString()
|
this.engine.createTemplate(template).make(StandardDslMap.get(context, dslMapBuilderConsumer)).toString()
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -23,10 +23,9 @@ final class GspTemplateRenderer implements TemplateRenderer {
|
|||||||
def diagnostics = []
|
def diagnostics = []
|
||||||
try {
|
try {
|
||||||
def result = this.gspRenderer.render(template.text, context) {
|
def result = this.gspRenderer.render(template.text, context) {
|
||||||
|
it.diagnosticsConsumer = diagnostics.&addAll
|
||||||
it.loggerName = "GspTemplate(${ template.path })"
|
it.loggerName = "GspTemplate(${ template.path })"
|
||||||
it.onDiagnostics = diagnostics.&addAll
|
|
||||||
it.text = text
|
it.text = text
|
||||||
return
|
|
||||||
}
|
}
|
||||||
Result.of(diagnostics, result)
|
Result.of(diagnostics, result)
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
|
Loading…
Reference in New Issue
Block a user