Search in sources :

Example 1 with RstTemplateHelper

use of com.github.jcustenborder.kafka.connect.utils.templates.rst.RstTemplateHelper in project connect-utils by jcustenborder.

the class BaseDocumentationTest method process.

void process(Writer writer, Template template, Object input) throws IOException, TemplateException {
    Map<String, Object> variables = ImmutableMap.of("input", input, "rstHelper", new RstTemplateHelper(), "markdownHelper", new MarkdownTemplateHelper());
    template.process(variables, writer);
}
Also used : RstTemplateHelper(com.github.jcustenborder.kafka.connect.utils.templates.rst.RstTemplateHelper) MarkdownTemplateHelper(com.github.jcustenborder.kafka.connect.utils.templates.markdown.MarkdownTemplateHelper)

Example 2 with RstTemplateHelper

use of com.github.jcustenborder.kafka.connect.utils.templates.rst.RstTemplateHelper in project connect-utils by jcustenborder.

the class BaseDocumentationTest method schema.

@TestFactory
public Stream<DynamicTest> schema() throws IOException {
    final File parentDirectory = new File(outputDirectory, "schemas");
    if (!parentDirectory.exists()) {
        parentDirectory.mkdirs();
    }
    List<Schema> schemas = schemas();
    if (null != schemas && !schemas.isEmpty()) {
        final File schemaRstPath = new File(outputDirectory, "schemas.rst");
        final String schemaRst = "=======\n" + "Schemas\n" + "=======\n" + "\n" + ".. toctree::\n" + "    :maxdepth: 0\n" + "    :caption: Schemas:\n" + "    :glob:\n" + "\n" + "    schemas/*";
        Files.write(schemaRst, schemaRstPath, Charsets.UTF_8);
    }
    final String templateName = "rst/schema.rst.ftl";
    return this.schemas().stream().filter(schema -> !Strings.isNullOrEmpty(schema.name())).map(schema -> dynamicTest(String.format("%s.%s", schema.type(), schema.name()), () -> {
        StringBuilder filenameBuilder = new StringBuilder().append(schema.type().toString().toLowerCase());
        if (!Strings.isNullOrEmpty(schema.name())) {
            filenameBuilder.append('.').append(schema.name());
        }
        filenameBuilder.append(".rst");
        File outputFile = new File(parentDirectory, filenameBuilder.toString());
        Template template = configuration.getTemplate(templateName);
        log.info("Writing {}", outputFile);
        try (Writer writer = Files.newWriter(outputFile, Charsets.UTF_8)) {
            Map<String, Object> variables = ImmutableMap.of("input", TemplateSchema.of(schema), "helper", new RstTemplateHelper());
            template.process(variables, writer);
        }
    }));
}
Also used : Graphviz(guru.nidi.graphviz.engine.Graphviz) BeforeEach(org.junit.jupiter.api.BeforeEach) Arrays(java.util.Arrays) BeansWrapper(freemarker.ext.beans.BeansWrapper) TestFactory(org.junit.jupiter.api.TestFactory) Factory.node(guru.nidi.graphviz.model.Factory.node) LoggerFactory(org.slf4j.LoggerFactory) ConnectorTemplate(com.github.jcustenborder.kafka.connect.utils.templates.ConnectorTemplate) Reflections(org.reflections.Reflections) Schema(org.apache.kafka.connect.data.Schema) Transformation(org.apache.kafka.connect.transforms.Transformation) SourceConnector(org.apache.kafka.connect.source.SourceConnector) BeforeAll(org.junit.jupiter.api.BeforeAll) Factory.to(guru.nidi.graphviz.model.Factory.to) DynamicTest.dynamicTest(org.junit.jupiter.api.DynamicTest.dynamicTest) Map(java.util.Map) Graph(guru.nidi.graphviz.model.Graph) ConfigDef(org.apache.kafka.common.config.ConfigDef) ImmutableSet(com.google.common.collect.ImmutableSet) ImmutableMap(com.google.common.collect.ImmutableMap) Set(java.util.Set) Collectors(java.util.stream.Collectors) ClasspathHelper(org.reflections.util.ClasspathHelper) Test(org.junit.jupiter.api.Test) List(java.util.List) Factory.graph(guru.nidi.graphviz.model.Factory.graph) Stream(java.util.stream.Stream) Modifier(java.lang.reflect.Modifier) Writer(java.io.Writer) MarkdownTemplateHelper(com.github.jcustenborder.kafka.connect.utils.templates.markdown.MarkdownTemplateHelper) TemplateSchema(com.github.jcustenborder.kafka.connect.utils.templates.TemplateSchema) TemplateException(freemarker.template.TemplateException) ClassTemplateLoader(freemarker.cache.ClassTemplateLoader) ArrayList(java.util.ArrayList) Strings(com.google.common.base.Strings) ImmutableList(com.google.common.collect.ImmutableList) Format(guru.nidi.graphviz.engine.Format) Files(com.google.common.io.Files) Template(freemarker.template.Template) Shape(guru.nidi.graphviz.attribute.Shape) ConfigurationBuilder(org.reflections.util.ConfigurationBuilder) TransformationTemplate(com.github.jcustenborder.kafka.connect.utils.templates.TransformationTemplate) SinkConnector(org.apache.kafka.connect.sink.SinkConnector) Charsets(com.google.common.base.Charsets) Logger(org.slf4j.Logger) MalformedURLException(java.net.MalformedURLException) RankDir(guru.nidi.graphviz.attribute.RankDir) StringWriter(java.io.StringWriter) IOException(java.io.IOException) File(java.io.File) Label(guru.nidi.graphviz.model.Label) Configuration(freemarker.template.Configuration) PluginTemplate(com.github.jcustenborder.kafka.connect.utils.templates.PluginTemplate) SourceConnectorTemplate(com.github.jcustenborder.kafka.connect.utils.templates.SourceConnectorTemplate) DynamicTest(org.junit.jupiter.api.DynamicTest) RstTemplateHelper(com.github.jcustenborder.kafka.connect.utils.templates.rst.RstTemplateHelper) Comparator(java.util.Comparator) RstTemplateHelper(com.github.jcustenborder.kafka.connect.utils.templates.rst.RstTemplateHelper) Schema(org.apache.kafka.connect.data.Schema) TemplateSchema(com.github.jcustenborder.kafka.connect.utils.templates.TemplateSchema) File(java.io.File) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Writer(java.io.Writer) StringWriter(java.io.StringWriter) ConnectorTemplate(com.github.jcustenborder.kafka.connect.utils.templates.ConnectorTemplate) Template(freemarker.template.Template) TransformationTemplate(com.github.jcustenborder.kafka.connect.utils.templates.TransformationTemplate) PluginTemplate(com.github.jcustenborder.kafka.connect.utils.templates.PluginTemplate) SourceConnectorTemplate(com.github.jcustenborder.kafka.connect.utils.templates.SourceConnectorTemplate) TestFactory(org.junit.jupiter.api.TestFactory)

Aggregations

MarkdownTemplateHelper (com.github.jcustenborder.kafka.connect.utils.templates.markdown.MarkdownTemplateHelper)2 RstTemplateHelper (com.github.jcustenborder.kafka.connect.utils.templates.rst.RstTemplateHelper)2 ConnectorTemplate (com.github.jcustenborder.kafka.connect.utils.templates.ConnectorTemplate)1 PluginTemplate (com.github.jcustenborder.kafka.connect.utils.templates.PluginTemplate)1 SourceConnectorTemplate (com.github.jcustenborder.kafka.connect.utils.templates.SourceConnectorTemplate)1 TemplateSchema (com.github.jcustenborder.kafka.connect.utils.templates.TemplateSchema)1 TransformationTemplate (com.github.jcustenborder.kafka.connect.utils.templates.TransformationTemplate)1 Charsets (com.google.common.base.Charsets)1 Strings (com.google.common.base.Strings)1 ImmutableList (com.google.common.collect.ImmutableList)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ImmutableSet (com.google.common.collect.ImmutableSet)1 Files (com.google.common.io.Files)1 ClassTemplateLoader (freemarker.cache.ClassTemplateLoader)1 BeansWrapper (freemarker.ext.beans.BeansWrapper)1 Configuration (freemarker.template.Configuration)1 Template (freemarker.template.Template)1 TemplateException (freemarker.template.TemplateException)1 RankDir (guru.nidi.graphviz.attribute.RankDir)1 Shape (guru.nidi.graphviz.attribute.Shape)1