mattfoster (owner)

Revisions

gist: 67095 Download_button fork
public
Public Clone URL: git://gist.github.com/67095.git
Embed All Files: show embed
perlcritic_textmate_command.rb #
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#!/usr/bin/env ruby
# Run Perl::Critic on the current file.
 
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/executor"
require ENV["TM_SUPPORT_PATH"] + "/lib/tm/save_current_document"
 
def colorize_critic_output(str)
  styles = {5 => "Red", 4 => "GoldenRod", 3 => "DodgerBlue" }
  styles.default = ""
  str.map do |line|
    file, line_no, col_no, message, ref, severity = line.split(':')
    "&bull; <span class=\"out\" style=\"color:#{styles[severity.to_i]};\";>(Severity: #{severity.to_i})</span> #{message} <a href=\"txmt://open?line=#{line_no}&amp;column=#{col_no}#{file}\">at line #{line_no}, column #{col_no}</a>. #{ref}.<br/>"
  end
end
 
TextMate.save_current_document
TextMate::Executor.run(ENV["TM_PERLCRITIC"] || "perlcritic",
    '--verbose', '%f:%l:%c:%m:%e:%s\n',
    ENV['TM_PERLCRITIC_LEVEL'] || '--stern',
    '--nocolor', ENV["TM_FILEPATH"],
    :use_hashbang=>false, :verb => "Criticising") do |str, type|
  case type
  when :err
    # do special transformation of stderr
    "<span class=\"err\">#{htmlize(str)}</span>"
  when :out
    # special transformation of stdout
    colorize_critic_output(str)
  end
end