You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@freemarker.apache.org by sg...@apache.org on 2020/06/18 15:03:39 UTC

[freemarker-generator] branch FREEMARKER-146 updated: FREEMARKER-146 Cleanly separate example templates and data from user-supplied content

This is an automated email from the ASF dual-hosted git repository.

sgoeschl pushed a commit to branch FREEMARKER-146
in repository https://gitbox.apache.org/repos/asf/freemarker-generator.git


The following commit(s) were added to refs/heads/FREEMARKER-146 by this push:
     new d32d68a  FREEMARKER-146 Cleanly separate example templates and data from user-supplied content
d32d68a is described below

commit d32d68a83f338da8e5357b1e084e17af4cac88eb
Author: Siegfried Goeschl <si...@gmail.com>
AuthorDate: Thu Jun 18 17:03:26 2020 +0200

    FREEMARKER-146 Cleanly separate example templates and data from user-supplied content
---
 freemarker-generator-cli/README.md                 | 24 ++++++++++----------
 freemarker-generator-cli/run-examples.sh           | 26 +++++++++++-----------
 .../src/main/scripts/run-examples.sh               | 26 +++++++++++-----------
 .../freemarker/generator/cli/ExamplesTest.java     | 16 ++++++-------
 .../freemarker/generator/cli/ManualTest.java       |  2 +-
 .../{examples => }/templates/csv/csv/transform.ftl |  0
 .../templates/csv/html/transform.ftl               |  0
 .../{examples => }/templates/csv/md/transform.ftl  |  0
 .../templates/excel/csv/transform.ftl              |  0
 .../templates/excel/html/transform.ftl             |  0
 .../templates/excel/md/transform.ftl               |  0
 11 files changed, 47 insertions(+), 47 deletions(-)

diff --git a/freemarker-generator-cli/README.md b/freemarker-generator-cli/README.md
index 2f42273..7f7a709 100644
--- a/freemarker-generator-cli/README.md
+++ b/freemarker-generator-cli/README.md
@@ -133,7 +133,7 @@ There a many examples (see below) available you can execute - run `./run-example
 ./run-examples.sh 
 templates/info.ftl
 examples/templates/demo.ftl
-examples/templates/csv/html/transform.ftl
+templates/csv/html/transform.ftl
 examples/templates/csv/md/transform.ftl
 examples/templates/csv/shell/curl.ftl
 examples/templates/csv/md/filter.ftl
@@ -141,14 +141,14 @@ examples/templates/csv/fo/transform.ftl
 fop -fo target/out/locker-test-users.fo target/out/locker-test-users.pdf
 examples/templates/csv/fo/transactions.ftl
 fop -fo target/out/transactions.fo target/out/transactions-fo.pdf
-examples/templates/csv/html/transform.ftl
+templates/csv/html/transform.ftl
 wkhtmltopdf -O landscape target/out/transactions.html target/out/transactions-html.pdf
 examples/templates/dataframe/example.ftl
 examples/templates/accesslog/combined-access.ftl
 examples/templates/excel/dataframe/transform.ftl
-examples/templates/excel/html/transform.ftl
-examples/templates/excel/md/transform.ftl
-examples/templates/excel/csv/transform.ftl
+templates/excel/html/transform.ftl
+templates/excel/md/transform.ftl
+templates/excel/csv/transform.ftl
 examples/templates/excel/csv/custom.ftl
 examples/templates/html/csv/dependencies.ftl
 examples/templates/json/csv/swagger-endpoints.ftl
@@ -307,8 +307,8 @@ creates the following output
 Sometimes you have a CSV file which needs to be translated in Markdown or HTML - there are on-line solutions available such as [CSV To Markdown Table Generator](https://donatstudios.com/CsvToMarkdownTable) but having a local solution gives you more flexibility.
 
 ```text
-> ./bin/freemarker-cli -t examples/templates/csv/md/transform.ftl examples/data/csv/contract.csv
-> ./bin/freemarker-cli -t examples/templates/csv/html/transform.ftl examples/data/csv/contract.csv
+> ./bin/freemarker-cli -t templates/csv/md/transform.ftl examples/data/csv/contract.csv
+> ./bin/freemarker-cli -t templates/csv/html/transform.ftl examples/data/csv/contract.csv
 ```
 
 The FreeMarker template is shown below
@@ -452,10 +452,10 @@ ENDPOINT;METHOD;CONSUMES;PRODUCES;SUMMARY;DESCRIPTION
 Another day my project management asked me to create a CSV configuration file based on an Excel documents - as usual manual copying was not an option due to required data cleanup and data transformation. So I thought about Apache POI which support XLS and XLSX documents - integration of Apache POI was a breeze but the resulting code was not particularly useful example. So a more generic transformation was provided to show the transformation of Excel documents ...
 
 ```text
-> ./bin/freemarker-cli -t examples/templates/excel/html/transform.ftl examples/data/excel/test.xls
-> ./bin/freemarker-cli -t examples/templates/excel/html/transform.ftl examples/data/excel/test.xlsx
-> ./bin/freemarker-cli -t examples/templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx
-> ./bin/freemarker-cli -t examples/templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx
+> ./bin/freemarker-cli -t templates/excel/html/transform.ftl examples/data/excel/test.xls
+> ./bin/freemarker-cli -t templates/excel/html/transform.ftl examples/data/excel/test.xlsx
+> ./bin/freemarker-cli -t templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx
+> ./bin/freemarker-cli -t templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx
 ```
 
 The provided FTL transforms an Excel into a HTML document supporting multiple Excel sheets
@@ -894,7 +894,7 @@ While this looks small and tidy there are some nifty features
 
 Sometimes you have a CSV file which is not quite right - you need to change the format. Lets have a look how `freemarker-cli` can help
 
-> bin/freemarker-cli -PCVS_IN_DELIMITER=COMMA -PCSV_OUT_DELIMITER=PIPE -t examples/templates/csv/csv/transform.ftl ./examples/data/csv/contract.csv 
+> bin/freemarker-cli -PCVS_IN_DELIMITER=COMMA -PCSV_OUT_DELIMITER=PIPE -t templates/csv/csv/transform.ftl ./examples/data/csv/contract.csv 
 
 renders the following template
 
diff --git a/freemarker-generator-cli/run-examples.sh b/freemarker-generator-cli/run-examples.sh
index 52e6eb3..6b68e16 100755
--- a/freemarker-generator-cli/run-examples.sh
+++ b/freemarker-generator-cli/run-examples.sh
@@ -57,11 +57,11 @@ $FREEMARKER_CMD -i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(
 # CSV
 #############################################################################
 
-echo "examples/templates/csv/html/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/csv/html/transform.ftl examples/data/csv/contract.csv > target/out/contract.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/csv/html/transform.ftl"
+$FREEMARKER_CMD -t templates/csv/html/transform.ftl examples/data/csv/contract.csv > target/out/contract.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
-echo "examples/templates/csv/md/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/csv/md/transform.ftl examples/data/csv/contract.csv > target/out/contract.md || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/csv/md/transform.ftl"
+$FREEMARKER_CMD -t templates/csv/md/transform.ftl examples/data/csv/contract.csv > target/out/contract.md || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
 echo "examples/templates/csv/shell/curl.ftl"
 $FREEMARKER_CMD -t ./examples/templates/csv/shell/curl.ftl examples/data/csv/user.csv > target/out/curl.sh || { echo >&2 "Test failed.  Aborting."; exit 1; }
@@ -93,7 +93,7 @@ fi
 # CSV to HTML & PDF
 #############################################################################
 
-echo "examples/templates/csv/html/transform.ftl"
+echo "templates/csv/html/transform.ftl"
 $FREEMARKER_CMD -t examples/templates/csv/html/transactions.ftl examples/data/csv/transactions.csv > target/out/transactions.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
 if hash wkhtmltopdf 2>/dev/null; then
@@ -122,16 +122,16 @@ $FREEMARKER_CMD -t examples/templates/accesslog/combined-access.ftl examples/dat
 echo "examples/templates/excel/dataframe/transform.ftl"
 $FREEMARKER_CMD -t examples/templates/excel/dataframe/transform.ftl examples/data/excel/test.xls > target/out/test.xls.dataframe.txt || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
-echo "examples/templates/excel/html/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/excel/html/transform.ftl examples/data/excel/test.xls > target/out/test.xls.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
-$FREEMARKER_CMD -t examples/templates/excel/html/transform.ftl examples/data/excel/test.xlsx > target/out/test.xslx.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
-$FREEMARKER_CMD -t examples/templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/excel/html/transform.ftl"
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test.xls > target/out/test.xls.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test.xlsx > target/out/test.xslx.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
-echo "examples/templates/excel/md/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.md || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/excel/md/transform.ftl"
+$FREEMARKER_CMD -t templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.md || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
-echo "examples/templates/excel/csv/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/excel/csv/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.csv || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/excel/csv/transform.ftl"
+$FREEMARKER_CMD -t templates/excel/csv/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.csv || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
 echo "examples/templates/excel/csv/custom.ftl"
 $FREEMARKER_CMD -t examples/templates/excel/csv/custom.ftl -Pcsv.format=MYSQL examples/data/excel/test.xls > target/out/test-transform-xls.csv || { echo >&2 "Test failed.  Aborting."; exit 1; }
diff --git a/freemarker-generator-cli/src/main/scripts/run-examples.sh b/freemarker-generator-cli/src/main/scripts/run-examples.sh
index 735e936..e65b6d8 100755
--- a/freemarker-generator-cli/src/main/scripts/run-examples.sh
+++ b/freemarker-generator-cli/src/main/scripts/run-examples.sh
@@ -57,11 +57,11 @@ $FREEMARKER_CMD -i '${DataFrameTool.print(DataFrameTool.fromMaps(GsonTool.parse(
 # CSV
 #############################################################################
 
-echo "examples/templates/csv/html/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/csv/html/transform.ftl examples/data/csv/contract.csv > target/out/contract.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/csv/html/transform.ftl"
+$FREEMARKER_CMD -t templates/csv/html/transform.ftl examples/data/csv/contract.csv > target/out/contract.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
-echo "examples/templates/csv/md/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/csv/md/transform.ftl examples/data/csv/contract.csv > target/out/contract.md || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/csv/md/transform.ftl"
+$FREEMARKER_CMD -t templates/csv/md/transform.ftl examples/data/csv/contract.csv > target/out/contract.md || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
 echo "examples/templates/csv/shell/curl.ftl"
 $FREEMARKER_CMD -t ./examples/templates/csv/shell/curl.ftl examples/data/csv/user.csv > target/out/curl.sh || { echo >&2 "Test failed.  Aborting."; exit 1; }
@@ -93,7 +93,7 @@ fi
 # CSV to HTML & PDF
 #############################################################################
 
-echo "examples/templates/csv/html/transform.ftl"
+echo "templates/csv/html/transform.ftl"
 $FREEMARKER_CMD -t examples/templates/csv/html/transactions.ftl examples/data/csv/transactions.csv > target/out/transactions.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
 if hash wkhtmltopdf 2>/dev/null; then
@@ -122,16 +122,16 @@ $FREEMARKER_CMD -t examples/templates/accesslog/combined-access.ftl examples/dat
 echo "examples/templates/excel/dataframe/transform.ftl"
 $FREEMARKER_CMD -t examples/templates/excel/dataframe/transform.ftl examples/data/excel/test.xls > target/out/test.xls.dataframe.txt || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
-echo "examples/templates/excel/html/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/excel/html/transform.ftl examples/data/excel/test.xls > target/out/test.xls.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
-$FREEMARKER_CMD -t examples/templates/excel/html/transform.ftl examples/data/excel/test.xlsx > target/out/test.xslx.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
-$FREEMARKER_CMD -t examples/templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/excel/html/transform.ftl"
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test.xls > target/out/test.xls.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test.xlsx > target/out/test.xslx.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
+$FREEMARKER_CMD -t templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.html || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
-echo "examples/templates/excel/md/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.md || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/excel/md/transform.ftl"
+$FREEMARKER_CMD -t templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.md || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
-echo "examples/templates/excel/csv/transform.ftl"
-$FREEMARKER_CMD -t examples/templates/excel/csv/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.csv || { echo >&2 "Test failed.  Aborting."; exit 1; }
+echo "templates/excel/csv/transform.ftl"
+$FREEMARKER_CMD -t templates/excel/csv/transform.ftl examples/data/excel/test-multiple-sheets.xlsx > target/out/test-multiple-sheets.xlsx.csv || { echo >&2 "Test failed.  Aborting."; exit 1; }
 
 echo "examples/templates/excel/csv/custom.ftl"
 $FREEMARKER_CMD -t examples/templates/excel/csv/custom.ftl -Pcsv.format=MYSQL examples/data/excel/test.xls > target/out/test-transform-xls.csv || { echo >&2 "Test failed.  Aborting."; exit 1; }
diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java
index b651a8f..a9dff72 100644
--- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java
+++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ExamplesTest.java
@@ -45,22 +45,22 @@ public class ExamplesTest extends AbstractMainTest {
 
     @Test
     public void shouldRunCsvExamples() throws IOException {
-        assertValid(execute("-t examples/templates/csv/html/transform.ftl examples/data/csv/contract.csv"));
-        assertValid(execute("-t examples/templates/csv/md/transform.ftl examples/data/csv/contract.csv"));
+        assertValid(execute("-t templates/csv/html/transform.ftl examples/data/csv/contract.csv"));
+        assertValid(execute("-t templates/csv/md/transform.ftl examples/data/csv/contract.csv"));
         assertValid(execute("-t examples/templates/csv/shell/curl.ftl examples/data/csv/user.csv"));
         assertValid(execute("-t examples/templates/csv/fo/transform.ftl examples/data/csv/locker-test-users.csv"));
         assertValid(execute("-t examples/templates/csv/fo/transactions.ftl examples/data/csv/transactions.csv"));
         assertValid(execute("-t examples/templates/csv/html/transactions.ftl examples/data/csv/transactions.csv"));
-        assertValid(execute("-t examples/templates/csv/csv/transform.ftl examples/data/csv/contract.csv"));
+        assertValid(execute("-t templates/csv/csv/transform.ftl examples/data/csv/contract.csv"));
     }
 
     @Test
     public void shouldRunExcelExamples() throws IOException {
-        assertValid(execute("-t examples/templates/excel/html/transform.ftl examples/data/excel/test.xls"));
-        assertValid(execute("-t examples/templates/excel/html/transform.ftl examples/data/excel/test.xlsx"));
-        assertValid(execute("-t examples/templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
-        assertValid(execute("-t examples/templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
-        assertValid(execute("-t examples/templates/excel/csv/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
+        assertValid(execute("-t templates/excel/html/transform.ftl examples/data/excel/test.xls"));
+        assertValid(execute("-t templates/excel/html/transform.ftl examples/data/excel/test.xlsx"));
+        assertValid(execute("-t templates/excel/html/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
+        assertValid(execute("-t templates/excel/md/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
+        assertValid(execute("-t templates/excel/csv/transform.ftl examples/data/excel/test-multiple-sheets.xlsx"));
         assertValid(execute("-t examples/templates/excel/csv/custom.ftl -Pcsv.format=MYSQL examples/data/excel/test.xls"));
         assertValid(execute("-t examples/templates/excel/dataframe/transform.ftl examples/data/excel/test.xls"));
     }
diff --git a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ManualTest.java b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ManualTest.java
index 91be862..fa33e18 100644
--- a/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ManualTest.java
+++ b/freemarker-generator-cli/src/test/java/org/apache/freemarker/generator/cli/ManualTest.java
@@ -25,7 +25,7 @@ public class ManualTest {
 
     private static final String SPACE = " ";
     // private static final String CMD = "-DCSV_TOOL_DELIMITER=SEMICOLON -DCSV_TOOL_HEADERS=true -t examples/templates/dataframe/example.ftl https://raw.githubusercontent.com/nRo/DataFrame/master/src/test/resources/users.csv";
-    private static final String CMD = "-PCSV_OUT_FORMAT=EXCEL -t examples/templates/csv/csv/transform.ftl examples/data/csv/contract.csv";
+    private static final String CMD = "-PCSV_OUT_FORMAT=EXCEL -t templates/csv/csv/transform.ftl examples/data/csv/contract.csv";
 
 
     public static void main(String[] args) {
diff --git a/freemarker-generator-cli/examples/templates/csv/csv/transform.ftl b/freemarker-generator-cli/templates/csv/csv/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/examples/templates/csv/csv/transform.ftl
rename to freemarker-generator-cli/templates/csv/csv/transform.ftl
diff --git a/freemarker-generator-cli/examples/templates/csv/html/transform.ftl b/freemarker-generator-cli/templates/csv/html/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/examples/templates/csv/html/transform.ftl
rename to freemarker-generator-cli/templates/csv/html/transform.ftl
diff --git a/freemarker-generator-cli/examples/templates/csv/md/transform.ftl b/freemarker-generator-cli/templates/csv/md/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/examples/templates/csv/md/transform.ftl
rename to freemarker-generator-cli/templates/csv/md/transform.ftl
diff --git a/freemarker-generator-cli/examples/templates/excel/csv/transform.ftl b/freemarker-generator-cli/templates/excel/csv/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/examples/templates/excel/csv/transform.ftl
rename to freemarker-generator-cli/templates/excel/csv/transform.ftl
diff --git a/freemarker-generator-cli/examples/templates/excel/html/transform.ftl b/freemarker-generator-cli/templates/excel/html/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/examples/templates/excel/html/transform.ftl
rename to freemarker-generator-cli/templates/excel/html/transform.ftl
diff --git a/freemarker-generator-cli/examples/templates/excel/md/transform.ftl b/freemarker-generator-cli/templates/excel/md/transform.ftl
similarity index 100%
rename from freemarker-generator-cli/examples/templates/excel/md/transform.ftl
rename to freemarker-generator-cli/templates/excel/md/transform.ftl