Skip to content

Instantly share code, notes, and snippets.

@stigi
Created September 30, 2012 13:06
Show Gist options
  • Save stigi/3806684 to your computer and use it in GitHub Desktop.
Save stigi/3806684 to your computer and use it in GitHub Desktop.
erb2haml.sh
#!/bin/sh
check_gem() {
REPLY=$(gem which $1 &>/dev/null)
}
convert() {
printf "Starting conversion\n["
for erb_file in `find . -name '*.erb'`
do
printf "."
html2haml -r $erb_file `ruby -e "puts '$erb_file'.sub(/erb$/,'haml')"`
rm $erb_file
done
printf "]\nDone.\n"
}
if
check_gem haml
check_gem hpricot
check_gem ruby_parser
then
convert
exit 0
else
echo "To use $0 you need to have the following gems installed: haml, hpricot and ruby_parser"
exit 1
fi
@stigi
Copy link
Author

stigi commented Sep 30, 2012

Need someone who is better in shell scripting than me + google. I want to AND bind the calls of check_gem in lines 24-26.

@toto
Copy link

toto commented Sep 30, 2012

Not much time. Have a look at man test

@phuesler
Copy link

there you go. A bit hacky, but it works

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment