Created
December 20, 2012 00:51
-
-
Save ndbroadbent/4342095 to your computer and use it in GitHub Desktop.
script/rails with --editor option
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 | |
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. | |
APP_PATH = File.expand_path('../../config/application', __FILE__) | |
require File.expand_path('../../config/boot', __FILE__) | |
# Add --editor option to open generated files in editor | |
# ----------------------------------------------------- | |
module Rails | |
module Generators | |
module Actions | |
def template(source, *args, &block) | |
super | |
if options["editor"].present? | |
destination = args.first || source.sub(/\.tt$/, '') | |
run("#{options["editor"]} \"#{destination}\"") | |
end | |
end | |
def copy_file(source, *args, &block) | |
super | |
if options["editor"].present? | |
destination = args.first || source | |
run("#{options["editor"]} \"#{destination}\"") | |
end | |
end | |
end | |
end | |
end | |
require 'rails/generators' | |
module Rails | |
module Generators | |
Base.class_eval do | |
class_option :editor, :type => :string, :aliases => "-e", :lazy_default => ENV['GUI_EDITOR'] || ENV['EDITOR'], | |
:required => false, :banner => "/path/to/your/editor", | |
:desc => "Open all generated & copied files in the specified editor (defaults to $GUI_EDITOR, then $EDITOR)" | |
end | |
end | |
end | |
require 'rails/commands' |
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 | |
# This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. | |
APP_PATH = File.expand_path('config/application') | |
require File.expand_path('config/boot') | |
# Add --editor option to open generated files in editor | |
# ----------------------------------------------------- | |
module Rails | |
module Generators | |
module Actions | |
def template(source, *args, &block) | |
super | |
if options["editor"].present? | |
destination = args.first || source.sub(/\.tt$/, '') | |
run("#{options["editor"]} \"#{destination}\"") | |
end | |
end | |
def copy_file(source, *args, &block) | |
super | |
if options["editor"].present? | |
destination = args.first || source | |
run("#{options["editor"]} \"#{destination}\"") | |
end | |
end | |
end | |
end | |
end | |
require 'rails/generators' | |
module Rails | |
module Generators | |
Base.class_eval do | |
class_option :editor, :type => :string, :aliases => "-e", :lazy_default => ENV['GUI_EDITOR'] || ENV['EDITOR'], | |
:required => false, :banner => "/path/to/your/editor", | |
:desc => "Open all generated & copied files in the specified editor (defaults to $GUI_EDITOR, then $EDITOR)" | |
end | |
end | |
end | |
require 'rails/commands' |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment