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

◇◆丶佛笑我妖孽 提交于 2019-11-30 05:41:42

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.)

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
Torsten

From https://gist.github.com/pho3nixf1re/1281382 looks like it does a whole directory tree:

#!/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
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!