From f4f60cdee7063df5e66746c0c253f6ea7e40685c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Eloy=20Dur=C3=A1n?= Date: Mon, 27 Jan 2014 16:31:52 +0100 Subject: [PATCH] [Command] Allow gems to register templates and show in help banner. Load available templates list as late as possible. --- lib/motion/command/create.rb | 7 +++++-- lib/motion/project/template.rb | 13 +++++++++++++ 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/lib/motion/command/create.rb b/lib/motion/command/create.rb index 44be3e0d..06aa314e 100644 --- a/lib/motion/command/create.rb +++ b/lib/motion/command/create.rb @@ -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' diff --git a/lib/motion/project/template.rb b/lib/motion/project/template.rb index 2e2e4621..6c90c882 100644 --- a/lib/motion/project/template.rb +++ b/lib/motion/project/template.rb @@ -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)