TextH在TextMate中将HTML整理为"Tidy"会导致NoMethodError [英] ⌃⇧H in TextMate to 'Tidy' HTML causes NoMethodError

查看:128
本文介绍了TextH在TextMate中将HTML整理为"Tidy"会导致NoMethodError的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

昨天我第一次尝试在HTML文档中使用"Tidy",并得到...

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

问题行是unless log.empty?.

我在OS X 10.6.6上运行TextMate 1.5.10(1631).我最近安装了rvm,并将默认的Ruby升级到1.9.2,尽管强制TextMate使用1.8.7不能解决问题.

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.

推荐答案

我遇到了同样的问题.我已经将Textmate设置为使用RVM版本的ruby,以便可以快速测试脚本.

I had the same problem. I have setup my Textmate to use the RVM version of ruby so that I can quickly test scripts.

我通过为我创建的环境变量取消选中"TM_RUBY"来解决了这个问题.

I solved the problem by unchecking the "TM_RUBY" for the environment variable I had created.

似乎正在发生的情况是,当使用OSX附带的红宝石版本时,包装/usr/bin/tidy命令的Textmate脚本无法正确执行.

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.

我很好奇,看到狮子出来时会发生什么.希望Textmate可以再看看这些内置脚本,并给它们一些除尘"功能.

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

这篇关于TextH在TextMate中将HTML整理为"Tidy"会导致NoMethodError的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆