This is an automated email from the ASF dual-hosted git repository. sgoeschl pushed a commit to branch FREEMARKER-149 in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git
commit 9235311f7c7133e816232963f6f9ce88388fa74b Author: Siegfried Goeschl <[email protected]> AuthorDate: Wed Jul 1 07:49:12 2020 +0200 FREEMARKER-149 Support multiple template transformation on the command line --- .../generator/base/template/TemplateOutput.java | 8 +++ .../base/template/TemplateTransformation.java | 8 +++ .../org/apache/freemarker/generator/cli/Main.java | 4 +- .../site/markdown/cli/concepts/transformation.md | 61 ++++++++++++++++------ 4 files changed, 62 insertions(+), 19 deletions(-) diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateOutput.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateOutput.java index 426c0f1..818d66d 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateOutput.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateOutput.java @@ -75,6 +75,14 @@ public class TemplateOutput { return writer != null ? writer : fileWriter(); } + @Override + public String toString() { + return "TemplateOutput{" + + "writer=" + writer + + ", file=" + file + + '}'; + } + private FileWriter fileWriter() { Validate.notNull(file, "Output file is null"); diff --git a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformation.java b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformation.java index b13a799..8c19478 100644 --- a/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformation.java +++ b/freemarker-generator-base/src/main/java/org/apache/freemarker/generator/base/template/TemplateTransformation.java @@ -41,4 +41,12 @@ public class TemplateTransformation { public TemplateOutput getTemplateOutput() { return templateOutput; } + + @Override + public String toString() { + return "TemplateTransformation{" + + "templateSource=" + templateSource + + ", templateOutput=" + templateOutput + + '}'; + } } diff --git a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/Main.java b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/Main.java index f9d135a..8b3b853 100644 --- a/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/Main.java +++ b/freemarker-generator-cli/src/main/java/org/apache/freemarker/generator/cli/Main.java @@ -208,6 +208,8 @@ public class Main implements Callable<Integer> { .isReadFromStdin(readFromStdin) .setArgs(args) .setConfiguration(configuration) + .setDataModels(dataModels) + .setDataSources(getCombinedDataSources()) .setDataSourceIncludePattern(dataSourceIncludePattern) .setDataSourceExcludePattern(dataSourceExcludePattern) .setInputEncoding(inputEncoding) @@ -216,8 +218,6 @@ public class Main implements Callable<Integer> { .setOutputEncoding(outputEncoding) .setOutputs(outputs) .setParameters(parameterModelSupplier.get()) - .setDataSources(getCombinedDataSources()) - .setDataModels(dataModels) .setSystemProperties(systemProperties != null ? systemProperties : new Properties()) .setTemplateDirectories(templateDirectories) .setTemplateNames(templateSourceOptions.templates) diff --git a/freemarker-generator-cli/src/site/markdown/cli/concepts/transformation.md b/freemarker-generator-cli/src/site/markdown/cli/concepts/transformation.md index f7788ee..73477eb 100644 --- a/freemarker-generator-cli/src/site/markdown/cli/concepts/transformation.md +++ b/freemarker-generator-cli/src/site/markdown/cli/concepts/transformation.md @@ -1,47 +1,74 @@ ## Transformation -The `freemarker-cli` generates text output based on FreeMarker templates and data +The `freemarker-cli` generates text output based on processing FreeMarker templates and data * A command line invocation requires 1..n `templates` and 0..n `data sources` / `data models` -* A command line invocation is mapped to a series of `transformations` -* The `transformation` consists of exactly one `template`, 0..n `data sources` / `data models` and an `output` -* An `output` is either written to +* A command line invocation is mapped to a series of `template transformations` +* The `transformation` consists of exactly one `template`, 0..n `data sources` / `data models` written to an `output` +* The `output` is either written to * `stdout` - * an output file - * an output directory + * one or more output files + * one or output directories * When the output is written to a directory * the structure of the input directory is preserved * a `ftl` file extension is removed -Transforming a single template and data source to `stdout` +### Examples + +Transforming a single template to a single output file ``` freemarker-cli \ --t templates/csv/md/transform.ftl examples/data/csv/contract.csv +-t templates/csv/md/transform.ftl examples/data/csv/contract.csv \ +-o target/contract.md ``` -Transforming multiple templates to multiple output files +Transforming multiple templates to multiple output files (1:1 mapping between templates and outputs) ``` -freemarker-cli \ +> freemarker-cli \ -t templates/csv/md/transform.ftl -o target/contract.md \ -t templates/csv/html/transform.ftl -o target/contract.html \ examples/data/csv/contract.csv + +> tree target +target +|-- contract.html +`-- contract.md ``` Transforming single template directory to single output directory ``` -freemarker-cli \ --P NGINX_HOSTNAME=localhost \ --t examples/data/template -o target/out/template1 +> freemarker-cli \ +-t examples/data/template -o target/template1 + +> tree target +target +`-- template1 + |-- application.properties + `-- nginx + `-- nginx.conf + + ``` Transforming multiple template directories to multiple output directories ``` -freemarker-cli \ --P NGINX_HOSTNAME=localhost \ --t examples/data/template -o target/out/template1 \ --t examples/data/template -o target/out/template2 +freemarker-cli \ +-t examples/data/template -o target/template1 \ +-t examples/data/template -o target/template2 + +> tree target +target +|-- template1 +| |-- application.properties +| `-- nginx +| `-- nginx.conf +`-- template2 + |-- application.properties + `-- nginx + `-- nginx.conf + ```
