html - 使用嵌入式 Ruby 代码 (erb) 缩进 HTML

标签 html ruby textmate indentation

我想知道是否存在解决以下问题的方法:

我有以下代码:

<div>
  <div>
<div><%= {:something => 'abc',
          :else => 'abc',
          :nice => 'ok'} %>
</div>
</div>
</div>

如您所见,它未经验证且难以阅读。我想知道是否存在一个最好在 ruby​​ 中可以重新缩进文档的工具(不对源进行修改或验证)。只需重新缩进。

预期的结果是:

<div>
  <div>
    <div>
      <%= {:something => 'abc',
           :else => 'abc',
           :nice => 'ok'} %>
    </div>
  </div>
</div>

此外,另一方面,我不想将其作为 Textmate 上的命令来实现。

最佳答案

在 Textmate 中实现?您确实了解 ⌘⌥[,即 Cmd+Alt+[(或使用 Text 从应用程序菜单中选择它 > Indent Selection)?

这不是您在示例中尝试实现的确切,但也许已经足够接近了。这是在 Textmate 中将其应用于您的代码时的输出:

<div>
  <div>
    <div><%= {:something => 'abc',
      :else => 'abc',
      :nice => 'ok'} %>
    </div>
  </div>
</div>

它适用于任何支持缩进的 Textmate 包。

关于html - 使用嵌入式 Ruby 代码 (erb) 缩进 HTML,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4003466/

相关文章:

html - 创建轮播时使用的角色 ="listbox"是什么?

ruby - 如何修复 Linux 中的 "usr/bin/google-chrome is no longer running, so ChromeDriver is assuming that Chrome has crashed"错误?

TextMate 切换注释宏已损坏

php - 在 TextMate PHP Bundle 中自动触发语法验证

javascript - 如何防止 TextMate 出现 "matching"//commented {( 括号(在 Javascript 中)?

html - iPhone 网络表单上一个/下一个跳过单选按钮 - 如何修复?

javascript - 简单的图像标记页面,如 facebook 图像标记

ruby-on-rails - 工厂女孩有一个协会

ruby - gsub 的时间复杂度

html - img :hover (transition opacity) 上的 chrome 出现奇怪的闪烁