From 7127401aa241939fa7f14c0604aa187546d3b7ef Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Thu, 30 May 2013 21:16:07 -0700 Subject: [PATCH 1/3] Micro-optimize some regexes --- middleman-core/lib/middleman-core/sitemap.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/middleman-core/lib/middleman-core/sitemap.rb b/middleman-core/lib/middleman-core/sitemap.rb index 958d6427..88d2bbb9 100644 --- a/middleman-core/lib/middleman-core/sitemap.rb +++ b/middleman-core/lib/middleman-core/sitemap.rb @@ -29,11 +29,11 @@ module Middleman # Files starting with an dot, but not .htaccess :source_dotfiles => proc { |file| - file =~ %r{/\.} && file !~ %r{/\.(htaccess|htpasswd)} + file =~ %r{/\.} && file !~ %r{/\.ht(access|passwd)} }, # Files starting with an underscore, but not a double-underscore - :partials => proc { |file| file =~ %r{/_} && file !~ %r{/__} }, + :partials => proc { |file| file =~ %r{/_[^_]} }, :layout => proc { |file, app| file.start_with?(File.join(app.config[:source], 'layout.')) || file.start_with?(File.join(app.config[:source], 'layouts/')) From dbcb28dded30ccf400849fe576052a560b487f73 Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Thu, 30 May 2013 21:16:30 -0700 Subject: [PATCH 2/3] 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. --- CHANGELOG.md | 2 ++ .../lib/middleman-core/templates.rb | 13 +++++++++-- .../lib/middleman-core/templates/empty.rb | 23 +++++++++++++++++++ .../middleman-core/templates/empty/Gemfile.tt | 3 +++ 4 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 middleman-core/lib/middleman-core/templates/empty.rb create mode 100644 middleman-core/lib/middleman-core/templates/empty/Gemfile.tt diff --git a/CHANGELOG.md b/CHANGELOG.md index 99122bad..879c6c93 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/middleman-core/lib/middleman-core/templates.rb b/middleman-core/lib/middleman-core/templates.rb index 336b81e0..dd9bb6c7 100644 --- a/middleman-core/lib/middleman-core/templates.rb +++ b/middleman-core/lib/middleman-core/templates.rb @@ -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 @@ -90,4 +96,7 @@ require "middleman-core/templates/mobile" require "middleman-more/templates/smacss" # Local templates -require "middleman-core/templates/local" \ No newline at end of file +require "middleman-core/templates/local" + +# Barebones template +require "middleman-core/templates/empty" diff --git a/middleman-core/lib/middleman-core/templates/empty.rb b/middleman-core/lib/middleman-core/templates/empty.rb new file mode 100644 index 00000000..c06ab262 --- /dev/null +++ b/middleman-core/lib/middleman-core/templates/empty.rb @@ -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) diff --git a/middleman-core/lib/middleman-core/templates/empty/Gemfile.tt b/middleman-core/lib/middleman-core/templates/empty/Gemfile.tt new file mode 100644 index 00000000..463687c3 --- /dev/null +++ b/middleman-core/lib/middleman-core/templates/empty/Gemfile.tt @@ -0,0 +1,3 @@ +source 'https://rubygems.org' + +gem "middleman", "~><%= Middleman::VERSION %>" From 85c6a8faa353ded0d042b89e08b9f58607bed7fb Mon Sep 17 00:00:00 2001 From: Ben Hollis Date: Thu, 30 May 2013 21:21:13 -0700 Subject: [PATCH 3/3] Fix changelog --- CHANGELOG.md | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 879c6c93..63b15580 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,6 +12,9 @@ 3.1.0.rc.2 === +* 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 * Track test coverage with simplecov * i18n only autodetects languages in the `locales` root * Frontmatter cache fixes solve performance regressions found in 3.1.x @@ -22,9 +25,6 @@ 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 * The i18n extension now supports providing localized templates as separate files, like index.es.html.haml. #816, #823