2011-12-10 14:17:47 -05:00
|
|
|
# Use thor for template generation
|
2011-04-12 23:32:13 -04:00
|
|
|
require "thor"
|
|
|
|
require "thor/group"
|
|
|
|
|
2011-12-10 14:17:47 -05:00
|
|
|
# Templates namespace
|
2011-04-12 23:32:13 -04:00
|
|
|
module Middleman::Templates
|
|
|
|
|
2011-12-10 14:17:47 -05:00
|
|
|
# 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
|
2011-04-12 23:32:13 -04:00
|
|
|
end
|
|
|
|
|
2011-12-10 14:17:47 -05:00
|
|
|
# Base Template class. Handles basic options and paths.
|
2011-04-12 23:32:13 -04:00
|
|
|
class Base < ::Thor::Group
|
|
|
|
include Thor::Actions
|
|
|
|
|
2011-12-10 14:17:47 -05:00
|
|
|
# Required path for the new project to be generated
|
2011-04-12 23:32:13 -04:00
|
|
|
argument :location, :type => :string
|
2011-12-10 14:17:47 -05:00
|
|
|
|
|
|
|
# Name of the template being used to generate the project.
|
2011-04-16 19:23:10 -04:00
|
|
|
class_option :template, :default => "default"
|
2011-12-10 14:17:47 -05:00
|
|
|
|
|
|
|
# What to call the directory which CSS will be searched for.
|
2011-04-16 19:23:10 -04:00
|
|
|
class_option :css_dir, :default => "stylesheets"
|
2011-12-10 14:17:47 -05:00
|
|
|
|
|
|
|
# What to call the directory which JS will be searched for.
|
2011-04-16 19:23:10 -04:00
|
|
|
class_option :js_dir, :default => "javascripts"
|
2011-12-10 14:17:47 -05:00
|
|
|
|
|
|
|
# What to call the directory which images will be searched for.
|
2011-04-16 19:23:10 -04:00
|
|
|
class_option :images_dir, :default => "images"
|
2011-08-06 17:56:05 -04:00
|
|
|
|
2011-12-10 14:17:47 -05:00
|
|
|
# Output a config.ru file for Rack if --rack is passed
|
|
|
|
class_option :rack, :type => :boolean, :default => false
|
2011-08-06 17:56:05 -04:00
|
|
|
def generate_rack
|
2011-12-10 14:17:47 -05:00
|
|
|
return unless options[:rack]
|
|
|
|
template "shared/config.ru", File.join(location, "config.ru")
|
2011-08-06 17:56:05 -04:00
|
|
|
end
|
|
|
|
|
2011-12-10 14:17:47 -05:00
|
|
|
# Output a Gemfile file for Bundler if --bundler is passed
|
|
|
|
class_option :bundler, :type => :boolean, :default => false
|
2011-08-06 17:56:05 -04:00
|
|
|
def generate_bundler
|
2011-12-10 14:17:47 -05:00
|
|
|
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`
|
2011-08-06 17:56:05 -04:00
|
|
|
end
|
2011-04-12 23:32:13 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
# Default template
|
|
|
|
require "middleman/templates/default"
|
2011-04-16 19:23:10 -04:00
|
|
|
|
2011-04-12 23:32:13 -04:00
|
|
|
# HTML5 template
|
2011-04-16 19:23:10 -04:00
|
|
|
require "middleman/templates/html5"
|
|
|
|
|
2011-12-10 14:17:47 -05:00
|
|
|
# HTML5 Mobile template
|
|
|
|
require "middleman/templates/mobile"
|
|
|
|
|
2011-04-16 19:23:10 -04:00
|
|
|
# Local templates
|
2011-07-25 23:48:49 -04:00
|
|
|
require "middleman/templates/local"
|