Skip to content

Instantly share code, notes, and snippets.

@bruce
Created October 29, 2008 01:01
Show Gist options
  • Save bruce/20572 to your computer and use it in GitHub Desktop.
Save bruce/20572 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'erb'
require 'find'
require 'open3'
require 'rubygems'
begin
require 'colorize'
rescue LoadError
abort "Please install the `colorize' gem"
end
trap(:SIGINT) { puts "\nThanks!"; exit }
Find.find(Dir.pwd) do |path|
next unless File.file?(path)
next unless File.extname(path) == '.erb'
next if path =~ /vendor/
short_path = path[(Dir.pwd.size + 1)..-1]
source = ERB.new(File.read(path), 0, '-').src
error = Open3.popen3('ruby -c') do |stdin, stdout, stderr|
stdin.write source
stdin.close
if stdout.read == ""
stderr.read
end
end
unless error
puts short_path.colorize(:green)
else
puts short_path.colorize(:red).underline
puts error.split(/\r?\n/).map { |l| " #{l}" }.join("\n")
end
next
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment