Merge pull request #1198 from middleman/move-templates
middleman-templates
1
Gemfile
|
@ -38,5 +38,6 @@ gem 'rubocop', :require => false
|
||||||
# Middleman itself
|
# Middleman itself
|
||||||
gem 'middleman-core', :path => 'middleman-core'
|
gem 'middleman-core', :path => 'middleman-core'
|
||||||
gem 'middleman-cli', :path => 'middleman-cli'
|
gem 'middleman-cli', :path => 'middleman-cli'
|
||||||
|
gem 'middleman-templates', :path => 'middleman-templates'
|
||||||
gem 'middleman-sprockets', :github => 'middleman/middleman-sprockets', :require => false
|
gem 'middleman-sprockets', :github => 'middleman/middleman-sprockets', :require => false
|
||||||
gem 'middleman', :path => 'middleman'
|
gem 'middleman', :path => 'middleman'
|
||||||
|
|
2
Rakefile
|
@ -7,7 +7,7 @@ require File.expand_path('../middleman-core/lib/middleman-core/version.rb', __FI
|
||||||
ROOT = File.expand_path(File.dirname(__FILE__))
|
ROOT = File.expand_path(File.dirname(__FILE__))
|
||||||
GEM_NAME = 'middleman'
|
GEM_NAME = 'middleman'
|
||||||
|
|
||||||
middleman_gems = %w(middleman-core middleman-cli middleman)
|
middleman_gems = %w(middleman-core middleman-templates middleman-cli middleman)
|
||||||
GEM_PATHS = middleman_gems.freeze
|
GEM_PATHS = middleman_gems.freeze
|
||||||
|
|
||||||
def sh_rake(command)
|
def sh_rake(command)
|
||||||
|
|
|
@ -27,7 +27,7 @@ module Middleman::Cli
|
||||||
# The extension task
|
# The extension task
|
||||||
# @param [String] name
|
# @param [String] name
|
||||||
def extension
|
def extension
|
||||||
generate_gitignore!
|
copy_file 'extension/gitignore', File.join(name, '.gitignore') unless options[:'skip-git']
|
||||||
template 'extension/Rakefile', File.join(name, 'Rakefile')
|
template 'extension/Rakefile', File.join(name, 'Rakefile')
|
||||||
template 'extension/gemspec', File.join(name, "#{name}.gemspec")
|
template 'extension/gemspec', File.join(name, "#{name}.gemspec")
|
||||||
template 'extension/Gemfile', File.join(name, 'Gemfile')
|
template 'extension/Gemfile', File.join(name, 'Gemfile')
|
||||||
|
@ -40,14 +40,5 @@ module Middleman::Cli
|
||||||
# Output a .gitignore file
|
# Output a .gitignore file
|
||||||
class_option :git, :type => :boolean, :default => true
|
class_option :git, :type => :boolean, :default => true
|
||||||
|
|
||||||
no_tasks {
|
|
||||||
# Write a .gitignore file for project
|
|
||||||
# @return [void]
|
|
||||||
def generate_gitignore!
|
|
||||||
return if options[:'skip-git']
|
|
||||||
copy_file 'shared/gitignore', File.join(name, '.gitignore')
|
|
||||||
end
|
|
||||||
}
|
|
||||||
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
require 'middleman-cli/templates'
|
require 'middleman-templates'
|
||||||
|
|
||||||
# CLI Module
|
# CLI Module
|
||||||
module Middleman::Cli
|
module Middleman::Cli
|
||||||
|
|
|
@ -1,99 +0,0 @@
|
||||||
# Use thor for template generation
|
|
||||||
require 'thor'
|
|
||||||
require 'thor/group'
|
|
||||||
|
|
||||||
# Templates namespace
|
|
||||||
module Middleman::Templates
|
|
||||||
|
|
||||||
# Static methods
|
|
||||||
class << self
|
|
||||||
|
|
||||||
# Get list of registered templates and add new ones
|
|
||||||
#
|
|
||||||
# Middleman::Templates.register(:ext_name, klass)
|
|
||||||
#
|
|
||||||
# @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 register(name=nil, klass=nil)
|
|
||||||
@_template_mappings ||= {}
|
|
||||||
@_template_mappings[name] = klass if name && klass
|
|
||||||
@_template_mappings
|
|
||||||
end
|
|
||||||
|
|
||||||
# Middleman::Templates.register(name, klass)
|
|
||||||
alias :registered :register
|
|
||||||
end
|
|
||||||
|
|
||||||
# Base Template class. Handles basic options and paths.
|
|
||||||
class Base < ::Thor::Group
|
|
||||||
include Thor::Actions
|
|
||||||
|
|
||||||
def initialize(names, options)
|
|
||||||
super
|
|
||||||
source_paths << File.join(File.dirname(__FILE__), 'templates')
|
|
||||||
end
|
|
||||||
|
|
||||||
# The gemfile template to use. Individual templates can define this class
|
|
||||||
# method to override the template path.
|
|
||||||
def self.gemfile_template
|
|
||||||
'shared/Gemfile.tt'
|
|
||||||
end
|
|
||||||
|
|
||||||
# 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'
|
|
||||||
|
|
||||||
# Output a config.ru file for Rack if --rack is passed
|
|
||||||
class_option :rack, :type => :boolean, :default => false
|
|
||||||
|
|
||||||
# Write a Rack config.ru file for project
|
|
||||||
# @return [void]
|
|
||||||
def generate_rack!
|
|
||||||
return unless options[:rack]
|
|
||||||
template 'shared/config.ru', File.join(location, 'config.ru')
|
|
||||||
end
|
|
||||||
|
|
||||||
class_option :'skip-bundle', :type => :boolean, :default => false
|
|
||||||
class_option :'skip-gemfile', :type => :boolean, :default => false
|
|
||||||
|
|
||||||
# Write a Bundler Gemfile file for project
|
|
||||||
# @return [void]
|
|
||||||
def generate_bundler!
|
|
||||||
return if options[:'skip-gemfile']
|
|
||||||
template self.class.gemfile_template, File.join(location, 'Gemfile')
|
|
||||||
|
|
||||||
return if options[:'skip-bundle']
|
|
||||||
inside(location) do
|
|
||||||
::Middleman::Cli::Bundle.new.invoke(:bundle)
|
|
||||||
end unless ENV['TEST']
|
|
||||||
end
|
|
||||||
|
|
||||||
# Output a .gitignore file
|
|
||||||
class_option :'skip-git', :type => :boolean, :default => false
|
|
||||||
|
|
||||||
# Write a .gitignore file for project
|
|
||||||
# @return [void]
|
|
||||||
def generate_gitignore!
|
|
||||||
return if options[:'skip-git']
|
|
||||||
copy_file 'shared/gitignore', File.join(location, '.gitignore')
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
# Default template
|
|
||||||
require 'middleman-cli/templates/default'
|
|
||||||
|
|
||||||
# HTML5 template
|
|
||||||
require 'middleman-cli/templates/html5'
|
|
||||||
|
|
||||||
# HTML5 Mobile template
|
|
||||||
require 'middleman-cli/templates/mobile'
|
|
||||||
|
|
||||||
# Local templates
|
|
||||||
require 'middleman-cli/templates/local'
|
|
||||||
|
|
||||||
# Barebones template
|
|
||||||
require 'middleman-cli/templates/empty'
|
|
0
middleman-cli/lib/middleman-cli/templates/html5/source/img/.gitignore → middleman-templates/.gemtest
Executable file → Normal file
5
middleman-templates/.simplecov
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
SimpleCov.start do
|
||||||
|
add_filter '/fixtures/'
|
||||||
|
add_filter '/features/'
|
||||||
|
add_filter '/spec/'
|
||||||
|
end
|
4
middleman-templates/.yardopts
Normal file
|
@ -0,0 +1,4 @@
|
||||||
|
lib/**/*.rb
|
||||||
|
--exclude lib/middleman-templates
|
||||||
|
--no-private
|
||||||
|
--hide-void-return
|
5
middleman-templates/Rakefile
Normal file
|
@ -0,0 +1,5 @@
|
||||||
|
# coding:utf-8
|
||||||
|
RAKE_ROOT = __FILE__
|
||||||
|
|
||||||
|
GEM_NAME = 'middleman-templates'
|
||||||
|
require File.expand_path(File.dirname(__FILE__) + '/../gem_rake_helper')
|
18
middleman-templates/bin/middleman
Executable file
|
@ -0,0 +1,18 @@
|
||||||
|
#!/usr/bin/env ruby
|
||||||
|
|
||||||
|
require 'middleman-core/profiling'
|
||||||
|
if ARGV.include? '--profile'
|
||||||
|
Middleman::Profiling.profiler = Middleman::Profiling::RubyProfProfiler.new
|
||||||
|
end
|
||||||
|
Middleman::Profiling.start
|
||||||
|
|
||||||
|
require "middleman-core/load_paths"
|
||||||
|
Middleman.setup_load_paths
|
||||||
|
|
||||||
|
require "middleman-cli"
|
||||||
|
|
||||||
|
# Change directory to the root
|
||||||
|
Dir.chdir(ENV["MM_ROOT"]) if ENV["MM_ROOT"]
|
||||||
|
|
||||||
|
# Start the CLI
|
||||||
|
Middleman::Cli::Base.start
|
0
middleman-cli/lib/middleman-cli/templates/mobile/source/js/script.js → middleman-templates/features/.gitkeep
Executable file → Normal file
0
middleman-templates/fixtures/.gitkeep
Normal file
92
middleman-templates/lib/middleman-templates.rb
Normal file
|
@ -0,0 +1,92 @@
|
||||||
|
# Setup our load paths
|
||||||
|
libdir = File.expand_path(File.dirname(__FILE__))
|
||||||
|
$LOAD_PATH.unshift(libdir) unless $LOAD_PATH.include?(libdir)
|
||||||
|
|
||||||
|
# Require Thor since that's what the whole CLI is built around
|
||||||
|
require 'thor'
|
||||||
|
require 'thor/group'
|
||||||
|
|
||||||
|
# Templates Module
|
||||||
|
module Middleman
|
||||||
|
module Templates
|
||||||
|
|
||||||
|
# Static methods
|
||||||
|
class << self
|
||||||
|
|
||||||
|
# Get list of registered templates and add new ones
|
||||||
|
#
|
||||||
|
# Middleman::Templates.register(:ext_name, klass)
|
||||||
|
#
|
||||||
|
# @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 register(name=nil, klass=nil)
|
||||||
|
@_template_mappings ||= {}
|
||||||
|
@_template_mappings[name] = klass if name && klass
|
||||||
|
@_template_mappings
|
||||||
|
end
|
||||||
|
|
||||||
|
# Middleman::Templates.register(name, klass)
|
||||||
|
alias :registered :register
|
||||||
|
end
|
||||||
|
|
||||||
|
# Base Template class. Handles basic options and paths.
|
||||||
|
class Base < ::Thor::Group
|
||||||
|
include Thor::Actions
|
||||||
|
|
||||||
|
def initialize(names, options)
|
||||||
|
super
|
||||||
|
source_paths << File.join(File.dirname(__FILE__), 'middleman-templates')
|
||||||
|
end
|
||||||
|
|
||||||
|
# The gemfile template to use. Individual templates can define this class
|
||||||
|
# method to override the template path.
|
||||||
|
def self.gemfile_template
|
||||||
|
'shared/Gemfile.tt'
|
||||||
|
end
|
||||||
|
|
||||||
|
# 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'
|
||||||
|
|
||||||
|
# Output a config.ru file for Rack if --rack is passed
|
||||||
|
class_option :rack, :type => :boolean, :default => false
|
||||||
|
|
||||||
|
# Write a Rack config.ru file for project
|
||||||
|
# @return [void]
|
||||||
|
def generate_rack!
|
||||||
|
return unless options[:rack]
|
||||||
|
template 'shared/config.ru', File.join(location, 'config.ru')
|
||||||
|
end
|
||||||
|
|
||||||
|
class_option :'skip-bundle', :type => :boolean, :default => false
|
||||||
|
class_option :'skip-gemfile', :type => :boolean, :default => false
|
||||||
|
|
||||||
|
# Write a Bundler Gemfile file for project
|
||||||
|
# @return [void]
|
||||||
|
def generate_bundler!
|
||||||
|
return if options[:'skip-gemfile']
|
||||||
|
template self.class.gemfile_template, File.join(location, 'Gemfile')
|
||||||
|
|
||||||
|
return if options[:'skip-bundle']
|
||||||
|
inside(location) do
|
||||||
|
::Middleman::Cli::Bundle.new.invoke(:bundle)
|
||||||
|
end unless ENV['TEST']
|
||||||
|
end
|
||||||
|
|
||||||
|
# Output a .gitignore file
|
||||||
|
class_option :'skip-git', :type => :boolean, :default => false
|
||||||
|
|
||||||
|
# Write a .gitignore file for project
|
||||||
|
# @return [void]
|
||||||
|
def generate_gitignore!
|
||||||
|
return if options[:'skip-git']
|
||||||
|
copy_file 'shared/gitignore', File.join(location, '.gitignore')
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
Dir.glob(File.expand_path("../middleman-templates/*.rb", __FILE__), &method(:require))
|
Before Width: | Height: | Size: 2.7 KiB After Width: | Height: | Size: 2.7 KiB |
Before Width: | Height: | Size: 25 KiB After Width: | Height: | Size: 25 KiB |
Before Width: | Height: | Size: 2 KiB After Width: | Height: | Size: 2 KiB |
Before Width: | Height: | Size: 1.8 KiB After Width: | Height: | Size: 1.8 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 1.3 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 1.1 KiB After Width: | Height: | Size: 1.1 KiB |
Before Width: | Height: | Size: 318 B After Width: | Height: | Size: 318 B |
0
middleman-templates/lib/middleman-templates/html5/source/img/.gitignore
vendored
Executable file
Before Width: | Height: | Size: 3 KiB After Width: | Height: | Size: 3 KiB |
Before Width: | Height: | Size: 17 KiB After Width: | Height: | Size: 17 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 2.4 KiB |
Before Width: | Height: | Size: 1.9 KiB After Width: | Height: | Size: 1.9 KiB |
Before Width: | Height: | Size: 4.4 KiB After Width: | Height: | Size: 4.4 KiB |
Before Width: | Height: | Size: 704 B After Width: | Height: | Size: 704 B |
Before Width: | Height: | Size: 206 B After Width: | Height: | Size: 206 B |
Before Width: | Height: | Size: 3.7 KiB After Width: | Height: | Size: 3.7 KiB |