mirror of
https://github.com/tests-always-included/mo.git
synced 2025-04-20 14:20:46 +00:00
Compare commits
No commits in common. "master" and "3.0.5" have entirely different histories.
@ -265,7 +265,6 @@ Pull requests to solve the following issues would be helpful.
|
|||||||
|
|
||||||
* Dotted names are supported but only for associative arrays (Bash 4). See [`demo/associative-arrays`](demo/associative-arrays) for an example.
|
* Dotted names are supported but only for associative arrays (Bash 4). See [`demo/associative-arrays`](demo/associative-arrays) for an example.
|
||||||
* There's no "top level" object, so `echo '{{.}}' | ./mo` does not do anything useful. In other languages you can say the data for the template is a string and in `mo` the data is always the environment. Luckily this type of usage is rare and `{{.}}` works great when iterating over an array.
|
* There's no "top level" object, so `echo '{{.}}' | ./mo` does not do anything useful. In other languages you can say the data for the template is a string and in `mo` the data is always the environment. Luckily this type of usage is rare and `{{.}}` works great when iterating over an array.
|
||||||
* [Parents](https://mustache.github.io/mustache.5.html#Parents), where a template can override chunks of a partial, are not supported.
|
|
||||||
* HTML encoding is not built into `mo`. `{{{var}}}`, `{{&var}}` and `{{var}}` all do the same thing. `echo '{{TEST}}' | TEST='<b>' mo` will give you "`<b>`" instead of "`>b<`".
|
* HTML encoding is not built into `mo`. `{{{var}}}`, `{{&var}}` and `{{var}}` all do the same thing. `echo '{{TEST}}' | TEST='<b>' mo` will give you "`<b>`" instead of "`>b<`".
|
||||||
|
|
||||||
|
|
||||||
|
112
mo
112
mo
@ -115,8 +115,6 @@ mo() (
|
|||||||
moDoubleHyphens=false
|
moDoubleHyphens=false
|
||||||
MO_OPEN_DELIMITER_DEFAULT="{{"
|
MO_OPEN_DELIMITER_DEFAULT="{{"
|
||||||
MO_CLOSE_DELIMITER_DEFAULT="}}"
|
MO_CLOSE_DELIMITER_DEFAULT="}}"
|
||||||
MO_FUNCTION_CACHE_HIT=()
|
|
||||||
MO_FUNCTION_CACHE_MISS=()
|
|
||||||
|
|
||||||
if [[ $# -gt 0 ]]; then
|
if [[ $# -gt 0 ]]; then
|
||||||
for arg in "$@"; do
|
for arg in "$@"; do
|
||||||
@ -432,19 +430,30 @@ mo::indirectArray() {
|
|||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
mo::trimUnparsed() {
|
mo::trimUnparsed() {
|
||||||
local moI moC
|
local moLastLen moR moN moT
|
||||||
|
|
||||||
moI=0
|
moLastLen=0
|
||||||
moC=${MO_UNPARSED:0:1}
|
moR=$'\r'
|
||||||
|
moN=$'\n'
|
||||||
|
moT=$'\t'
|
||||||
|
|
||||||
while [[ "$moC" == " " || "$moC" == $'\r' || "$moC" == $'\n' || "$moC" == $'\t' ]]; do
|
while [[ "${#MO_UNPARSED}" != "$moLastLen" ]]; do
|
||||||
moI=$((moI + 1))
|
moLastLen=${#MO_UNPARSED}
|
||||||
moC=${MO_UNPARSED:$moI:1}
|
|
||||||
|
# These conditions are necessary for a significant speed increase
|
||||||
|
while [[ "${MO_UNPARSED:0:1}" == " " ]]; do
|
||||||
|
MO_UNPARSED=${MO_UNPARSED# }
|
||||||
|
done
|
||||||
|
while [[ "${MO_UNPARSED:0:1}" == "$moR" ]]; do
|
||||||
|
MO_UNPARSED=${MO_UNPARSED#"$moR"}
|
||||||
|
done
|
||||||
|
while [[ "${MO_UNPARSED:0:1}" == "$moN" ]]; do
|
||||||
|
MO_UNPARSED=${MO_UNPARSED#"$moN"}
|
||||||
|
done
|
||||||
|
while [[ "${MO_UNPARSED:0:1}" == "$moT" ]]; do
|
||||||
|
MO_UNPARSED=${MO_UNPARSED#"$moT"}
|
||||||
|
done
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "$moI" != 0 ]]; then
|
|
||||||
MO_UNPARSED=${MO_UNPARSED:$moI}
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -902,28 +911,10 @@ mo::parseValue() {
|
|||||||
#
|
#
|
||||||
# Returns 0 if the name is a function, 1 otherwise.
|
# Returns 0 if the name is a function, 1 otherwise.
|
||||||
mo::isFunction() {
|
mo::isFunction() {
|
||||||
local moFunctionName
|
|
||||||
|
|
||||||
for moFunctionName in "${MO_FUNCTION_CACHE_HIT[@]}"; do
|
|
||||||
if [[ "$moFunctionName" == "$1" ]]; then
|
|
||||||
return 0
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
for moFunctionName in "${MO_FUNCTION_CACHE_MISS[@]}"; do
|
|
||||||
if [[ "$moFunctionName" == "$1" ]]; then
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
done
|
|
||||||
|
|
||||||
if declare -F "$1" &> /dev/null; then
|
if declare -F "$1" &> /dev/null; then
|
||||||
MO_FUNCTION_CACHE_HIT=( ${MO_FUNCTION_CACHE_HIT[@]+"${MO_FUNCTION_CACHE_HIT[@]}"} "$1" )
|
|
||||||
|
|
||||||
return 0
|
return 0
|
||||||
fi
|
fi
|
||||||
|
|
||||||
MO_FUNCTION_CACHE_MISS=( ${MO_FUNCTION_CACHE_MISS[@]+"${MO_FUNCTION_CACHE_MISS[@]}"} "$1" )
|
|
||||||
|
|
||||||
return 1
|
return 1
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1002,24 +993,13 @@ mo::isArrayIndexValid() {
|
|||||||
# Can not use logic like this in case invalid variable names are passed.
|
# Can not use logic like this in case invalid variable names are passed.
|
||||||
# [[ "${!1-a}" == "${!1-b}" ]]
|
# [[ "${!1-a}" == "${!1-b}" ]]
|
||||||
#
|
#
|
||||||
# Using logic like this gives false positives.
|
|
||||||
# [[ -v "$a" ]]
|
|
||||||
#
|
|
||||||
# Declaring a variable is not the same as assigning the variable.
|
|
||||||
# export x
|
|
||||||
# declare -p x # Output: declare -x x
|
|
||||||
# export y=""
|
|
||||||
# declare -p y # Output: declare -x y=""
|
|
||||||
# unset z
|
|
||||||
# declare -p z # Error code 1 and output: bash: declare: z: not found
|
|
||||||
#
|
|
||||||
# Returns true (0) if the variable is set, 1 if the variable is unset.
|
# Returns true (0) if the variable is set, 1 if the variable is unset.
|
||||||
mo::isVarSet() {
|
mo::isVarSet() {
|
||||||
if declare -p "$1" &> /dev/null && [[ -v "$1" ]]; then
|
if ! declare -p "$1" &> /dev/null; then
|
||||||
return 0
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
return 1
|
return 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1430,39 +1410,31 @@ mo::standaloneCheck() {
|
|||||||
#
|
#
|
||||||
# Returns nothing.
|
# Returns nothing.
|
||||||
mo::standaloneProcess() {
|
mo::standaloneProcess() {
|
||||||
local moI moTemp
|
local moContent moLast moT moR moN
|
||||||
|
|
||||||
|
moT=$'\t'
|
||||||
|
moR=$'\r'
|
||||||
|
moN=$'\n'
|
||||||
|
moLast=
|
||||||
|
|
||||||
mo::debug "Standalone tag - processing content before and after tag"
|
mo::debug "Standalone tag - processing content before and after tag"
|
||||||
moI=$((${#MO_PARSED} - 1))
|
|
||||||
mo::debug "zero done ${#MO_PARSED}"
|
|
||||||
mo::escape moTemp "$MO_PARSED"
|
|
||||||
mo::debug "$moTemp"
|
|
||||||
|
|
||||||
while [[ "${MO_PARSED:$moI:1}" == " " || "${MO_PARSED:$moI:1}" == $'\t' ]]; do
|
while [[ "$moLast" != "$MO_PARSED" ]]; do
|
||||||
moI=$((moI - 1))
|
moLast=$MO_PARSED
|
||||||
|
MO_PARSED=${MO_PARSED% }
|
||||||
|
MO_PARSED=${MO_PARSED%"$moT"}
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ $((moI + 1)) != "${#MO_PARSED}" ]]; then
|
moLast=
|
||||||
MO_PARSED="${MO_PARSED:0:${moI}+1}"
|
|
||||||
fi
|
|
||||||
|
|
||||||
moI=0
|
while [[ "$moLast" != "$MO_UNPARSED" ]]; do
|
||||||
|
moLast=$MO_UNPARSED
|
||||||
while [[ "${MO_UNPARSED:${moI}:1}" == " " || "${MO_UNPARSED:${moI}:1}" == $'\t' ]]; do
|
MO_UNPARSED=${MO_UNPARSED# }
|
||||||
moI=$((moI + 1))
|
MO_UNPARSED=${MO_UNPARSED#"$moT"}
|
||||||
done
|
done
|
||||||
|
|
||||||
if [[ "${MO_UNPARSED:${moI}:1}" == $'\r' ]]; then
|
MO_UNPARSED=${MO_UNPARSED#"$moR"}
|
||||||
moI=$((moI + 1))
|
MO_UNPARSED=${MO_UNPARSED#"$moN"}
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "${MO_UNPARSED:${moI}:1}" == $'\n' ]]; then
|
|
||||||
moI=$((moI + 1))
|
|
||||||
fi
|
|
||||||
|
|
||||||
if [[ "$moI" != 0 ]]; then
|
|
||||||
MO_UNPARSED=${MO_UNPARSED:${moI}}
|
|
||||||
fi
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -1988,7 +1960,7 @@ mo::tokenizeTagContentsSingleQuote() {
|
|||||||
|
|
||||||
# Save the original command's path for usage later
|
# Save the original command's path for usage later
|
||||||
MO_ORIGINAL_COMMAND="$(cd "${BASH_SOURCE[0]%/*}" || exit 1; pwd)/${BASH_SOURCE[0]##*/}"
|
MO_ORIGINAL_COMMAND="$(cd "${BASH_SOURCE[0]%/*}" || exit 1; pwd)/${BASH_SOURCE[0]##*/}"
|
||||||
MO_VERSION="3.0.7"
|
MO_VERSION="3.0.5"
|
||||||
|
|
||||||
# If sourced, load all functions.
|
# If sourced, load all functions.
|
||||||
# If executed, perform the actions as expected.
|
# If executed, perform the actions as expected.
|
||||||
|
@ -94,7 +94,7 @@ This is open source! Please feel free to contribute.
|
|||||||
|
|
||||||
https://github.com/tests-always-included/mo
|
https://github.com/tests-always-included/mo
|
||||||
|
|
||||||
MO_VERSION=3.0.7
|
MO_VERSION=3.0.5
|
||||||
EOF
|
EOF
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,9 +0,0 @@
|
|||||||
#!/usr/bin/env bash
|
|
||||||
cd "${0%/*}" || exit 1
|
|
||||||
. ../run-tests
|
|
||||||
|
|
||||||
export uv
|
|
||||||
export template='{{^uv}}OK{{/uv}}{{#uv}}FAIL{{/uv}}'
|
|
||||||
export expected='OK'
|
|
||||||
|
|
||||||
runTest
|
|
Loading…
x
Reference in New Issue
Block a user