Add an "empty" template and let template classes override the "Gemfile" template.

Custom template classes can define "self.gemfile_template" to return the path to their own Gemfile template, without having to reimplement our generate_bundler! task.
This commit is contained in:
Ben Hollis 2013-05-30 21:16:30 -07:00
parent 7127401aa2
commit dbcb28dded
4 changed files with 39 additions and 2 deletions

View file

@ -22,6 +22,8 @@
3.1.0.rc.1
===
* Custom template classes can now override the file used for creating the project Gemfile.
* Add an "empty" template that produces the minimum necessary structure for a Middleman project.
* Fix ignoring layouts from the sitemap when the source directory has been set to something other than 'source'. #896
* Move more into core, autoloaded if gems are available.
* DataStore may now be accessed like a hash with #[] and #has_key?. #880

View file

@ -34,6 +34,12 @@ module Middleman::Templates
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
@ -57,7 +63,7 @@ module Middleman::Templates
# @return [void]
def generate_bundler!
return if options[:'skip-gemfile']
template "shared/Gemfile.tt", File.join(location, "Gemfile")
template self.class.gemfile_template, File.join(location, "Gemfile")
return if options[:'skip-bundle']
inside(location) do
@ -91,3 +97,6 @@ require "middleman-more/templates/smacss"
# Local templates
require "middleman-core/templates/local"
# Barebones template
require "middleman-core/templates/empty"

View file

@ -0,0 +1,23 @@
# A barebones template with nothing much in it
class Middleman::Templates::Empty < Middleman::Templates::Base
# Template files are relative to this file
# @return [String]
def self.source_root
File.dirname(__FILE__)
end
def self.gemfile_template
"empty/Gemfile.tt"
end
# Actually output the files
# @return [void]
def build_scaffold!
create_file File.join(location, "config.rb"), "\n"
empty_directory File.join(location, "source")
end
end
# Register this template
Middleman::Templates.register(:empty, Middleman::Templates::Empty)

View file

@ -0,0 +1,3 @@
source 'https://rubygems.org'
gem "middleman", "~><%= Middleman::VERSION %>"