I was thinking about this last night after spending some time messing
with a project plugin for Vim. This morning I hacked up a quick patch
for the rails app_generator to automatically setup a vim project file.
It works, but I knew it wouldn’t be a particularly good fit for the core
of rails - still nothing ventured etc. Anyway it was suggested that
perhaps peopel on the rails list might be intrigued…
Anyway if you’re a vim user, this might make starting your rails
projects easier (note I’m a long time vi user, but in no way would I
consider myself advanced, so any suggestions would be helpful).
1
here’s the patch to rails app_generator (eg
C:\ruby\lib\ruby\gems\1.8\gems\rails-0.14.3\lib\rails_generator\generators\applications\app\app_generator)
Index: app_generator.rb
— app_generator.rb (revision 2943)
+++ app_generator.rb (working copy)
@@ -10,7 +10,8 @@
def initialize(runtime_args, runtime_options = {})
super
usage if args.empty?
- @destination_root = args.shift
- @destination_root = args.shift
-
@app_name = File.basename(File.expand_path(@destination_root))
@socket = MYSQL_SOCKET_LOCATIONS.find { |f| File.exists?(f) }
@socket = ‘/path/to/your/mysql.sock’ if @socket.blank?
end
@@ -26,6 +27,10 @@Root
m.file “fresh_rakefile”, “Rakefile”
m.file “README”, “README” -
m.template "vim4rails", "vim4#{@app_name}", :assigns => {
-
:app_name => @app_name,
-
:location => File.expand_path(@app_name)
-
} # Application m.template "helpers/application.rb",
“app/controllers/application.rb”
@@ -34,7 +39,7 @@
# database.yml and .htaccess
m.template "configs/database.yml", "config/database.yml",
:assigns => {
-
:app_name =>
File.basename(File.expand_path(@destination_root)),
-
:app_name => @app_name, :socket => @socket } m.template "configs/routes.rb", "config/routes.rb"
after patching app_generator you need to add this file (contents below)
to eg if your rails gem is installed like mine (on
windows) c:\ruby\lib\ruby\gems\1.8\gems\rails-0.14.3
2
Save this as “vim4rails”
<%= app_name %>=<%= location %> CD=. {
View=app/views CD=. {
}
Controllers=app/controllers CD=. filter=“.rb" {
}
Models=app/models CD=. filter=".rb” {
}
YAML=config CD=. filter=“.yml" {
}
DDL=db CD=. filter=".ddl .sql" {
}
Tests=test CD=. {
Fixtures=fixtures CD=. filter=".yml” {
}
Functional=functional CD=. filter=“.rb" {
}
Unit=unit CD=. filter=".rb” {
}
}
Stylesheet=public/stylesheets CD=. filter=“*.css” {
}
}
3
Now you need to download and set up the project plugin I used - download
from here : project.tar.gz - Organize/Navigate projects of files (like IDE/buffer explorer) : vim online, follow
the included instructions to install the plugin on your system
4
Create a new rails app with “rails #{your_app}”
5
Check that inside the root of your rails app there’s a file called
vim4#{your_app}
6
open Vim
7 (and finally)
Load the project file for your rails app…
go into command mode (ESC)
type :Project /vim4#{your_app}
8
enjoy!
I’m quite happy with it, I’d like to turn it into a real generator, any
other suggestions welcome.
Kev