Fixing indentation of partials

This commit is contained in:
Tyler Akins 2017-04-21 09:30:32 -05:00
parent 387fc478fc
commit 8142f70769
No known key found for this signature in database
GPG Key ID: 8F3B8C432F4393BD

32
mo
View File

@ -255,10 +255,10 @@ moIndentLines() {
local content fragment len posN posR result trimmed local content fragment len posN posR result trimmed
result="" result=""
len=$((${#3} - 1))
#: Remove the period from the end of the string.
#: This removes newline and dot from the workaround in moPartial len=$((${#content} - 1))
content="${3:0:$len}" content=${3:0:len}
if [[ -z "${2-}" ]]; then if [[ -z "${2-}" ]]; then
local "$1" && moIndirect "$1" "$content" local "$1" && moIndirect "$1" "$content"
@ -285,8 +285,23 @@ moIndentLines() {
fi fi
result="$result$fragment" result="$result$fragment"
moFindString posN "$content" $'\n' moFindString posN "$content" $'\n'
moFindString posR "$content" $'\r' moFindString posR "$content" $'\r'
# If the content ends in a newline, do not indent.
if [[ "$posN" -eq ${#content} ]]; then
# Special clause for \r\n
if [[ "$posR" -eq "$((posN - 1))" ]]; then
posR=-1
fi
posN=-1
fi
if [[ "$posR" -eq ${#content} ]]; then
posR=-1
fi
done done
moTrimChars trimmed "$content" false true " " $'\t' moTrimChars trimmed "$content" false true " " $'\t'
@ -692,12 +707,13 @@ moPartial() {
cd "$(dirname -- "$moFilename")" || exit 1 cd "$(dirname -- "$moFilename")" || exit 1
moIndentLines moPartial "$moIndent" "$( moIndentLines moPartial "$moIndent" "$(
moLoadFile moPartial "${moFilename##*/}" moLoadFile moPartial "${moFilename##*/}"
moParse "${moPartial}" "$6" true
# Fix bash handling of subshells # Fix bash handling of subshells and keep trailing whitespace.
# The extra dot is removed in moIndentLines # This is removed in moIndentLines.
echo -n "${moPartial}." echo -n "."
)" )"
moParse "$moPartial" "$6" true echo -n "$moPartial"
) )
local "$1" && moIndirect "$1" "$moContent" local "$1" && moIndirect "$1" "$moContent"