Skip to content

Instantly share code, notes, and snippets.

@mathias
Created August 31, 2011 00:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mathias/1182534 to your computer and use it in GitHub Desktop.
Save mathias/1182534 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
source $(dirname $0)/scriptlib
TMP=/tmp/_git_hamlize_tmp
TARGET_FILES="$*"
REQUIRED_GEMS="hpricot ruby_parser"
function move_and_hamlize {
for F in $TARGET_FILES
do
BASE_PATH_NAME="$(basename $F .html.erb)"
echo "Git-Moving ${BASE_PATH_NAME}.html.erb to ${BASE_PATH_NAME}.html.haml"
git mv ${BASE_PATH_NAME}.html.erb ${BASE_PATH_NAME}.html.haml
html2haml -r ${BASE_PATH_NAME}.html.haml > $TMP
mv $TMP ${BASE_PATH_NAME}.html.haml
done
}
function all_gems_present {
for gem in $REQUIRED_GEMS
do
if [ "$(gem list $gem | grep $gem | wc -l | sed -e 's/^ *//')" != "1" ]; then
return -1
fi
done
return 0
}
if all_gems_present; then
move_and_hamlize
else
fail "$0 requires the following gems: $REQUIRED_GEMS"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment