From a6d2370fc42311c30100c22e27709823cc9aff65 Mon Sep 17 00:00:00 2001 From: Thomas Reynolds Date: Sat, 16 Apr 2011 16:23:10 -0700 Subject: [PATCH] Support custom templates in the user's ~/.middleman directory --- lib/middleman/templates.rb | 13 +++++++++---- lib/middleman/templates/local.rb | 20 ++++++++++++++++++++ 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 lib/middleman/templates/local.rb diff --git a/lib/middleman/templates.rb b/lib/middleman/templates.rb index 45d683f3..4da13659 100644 --- a/lib/middleman/templates.rb +++ b/lib/middleman/templates.rb @@ -19,13 +19,18 @@ module Middleman::Templates include Thor::Actions argument :location, :type => :string - class_option :css_dir, :default => "stylesheets", :desc => 'The path to the css files' - class_option :js_dir, :default => "javascripts", :desc => 'The path to the javascript files' - class_option :images_dir, :default => "images", :desc => 'The path to the image files' + class_option :template, :default => "default" + class_option :css_dir, :default => "stylesheets" + class_option :js_dir, :default => "javascripts" + class_option :images_dir, :default => "images" end end # Default template require "middleman/templates/default" + # HTML5 template -require "middleman/templates/html5" \ No newline at end of file +require "middleman/templates/html5" + +# Local templates +require "middleman/templates/local" \ No newline at end of file diff --git a/lib/middleman/templates/local.rb b/lib/middleman/templates/local.rb new file mode 100644 index 00000000..affaf8da --- /dev/null +++ b/lib/middleman/templates/local.rb @@ -0,0 +1,20 @@ +module Middleman + def self.templates_path + File.join(`cd ~ && pwd`.chomp, ".middleman") + end +end + +class Middleman::Templates::Local < Middleman::Templates::Base + def self.source_root + Middleman.templates_path + end + + def build_scaffold + directory options[:template].to_s, location + end +end + +Dir[File.join(Middleman.templates_path, "*")].each do |dir| + next unless File.directory?(dir) + Middleman::Templates.register(File.basename(dir).to_sym, Middleman::Templates::Local) +end \ No newline at end of file