Created
August 21, 2008 14:38
-
-
Save heycarsten/6570 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby -w | |
require File.join(ENV['TM_SUPPORT_PATH'], '/lib/textmate') | |
PROJECT_DIR = ENV['TM_PROJECT_DIRECTORY'] | |
METHOD_NAME = ENV['TM_CURRENT_WORD'] || ENV['TM_CURRENT_SELECTION'] | |
def blank?(string) | |
string.nil? || string.strip.eql?('') | |
end | |
def helpers_dir | |
File.join(PROJECT_DIR, '/app/helpers/*') | |
end | |
def grep_and_go_to! | |
method_name = Regexp.escape(METHOD_NAME) | |
grep = `grep -rnE "def #{method_name}([\( ]{1}|$)" #{helpers_dir}` | |
filepath, line = grep.match(/^.+:[\d]+/).to_s.strip.split(':') | |
if filepath && line | |
TextMate.go_to(:file => filepath, :line => line) | |
else | |
puts 'Could not find a matching Helper file' | |
end | |
end | |
if blank?(PROJECT_DIR) | |
puts 'Go To Helper Method only works in a project!' | |
elsif blank?(METHOD_NAME) | |
puts 'Place the cursor over the name of a Helper method' | |
else | |
grep_and_go_to! | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment