From f9aea511631e0ca8c0ccd10739c5cfcf9e4bf4ab Mon Sep 17 00:00:00 2001 From: Alexandre-Silva <alexandre.si.moes.lva@gmail.com> Date: Thu, 21 Jul 2016 12:07:02 +0100 Subject: [PATCH] mo can now source a script before parsing templates --- .gitignore | 1 + demo/sourcing | 18 ++++++++++++++++++ mo | 11 +++++++++-- 3 files changed, 28 insertions(+), 2 deletions(-) create mode 100755 demo/sourcing diff --git a/.gitignore b/.gitignore index 5a1b4f1..bf77c8f 100644 --- a/.gitignore +++ b/.gitignore @@ -4,3 +4,4 @@ diagnostic.test tests/*.diff spec/ spec-runner/ +demo/sourcing.vars diff --git a/demo/sourcing b/demo/sourcing new file mode 100755 index 0000000..01cfb6a --- /dev/null +++ b/demo/sourcing @@ -0,0 +1,18 @@ +#!/bin/bash +# +# This sources a simple script with the env. variables needed for the template. + +cd "$(dirname "$0")" # Go to the script's directory + +cat <<EOF >sourcing.vars +export NAME="Alex" +export ARRAY=( AAA BBB CCC ) +EOF + +cat <<EOF | ../mo --source=sourcing.vars +Hello, my name is {{NAME}}. +And this is ARRAY's conntents: +{{#ARRAY}} + * {{.}} +{{/ARRAY}} +EOF \ No newline at end of file diff --git a/mo b/mo index 598c566..1ca2ab9 100755 --- a/mo +++ b/mo @@ -21,7 +21,9 @@ # # $0 - Name of the mo file, used for getting the help message. # $* - Filenames to parse. Can use -h or --help as the only option -# in order to show a help message. +# in order to show a help message. Additionaly, --source=file +# can be passed so that mo sources the file before parsing +# the filenames. # # Returns nothing. mo() ( @@ -30,13 +32,18 @@ mo() ( local moContent IFS=$' \n\t' - + if [[ $# -gt 0 ]]; then case "$1" in -h|--h|--he|--hel|--help) moUsage "$0" exit 0 ;; + + --source=*) + . "${1#--source=}" + shift 1 + ;; esac fi