Permalink
Browse files

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

  • Loading branch information...
1 parent aed135d commit 55575e21655023259d0dae22bc1b148b34168d92 @josevalim josevalim committed Aug 7, 2009
@@ -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)
@@ -0,0 +1 @@
+say "It works from file!"
@@ -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
@@ -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

0 comments on commit 55575e2

Please sign in to comment.