From b10df6cd65be31fbe73cea89b3d924a6451adf85 Mon Sep 17 00:00:00 2001 From: Guilherme Thomazi Bonicontro Date: Tue, 6 Aug 2024 14:04:56 +0200 Subject: [PATCH] initial templating tests --- templates/papers.tmpl | 22 ++++++++++++++++++++++ templates/test/TMZ-MyArticle.txt | 1 + templates/test/output/blabla.html | 17 +++++++++++++++++ templates/test/render.sh | 23 +++++++++++++++++++++++ 4 files changed, 63 insertions(+) create mode 100644 templates/papers.tmpl create mode 100644 templates/test/TMZ-MyArticle.txt create mode 100644 templates/test/output/blabla.html create mode 100755 templates/test/render.sh diff --git a/templates/papers.tmpl b/templates/papers.tmpl new file mode 100644 index 0000000..e9fd37a --- /dev/null +++ b/templates/papers.tmpl @@ -0,0 +1,22 @@ + + + {{ .Env.TITLE }} + + + + + + + + + + {{ .Env.BODY }} +
+
+
+
+ + diff --git a/templates/test/TMZ-MyArticle.txt b/templates/test/TMZ-MyArticle.txt new file mode 100644 index 0000000..9556215 --- /dev/null +++ b/templates/test/TMZ-MyArticle.txt @@ -0,0 +1 @@ +UAHSIUHAIUSHAIUSHAIUSHAIUSHAIUH diff --git a/templates/test/output/blabla.html b/templates/test/output/blabla.html new file mode 100644 index 0000000..586509e --- /dev/null +++ b/templates/test/output/blabla.html @@ -0,0 +1,17 @@ + + + MyArticle + + + + + + + + UAHSIUHAIUSHAIUSHAIUSHAIUSHAIUH +
+
+
+
+ + diff --git a/templates/test/render.sh b/templates/test/render.sh new file mode 100755 index 0000000..7aeaf19 --- /dev/null +++ b/templates/test/render.sh @@ -0,0 +1,23 @@ +#!/bin/bash + +TEMPLATE_PATH="../papers.tmpl" +OUTPUT_DIR="output" + +# Create output directory if it doesn't exist +mkdir -p $OUTPUT_DIR + +# Loop through each file in the directory +for file in *.txt; do + FILE_NAME=$(basename "$file" .txt) + # Get the base name of the file without the extension + export TITLE=$(echo $FILE_NAME | cut -d '-' -f 2 | tr -d '[:space:]') + # Read the file content + export BODY=$(cat "$file") + + export AUTHOR=$(echo $FILE_NAME | cut -d '-' -f 1 | tr -d '[:space:]') + + # Run gomplate with the template and context variables + gomplate \ + -f "$TEMPLATE_PATH" \ + -o "$OUTPUT_DIR/blabla.html" +done