Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a bash command for converting an entire directory to HAML from HTML?

I'm looking to convert an entire directory of HTML to HAML so that the files have the same name but with a new extension.

html2haml file.html.erb file.haml

Can I run a loop so that I can convert all these files all at once so that the name is the same just the extension is changed?

My files:

continue_login.html.erb
expired_trial.html.erb
expired_trial.mobile.erb
login.html.erb
login.mobile.erb
recover_password.html.erb
signup.html.erb
trial_expires_soon.html.erb
trial_expires_soon.mobile.erb
like image 550
Trip Avatar asked Feb 22 '12 16:02

Trip


2 Answers

It's not sexy but it's working:

for file in $(find . -type f -name \*.html.erb); do
  html2haml -e ${file} "$(dirname ${file})/$(basename ${file} .erb).haml";
done

(Pay attention to the -e flag of html2haml it parses the ERb tags.)

like image 53
KARASZI István Avatar answered Sep 30 '22 19:09

KARASZI István


You could do something like this:

for f in *.html.erb; do html2haml $f ${f/\.html\.erb/.haml}; done

Edit: If you need to look for template files recursively and you're using bash 4.x, then you can use globstar:

shopt -s globstar
for f in **/*.html.erb; do html2haml $f ${f/\.html\.erb/.haml}; done
like image 24
jcollado Avatar answered Sep 30 '22 19:09

jcollado