Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Allow rails templates relative to the current path to be given.

  • Loading branch information...
commit 55575e21655023259d0dae22bc1b148b34168d92 1 parent aed135d
@josevalim josevalim authored
View
21 railties/lib/generators/rails/app/app_generator.rb
@@ -49,7 +49,7 @@ def create_root
self.destination_root = File.expand_path(app_path, destination_root)
empty_directory '.'
- app_name # Sets the app name
+ set_default_accessors!
FileUtils.cd(destination_root)
end
@@ -164,9 +164,9 @@ def create_vendor_files
end
def apply_rails_template
- apply options[:template] if options[:template]
+ apply rails_template if rails_template
rescue Thor::Error, LoadError, Errno::ENOENT => e
- raise Error, "The template [#{options[:template]}] could not be loaded. Error: #{e}"
+ raise Error, "The template [#{rails_template}] could not be loaded. Error: #{e}"
end
def freeze?
@@ -175,6 +175,21 @@ def freeze?
protected
+ attr_accessor :rails_template
+
+ def set_default_accessors!
+ app_name # Cache app name
+
+ self.rails_template = case options[:template]
+ when /^http:\/\//
+ options[:template]
+ when String
+ File.expand_path(options[:template], Dir.pwd)
+ else
+ options[:template]
+ end
+ end
+
# Define file as an alias to create_file for backwards compatibility.
#
def file(*args, &block)
View
1  railties/test/fixtures/lib/template.rb
@@ -0,0 +1 @@
+say "It works from file!"
View
5 railties/test/generators/app_generator_test.rb
@@ -131,6 +131,11 @@ def test_rails_is_frozen
assert_file 'config/environment.rb', /# RAILS_GEM_VERSION/
end
+ def test_template_from_dir_pwd
+ FileUtils.cd(RAILS_ROOT)
+ assert_match /It works from file!/, run_generator(["-m", "lib/template.rb"])
+ end
+
def test_template_raises_an_error_with_invalid_path
content = capture(:stderr){ run_generator(["-m", "non/existant/path"]) }
assert_match /The template \[.*\] could not be loaded/, content
View
2  railties/test/generators/generators_test_helper.rb
@@ -20,7 +20,7 @@ class GeneratorsTestCase < Test::Unit::TestCase
def destination_root
@destination_root ||= File.expand_path(File.join(File.dirname(__FILE__),
- '..', '..', 'fixtures', 'tmp'))
+ '..', 'fixtures', 'tmp'))
end
def setup
Please sign in to comment.
Something went wrong with that request. Please try again.