While I am working on the generalization of generators to remove code duplication (
https://github.com/devboy/gator-as3/commit/fcc1c57a73b7edebc6a776e51f57a7c0a16fd6fd).
I also started thinking about where to store our generator templates.
Right now a Generator only looks in the directory its Ruby file is in because we set the source root to that directory:
def self.source_root
File.dirname __FILE__
end
As I am sure people want to have their own templates to suit their liking we have to offer something here.
A generator gem obviously needs to ship with templates to work out of the box, thats one location.
A user might want to change these template on a global scope and maybe also on a project scope.
Now we have to deal with 3 different locations where looking for a single filename for a template isn't gonna work as it is now:
template "klass.as.tt", File.join(src, "#{class_name}.as")
What about we change the lookup to something like this to prevent naming clashes:
Then we can add multiple directories to the template-lookup and based on the order it would choose the first directory containing the template we are looking for.
So we could define a template directory on a project base (in the gator.rb file) which would be searched first.
Second place would be the global template directory (~/.gator/templates/generators/...).
And if the file couldn't be found there we will look for the template in the gems directory.
Is that a plan?