lib/middleman/templates.rb in middleman-3.0.0.alpha.3 vs lib/middleman/templates.rb in middleman-3.0.0.alpha.4
- old
+ new
@@ -1,53 +1,74 @@
+# Use thor for template generation
require "thor"
require "thor/group"
+# Templates namespace
module Middleman::Templates
- @@template_mappings = {}
- def self.register(name, klass)
- @@template_mappings[name] = klass
- end
- def self.registered_names
- @@template_mappings.keys
+ # Static methods
+ class << self
+
+ # Get list of registered templates and add new ones
+ #
+ # @param [Symbol] name The name of the template
+ # @param [Class] klass The class to be executed for this template
+ # @return [Hash] List of registered templates
+ def registered(*args)
+ @_template_mappings ||= {}
+ @_template_mappings[args[0]] = args[1] if args.length == 2
+ @_template_mappings
+ end
+
+ # Middleman::Templates.register(name, klass)
+ alias :register :registered
end
- def self.registered_templates
- @@template_mappings
- end
-
+ # Base Template class. Handles basic options and paths.
class Base < ::Thor::Group
include Thor::Actions
+ # Required path for the new project to be generated
argument :location, :type => :string
+
+ # Name of the template being used to generate the project.
class_option :template, :default => "default"
+
+ # What to call the directory which CSS will be searched for.
class_option :css_dir, :default => "stylesheets"
+
+ # What to call the directory which JS will be searched for.
class_option :js_dir, :default => "javascripts"
+
+ # What to call the directory which images will be searched for.
class_option :images_dir, :default => "images"
- class_option :rack, :type => :boolean, :default => false
- class_option :bundler, :type => :boolean, :default => false
+ # Output a config.ru file for Rack if --rack is passed
+ class_option :rack, :type => :boolean, :default => false
def generate_rack
- if options[:rack]
- template "shared/config.ru", File.join(location, "config.ru")
- end
+ return unless options[:rack]
+ template "shared/config.ru", File.join(location, "config.ru")
end
+ # Output a Gemfile file for Bundler if --bundler is passed
+ class_option :bundler, :type => :boolean, :default => false
def generate_bundler
- if options[:bundler]
- template "shared/Gemfile.tt", File.join(location, "Gemfile")
-
- say_status :run, "bundle install"
- print `cd #{location} && "#{Gem.ruby}" -rubygems "#{Gem.bin_path('bundler', 'bundle')}" install`
- end
+ return unless options[:bundler]
+ template "shared/Gemfile.tt", File.join(location, "Gemfile")
+
+ say_status :run, "bundle install"
+ print `cd #{location} && "#{Gem.ruby}" -rubygems "#{Gem.bin_path('bundler', 'bundle')}" install`
end
end
end
# Default template
require "middleman/templates/default"
# HTML5 template
require "middleman/templates/html5"
+
+# HTML5 Mobile template
+require "middleman/templates/mobile"
# Local templates
require "middleman/templates/local"
\ No newline at end of file