public
Fork of drnic/ruby-on-rails-tmbundle
Description: Ruby on Rails TextMate bundle [master branch is svn trunk; patches to drnicwilliams@gmail.com]
Homepage: http://macromates.com
Clone URL: git://github.com/Infininight/ruby-on-rails-tmbundle.git
Search Repo:
commit  c1160ccd8fd575a698a44d7b4a7094a1a7c973d8
tree    920c6eeed6657a0f348871e7186beeef8429dc7a
parent  4e2fe3ade86e6bbd8b4c47482a6e81dc8d85ff59
ruby-on-rails-tmbundle / Support / bin / go_to_alternate_file.rb
100755 51 lines (44 sloc) 1.463 kb
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
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
#!/usr/bin/env ruby
 
# Copyright:
# (c) 2006 syncPEOPLE, LLC.
# Visit us at http://syncpeople.com/
# Author: Duane Johnson (duane.johnson@gmail.com)
# Description:
# Makes an intelligent decision on which file to go to based on the current line or current context.
 
require 'rails_bundle_tools'
 
current_file = RailsPath.new
 
choice = ARGV.empty? ? current_file.best_match : ARGV.shift
 
if choice.nil?
  puts "This file is not associated with any other files"
elsif rails_path = current_file.rails_path_for(choice.to_sym)
  if choice.to_sym == :view and !rails_path.exists?
    if filename = TextMate.input("Enter the name of the new view file:", rails_path.basename)
      rails_path = RailsPath.new(File.join(rails_path.dirname, filename))
    else
      TextMate.exit_discard
    end
  end
 
  if !rails_path.exists?
    if !TextMate.message_ok_cancel("Create missing #{rails_path.basename}?")
      TextMate.exit_discard
    end
    rails_path.touch
    if choice.to_sym == :controller
      generated_code = <<-RUBY
class #{rails_path.controller_name.camelize}Controller < ApplicationController
end
RUBY
      rails_path.append generated_code
    elsif choice.to_sym == :helper
      generated_code = <<-RUBY
module #{rails_path.controller_name.camelize}Helper
end
RUBY
      rails_path.append generated_code
    end
    TextMate.rescan_project
  end
 
  TextMate.open rails_path
else
  puts "#{current_file.basename} does not have a #{choice}"
end