Skip to content

Instantly share code, notes, and snippets.

@jcleveley-zz
Created December 11, 2016 19:04
Show Gist options
  • Save jcleveley-zz/7656bf9d733f85f71d04fb7bd9f1aa52 to your computer and use it in GitHub Desktop.
Save jcleveley-zz/7656bf9d733f85f71d04fb7bd9f1aa52 to your computer and use it in GitHub Desktop.
#! /bin/zsh
autoload -U zmv
zmv -C '(**/)(*).mustache' '$1$2.html'
for file in **/*.html; do
echo "Converting: $file";
# Comments
perl -0777 -pi -e 's/{{\!(.*?)}}/{#$1#}/s' $file
# Partials
perl -pi -e 's/{{> ?(\S+) ?}}/{% include "$1.html" %}/g' "$file"
# Block
perl -pi -e 's/{{#([^}]+)}}/{% if $1 %}/g' "$file"
# End block
perl -pi -e 's/{{\/[^}]+}}/{% endif %}/g' "$file"
# No html escape
perl -pi -e 's/{{{ ?(\S+) ?}}}/{{ $1|safe }}/g' "$file"
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment