我想知道是否存在解决以下问题的方法:
我有以下代码:
<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/