From e623b16bb85fd09f8aac2eac54ba5d2bd7f889ab Mon Sep 17 00:00:00 2001 From: Tyler Akins Date: Thu, 27 Aug 2015 09:42:01 -0500 Subject: [PATCH] Allowing access to globals while in a loop This used to make a name like DATA.0.STR. Since bash doesn't like using multi-dimensional arrays, we can shortcut things and just assume that STR referes to the global variable here. This closes issue #7 --- mo | 2 +- tests/globals-in-loop.env | 2 ++ tests/globals-in-loop.expected | 6 ++++++ tests/globals-in-loop.template | 6 ++++++ 4 files changed, 15 insertions(+), 1 deletion(-) create mode 100644 tests/globals-in-loop.env create mode 100644 tests/globals-in-loop.expected create mode 100644 tests/globals-in-loop.template diff --git a/mo b/mo index c7da112..3e8b7bf 100755 --- a/mo +++ b/mo @@ -111,7 +111,7 @@ mustache-find-string() { # $2: Context name # $3: Desired variable name mustache-full-tag-name() { - if [[ -z "$2" ]]; then + if [[ -z "$2" ]] || [[ "$2" == *.* ]]; then local "$1" && mustache-indirect "$1" "$3" else local "$1" && mustache-indirect "$1" "${2}.${3}" diff --git a/tests/globals-in-loop.env b/tests/globals-in-loop.env new file mode 100644 index 0000000..47d1b68 --- /dev/null +++ b/tests/globals-in-loop.env @@ -0,0 +1,2 @@ +STR=abc +DATA=(111 222) diff --git a/tests/globals-in-loop.expected b/tests/globals-in-loop.expected new file mode 100644 index 0000000..fe24ce5 --- /dev/null +++ b/tests/globals-in-loop.expected @@ -0,0 +1,6 @@ +Issue #7 +abc + Item: 111 + String: abc + Item: 222 + String: abc diff --git a/tests/globals-in-loop.template b/tests/globals-in-loop.template new file mode 100644 index 0000000..586eeb8 --- /dev/null +++ b/tests/globals-in-loop.template @@ -0,0 +1,6 @@ +Issue #7 +{{STR}} +{{#DATA}} + Item: {{.}} + String: {{STR}} +{{/DATA}}