Skip to content

Instantly share code, notes, and snippets.

@wilkie
Created September 18, 2011 01:10
Show Gist options
  • Save wilkie/1224555 to your computer and use it in GitHub Desktop.
Save wilkie/1224555 to your computer and use it in GitHub Desktop.
Proof of concept trailing whitespace visualizer (idea by @jackiekircher)
module Whitespace
def self.trollify path, code
code.chomp!.gsub!(/([ \t]+)$/) do |match|
"; Whitespace::annoy(#{match.length})"
end
code.gsub!(/\brequire_relative\s*\(?\s*(.+?)\s*\)?;?$/) do |match|
"Whitespace::require_relative #{$1}, binding(), '#{path}'"
end
code
end
def self.require_relative s, b = binding(), path = ""
s = File.expand_path(s, path)
return if /\bwhitespace(?:.rb)?$/ =~ s
eval trollify(File.dirname(s), File.open(s).read), b
end
def self.annoy(number_of_spaces)
number_of_spaces.times do
sleep(1)
end
end
end
caller_file = caller.first.split(/:\d/, 2).first
abs_path = File.expand_path(caller_file, File.dirname(caller_file))
Whitespace::require_relative abs_path, binding()
exit
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment