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

I want to convert the entire HTML directory 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 at the same time, so that the name is the same, only the extension has been 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 
+6
source share
3 answers

This is not sexy, but it works:

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

(Note the -e html2haml flag; it parses ERb tags.)

+13
source

You can do something like this:

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

Edit: if you need to search for template files recursively, and you are 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 
+4
source

From https://gist.github.com/pho3nixf1re/1281382 it looks like this is a tree of whole directories:

 #!/bin/bash if [ -z "$1" ]; then wdir="." else wdir=$1 fi for f in $( find . -name '*.erb' ); do out="${f%.erb}.haml" if [ -e $out ]; then echo "skipping $out; already exists" # rm $f else echo "hamlifying $f" html2haml $f > $out # rm $f fi done 
0
source

Source: https://habr.com/ru/post/909097/


All Articles