8

我希望将整个 HTML 目录转换为 HAML,以便文件具有相同的名称但具有新的扩展名。

html2haml file.html.erb file.haml

我可以运行一个循环,以便我可以一次转换所有这些文件,以便名称相同,只是更改了扩展名?

我的文件:

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
4

3 回答 3

14

这并不性感,但它正在发挥作用:

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

(注意它的-e标志html2haml解析ERb标签。)

于 2012-02-22T16:27:43.103 回答
5

你可以这样做:

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

编辑:如果您需要递归查找模板文件并且您使用的是bash4.x,那么您可以使用globstar

shopt -s globstar
for f in **/*.html.erb; do html2haml $f ${f/\.html\.erb/.haml}; done
于 2012-02-22T16:32:44.563 回答
0

https://gist.github.com/pho3nixf1re/1281382看起来它做了一个完整的目录树:

#!/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
于 2016-03-19T20:41:34.223 回答