是否有 bash 命令可以将整个目录从 HTML 转换为 HAML?

发布于 2025-01-08 02:05:19 字数 405 浏览 0 评论 0 原文

我希望将整个 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

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

马蹄踏│碎落叶 2025-01-15 02:05:19

它并不性感,但它正在工作:(

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

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

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

蓝海 2025-01-15 02:05:19

您可以执行以下操作:

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

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

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

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
溺深海 2025-01-15 02:05:19

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文