新手问题 求教:Sublime Text 对 .html.erb 文件的自动缩进

happypeter · 2013年11月26日 · 最后由 happypeter 回复于 2013年12月20日 · 4568 次阅读

请问大家,如何配置 sublime 才能在运行 reindent lines 这个命令的时候,自动处理 erb 文件的缩进?

P.S 目前我的 sublime 对于 html 和 css/sass 的缩进支持都是完美的

……难道不是直接就能用?…… 最好给个例子说明怎么样才算完美的缩进

使用 slim,不缩进都不行 :)

#2 楼 @Kabie

现在 sublime 给我 reindent 出来的效果:

<% if one %>
<%= @two %>
<% else %>
<h1>three</h1>
<% end %>

我期待的:

<% if one %>
  <%= @two %>
<% else %>
  <h1>three</h1>
<% end %>

哦……这种跨作用域的 sublime 似乎没办法…… 一般插件也都是调用外部工具的…… 如果你不介意整个文件 format……可以试试 Beautifiy Ruby

#4 楼 @happypeter 希望代码看起来高大上,还是建议换成 slim 和 haml。html.erb 其实一点也不优雅

#5 楼 @Kabie 多谢!Beautify Ruby 确实有这个功能,不过我在安装后卡到这一步了:https://github.com/CraigWilliams/BeautifyRuby/issues/52

目前还是不能用。

我 Windows 下 st2 设置了 ruby 路径就能用了…… arch 下 st3 从 package control 安装也出错……手动安装也好了…… 不清楚你的情况是怎么样的了……

你用了 rvm?我也不知道手动安装还有问题是怎么回事了…… 不过说明里写的有问题…… 一般是不应该修改 Settings Default 的……应该改对应的 Settings User

gem install htmlbeautifier,你装了吗?@happypeter

@tankerwng

装了

peter@goodcat:~$ gem list|grep html
htmlbeautifier (0.0.8)
peter@goodcat:~$ which htmlbeautifier 
/home/peter/.rbenv/shims/htmlbeautifier

我的是 win7 的,BeautifyRuby 的 Settings-Default: { // Would you prefer a tab or two spaces to represent a tab // The default is two spaces represented by 'space' // anything else will use one tab character "tab_or_space": "space", "ruby": "C:/Ruby200/bin/ruby.exe", "file_patterns": ["\.html\.erb", "\.rb", "\.rake", "Rakefile", "Gemfile"], "html_erb_patterns": ["\.html\.erb"], "run_on_save": false, "save_on_beautify": true }

htmlbeautifier 是直接 gem install 装的,没用 rvm 之类的。

客气,也没帮上啥忙。不过,https://github.com/CraigWilliams/BeautifyRuby中提到: If you use project-specific rubies and gem sets managed with rvm, then simply set "ruby": "~/.rvm/bin/rvm-auto-ruby", and then the htmlbeautifier gem is found even if it is only installed for this project.

#17 楼 @tankerwng 有道理,我的 htmlbeautifier 是全局安装的。

需要 登录 后方可回复, 如果你还没有账号请 注册新账号