From 86224fef7f70d4f7becf5aae04f856667f655e1e Mon Sep 17 00:00:00 2001 From: Olivier DOSSMANN Date: Fri, 7 Feb 2020 12:34:49 +0100 Subject: [PATCH] Orgas: export common variables, functions and statement outside gen.sh --- orgas/commons.sh | 45 +++++++++++++++++++++++++++++++++++++ orgas/gen.sh | 39 +++++--------------------------- orgas/templates/header.tmpl | 4 ++-- 3 files changed, 52 insertions(+), 36 deletions(-) create mode 100644 orgas/commons.sh diff --git a/orgas/commons.sh b/orgas/commons.sh new file mode 100644 index 0000000..ea9a9d1 --- /dev/null +++ b/orgas/commons.sh @@ -0,0 +1,45 @@ +#!/usr/bin/env bash +# +# COMMONS variables, functions and statements for differents graphs +# + +# Built variables +outputfile="$1" +SRC_DIR="${RERO_DIR}/data/" + +# Templates +tmpl_gizmo="templates/gizmo.tmpl" # A colored polygon. Represents an entity. +tmpl_link="templates/link.tmpl" # A link between two entities. +tmpl_label="templates/label_default.tmpl" # Default label for entities. + +# Graph info +rankdir="RL" +title="" + +# TESTS +if [[ -z "${outputfile}" ]]; then + echo "No output file given" + exit 1 +elif [[ -f "${outputfile}" ]]; then + echo "File already exists!" + exit 1 +fi + +# FUNCTIONS +# WRITE first argument in output file +send() { + echo -e "$1" >> "$outputfile" +} +# render: SHOW template (given in $1) after variables REPLACEMENTS +render() { + template="$(cat $1)" + eval "echo -e \"${template}\"" +} +# save: WRITE template (given in $1) in outputfile after variables REPLACEMENTS +save() { + rendered_template="$(render $1)" + send "${rendered_template}" +} + +# Output file initialization +echo "" > "$outputfile" # flush output file diff --git a/orgas/gen.sh b/orgas/gen.sh index 6fa6e9e..f19d0cf 100755 --- a/orgas/gen.sh +++ b/orgas/gen.sh @@ -25,40 +25,11 @@ LIB_COLOR="${COLOR2}" # libraries PT_COLOR="${COLOR3}" # patron_types USER_COLOR="${COLOR5}" # users/patrons -# Built variables -outputfile="$1" -SRC_DIR="${RERO_DIR}/data/" -tmpl_gizmo="templates/gizmo.tmpl" # A colored polygon. Represents an entity. -tmpl_link="templates/link.tmpl" # A link between two entities. -tmpl_label="templates/label_default.tmpl" # Default label for entities. +# Load commons variables, functions and statements +source commons.sh -# TESTS -if [[ -z "${outputfile}" ]]; then - echo "No output file given" - exit 1 -elif [[ -f "${outputfile}" ]]; then - echo "File already exists!" - exit 1 -fi - -# FUNCTIONS -# WRITE first argument in output file -send() { - echo -e "$1" >> "$outputfile" -} -# render: SHOW template (given in $1) after variables REPLACEMENTS -render() { - template="$(cat $1)" - eval "echo -e \"${template}\"" -} -# save: WRITE template (given in $1) in outputfile after variables REPLACEMENTS -save() { - rendered_template="$(render $1)" - send "${rendered_template}" -} - -# Output file initialization -echo "" > "$outputfile" # flush output file +# Graph header +title="Link between organisations, libraries and users." save "templates/header.tmpl" # ORGANISATIONS @@ -188,7 +159,7 @@ do fi done -# end of file +# Graph footer save "templates/footer.tmpl" diff --git a/orgas/templates/header.tmpl b/orgas/templates/header.tmpl index da694be..734f122 100644 --- a/orgas/templates/header.tmpl +++ b/orgas/templates/header.tmpl @@ -1,3 +1,3 @@ digraph { -rankdir = RL; -label = \"Link between organisations, libraries and users.\"; +rankdir = ${rankdir}; +label = \"${title}\";