TextMate 中的 ⌃⇧H 为“Tidy”; HTML 导致 NoMethodError
昨天我第一次尝试在 HTML 文档中使用“Tidy”,结果...
/tmp/temp_textmate.Z2P0KX:30:in `<main>': undefined method `empty?' for nil:NilClass (NoMethodError)
我没有对包中的代码执行任何操作...
#!/usr/bin/env ruby -wKU
require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb'
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes.rb'
result = `"${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \
-wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \
--indent yes \
${TM_XHTML:+-asxhtml --output-xhtml yes} \
${TM_SELECTED_TEXT:+--show-body-only yes} \
--enclose-text yes \
--doctype strict \
--wrap-php no \
--tidy-mark no`
status = $?.exitstatus
at_exit { File.unlink('/tmp/tm_tidy_errors') } # Clean up error log
if status == 2 # Errors
msg = "Errors: " + File.read('/tmp/tm_tidy_errors')
TextMate.exit_show_tool_tip msg
elsif status == 1 # Warnings - use output but also display notification with warnings
log = File.read('/tmp/tm_tidy_errors').to_a.select do |line|
! (ENV['TM_SELECTED_TEXT'] and (line.include?('Warning: missing <!DOCTYPE> declaration') or line.include?("Warning: inserting missing 'title' element")))
end.join rescue nil
unless log.empty?
options = {
:title => "Tidy Warnings",
:summary => "Warnings for tidying your document (press escape to close):",
:log => log
}
TextMate::UI.simple_notification(options)
end
end
if ENV['TM_SOFT_TABS'] == "YES"
print result
else
in_pre = false
result.each_line do |line|
unless in_pre
tab_size = ENV["TM_TAB_SIZE"].to_i
space, text = /( *)(.*)/m.match(line)[1..2]
line = "\t" * (space.length / tab_size).floor + " " * (space.length % tab_size) + text
end
print line
in_pre = true if line.include?("<pre>")
in_pre = false if line.include?("</pre>")
end
end
问题行是 unless log.empty?.
我在 OS X 10.6.6 上运行 TextMate 1.5.10 (1631)。我最近安装了 rvm 并将默认 Ruby 升级到 1.9.2,但强制 TextMate 使用 1.8.7 并没有解决问题。
I tried using 'Tidy' in an HTML document for the first time yesterday, and got...
/tmp/temp_textmate.Z2P0KX:30:in `<main>': undefined method `empty?' for nil:NilClass (NoMethodError)
I've not done anything to the code in the bundle...
#!/usr/bin/env ruby -wKU
require ENV['TM_SUPPORT_PATH'] + '/lib/ui.rb'
require ENV['TM_SUPPORT_PATH'] + '/lib/exit_codes.rb'
result = `"${TM_TIDY:-tidy}" -f /tmp/tm_tidy_errors -iq -utf8 \
-wrap 0 --tab-size $TM_TAB_SIZE --indent-spaces $TM_TAB_SIZE \
--indent yes \
${TM_XHTML:+-asxhtml --output-xhtml yes} \
${TM_SELECTED_TEXT:+--show-body-only yes} \
--enclose-text yes \
--doctype strict \
--wrap-php no \
--tidy-mark no`
status = $?.exitstatus
at_exit { File.unlink('/tmp/tm_tidy_errors') } # Clean up error log
if status == 2 # Errors
msg = "Errors: " + File.read('/tmp/tm_tidy_errors')
TextMate.exit_show_tool_tip msg
elsif status == 1 # Warnings - use output but also display notification with warnings
log = File.read('/tmp/tm_tidy_errors').to_a.select do |line|
! (ENV['TM_SELECTED_TEXT'] and (line.include?('Warning: missing <!DOCTYPE> declaration') or line.include?("Warning: inserting missing 'title' element")))
end.join rescue nil
unless log.empty?
options = {
:title => "Tidy Warnings",
:summary => "Warnings for tidying your document (press escape to close):",
:log => log
}
TextMate::UI.simple_notification(options)
end
end
if ENV['TM_SOFT_TABS'] == "YES"
print result
else
in_pre = false
result.each_line do |line|
unless in_pre
tab_size = ENV["TM_TAB_SIZE"].to_i
space, text = /( *)(.*)/m.match(line)[1..2]
line = "\t" * (space.length / tab_size).floor + " " * (space.length % tab_size) + text
end
print line
in_pre = true if line.include?("<pre>")
in_pre = false if line.include?("</pre>")
end
end
The problem line is unless log.empty?
.
I'm running TextMate 1.5.10 (1631) on OS X 10.6.6. I recently installed rvm and upgraded default Ruby to 1.9.2, though forcing TextMate to use 1.8.7 did not fix the problem.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
我也有同样的问题。我已将 Textmate 设置为使用 RVM 版本的 ruby,以便我可以快速测试脚本。
我通过取消选中我创建的环境变量的“TM_RUBY”解决了该问题。
似乎发生的情况是,当使用 OSX 附带的 ruby 版本以外的 ruby 版本时,包装 /usr/bin/tidy 命令的 Textmate 脚本无法正确执行。
我很好奇狮子出来后会发生什么。希望 Textmate 能够重新审视这些内置脚本,并对它们进行一些“除尘”。
I had the same problem. I have setup my Textmate to use the RVM version of ruby so that I can quickly test scripts.
I solved the problem by unchecking the "TM_RUBY" for the environment variable I had created.
What appears to be happening is the Textmate scripts that wrapper the /usr/bin/tidy command are not executing properly when using a ruby version other than the one that ships with OSX.
I'm curious to see what happens when Lion comes out. Hopefully, Textmate will take another look at these build-in scripts and give them a little "dusting-off".
如果您查看
log
的分配,您会看到以下内容:末尾的
rescue nil
会将nil
放入如果
。然后脚本将调用/tmp/tm_tidy_errors
文件不存在或无法读取或发生其他情况,则记录nil
上的.empty?
方法,但nil
对象没有这样的方法,脚本崩溃并终止。您可以通过将
rescue nil
更改为rescue ''
或将unless log.empty?
更改为unless log.nil 来抑制该问题? || log.empty?
但这可能不是真正的问题。您是否设置了
TM_TIDY
环境变量?您的PATH
中有tidy
命令吗?看起来您的 Tidy 安装不正确(或者可能根本不存在)。我的 OSX 有/usr/bin/tidy
,显然这是标准的。尝试在终端中手动运行大型tidy
命令,看看会发生什么。If you look at the assignment to
log
, you'll see this:The
rescue nil
at the end will put anil
intolog
if the/tmp/tm_tidy_errors
file isn't there or it can't be read or what ever. Then the script will call the.empty?
method onnil
but thenil
object has no such method and the script falls over and dies.You can suppress the problem by changing
rescue nil
torescue ''
or by changingunless log.empty?
tounless log.nil? || log.empty?
but that might not be the real problem.Do you have a
TM_TIDY
environment variable set? Is there atidy
command in yourPATH
? Looks like your Tidy install isn't right (or possible not there at all). My OSX has/usr/bin/tidy
and apparently that's standard. Try running that bigtidy
command by hand in a terminal and see what happens.我也遇到了同样的问题,在一台运行 OS X 10.9.5 的机器上,Ruby 升级到了 ruby 2.0.0。通过将 mu is Too Short 的建议更改为
unless log.empty?
到unless long.nil? 来修复此问题。 || log.empty?
。这使得 Tidy 能够正常运行,但我的 HTML 选择的顶部仍然显示恼人的错误:我通过更改脚本的第一行来关闭它 #!/usr/bin/env ruby -wKU 到<代码>#!/usr/bin/env ruby -wKU -W0。显然,问题仍然存在,但对于一些有用但不是必需的东西,就像这个功能一样,我认为它已经足够好了。
I had the same problem too, on a machine running OS X 10.9.5 with Ruby upgraded to ruby 2.0.0. Fixed it by taking mu is too short's suggestion to change
unless log.empty?
tounless long.nil? || log.empty?
. That allowed Tidy to run properly, but the top of my HTML selection was still showing me annoying errors:I shut that up by changing the first line of the script from
#!/usr/bin/env ruby -wKU
to#!/usr/bin/env ruby -wKU -W0
. Obviously the problems are still there under the hood, but for something helpful but not essential, as this functionality is, I think it's plenty good enough.