[Command] Allow gems to register templates and show in help banner.

Load available templates list as late as possible.
This commit is contained in:
Eloy Durán
2014-01-27 16:31:52 +01:00
parent 5afb52f99c
commit f4f60cdee7
2 changed files with 18 additions and 2 deletions

View File

@@ -40,8 +40,11 @@ module Motion; class Command
self.summary = 'Create a new project.'
self.description = "Create a new RubyMotion project from one of the " \
"following templates: #{templates_description}."
# Override getter so that we fetch the template names as late as possible.
def self.description
"Create a new RubyMotion project from one of the " \
"following templates: #{templates_description}."
end
self.arguments = 'APP-NAME'

View File

@@ -36,6 +36,18 @@ module Motion; module Project
File.expand_path(File.join(ENV['HOME'], 'Library/RubyMotion/template'))
]
# TODO Caching these and making it based on the Paths constant makes it
# less simple to register plugin templates, because you cannot add
# them to the Paths constant and ensure this method will return those
# newly registered templates either. The only nice way atm to register
# them is to add them directly to this cached `@all_templates` var.
# For instance, from the Joybox plugin:
#
# require 'motion/project/template'
# Dir.glob(File.expand_path('../../template/joybox-*', __FILE__)).each do |template_path|
# Motion::Project::Template.all_templates[File.basename(template_path)] = template_path
# end
#
def self.all_templates
@all_templates ||= begin
h = {}
@@ -46,6 +58,7 @@ module Motion; module Project
end
end
# TODO This seems to be unused.
Templates = Paths.map { |path| Dir.glob(path + '/*') }.flatten.select { |x| !x.match(/^\./) and File.directory?(x) }.map { |x| File.basename(x) }
def initialize(app_name, template_name)