I'm making a custom generator that generates a new rails app, and I do it like this
require 'thor'
require 'rails/generators/rails/app/app_generator'
class AppBuilder < Rails::AppBuilder
include Thor::Actions
include Thor::Shell
...
end
The problem is, how do I add a new source directory (which is then used by Thor::Actions#copy_file
, Thor::Actions#template
, and the others)? I saw in the Thor's documentation that Thor::Actions#source_paths
holds the sources (it's an array of paths), so I tried overriding it inside my class (since I've included Thor::Actions
):
def source_paths
[File.join(File.expand_path(File.dirname(__FILE__)), "templates")] + super
end
With this I wanted to add the ./templates
directory in the sources, while still keeping the Rails' one (that's why the + super
at the end). But it doesn't work, it still lists the Rails' source path as the only one.
I tried browsing through the Rails' source code, but I couldn't find how Rails put his directory in the source paths. And I really want to know that :)
Could not find "<any_file>" in any of your source paths. Your current source paths are: path/to/gems/railties-3.2.2/lib/rails/generators/rails/app/templates
, so it didn't pick it up at all. – Disaster