From 260b7c9f1b601d455aa16dca7d50dc6272c0368c Mon Sep 17 00:00:00 2001 From: tdreyno Date: Sat, 5 Feb 2011 10:32:04 -0800 Subject: [PATCH] Init generator on Thor --- Rakefile | 2 +- bin/mm-init | 43 ++++++++----------- .../template/{config.rbt => config.tt} | 24 +++++------ middleman.gemspec | 14 +++--- 4 files changed, 38 insertions(+), 45 deletions(-) rename lib/middleman/template/{config.rbt => config.tt} (77%) diff --git a/Rakefile b/Rakefile index 684dde17..b4b77f9e 100644 --- a/Rakefile +++ b/Rakefile @@ -7,4 +7,4 @@ Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t| t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'pretty'}" end -task :default => :cucumber +task :test => :cucumber diff --git a/bin/mm-init b/bin/mm-init index a1a3f8d9..a157473a 100755 --- a/bin/mm-init +++ b/bin/mm-init @@ -1,37 +1,30 @@ #!/usr/bin/env ruby require File.join(File.dirname(File.dirname(__FILE__)), 'lib', 'middleman') -require 'templater' +require "thor" +require "thor/group" -module Generators - extend Templater::Manifold - desc "Generator for streamlining staticmatic" - - class NewSite < Templater::Generator - desc "Creates a new middleman scaffold." - first_argument :location, :required => true, :desc => "Project location" +module Middleman + class Generator < ::Thor::Group + include Thor::Actions - option :css_dir, :desc => 'The path to the css files' - option :js_dir, :desc => 'The path to the javascript files' - option :images_dir, :desc => 'The path to the image files' - - def destination_root - File.expand_path(location) - end - def self.source_root File.join(File.dirname(__FILE__), '..', 'lib', 'middleman', 'template') end - template :config, "config.rb" - glob! :views - glob! :public + argument :location, :type => :string, :desc => "New project location" - empty_directory :stylesheets, "public/stylesheets"#, File.join("public", css_dir) - empty_directory :javascripts, "public/javascripts"#, File.join("public", js_dir) - empty_directory :images, "public/images"#, File.join("public", images_dir) + 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' + + def create_project + template "config.tt", File.join(location, "config.rb") + directory "views", File.join(location, "views") + empty_directory File.join(location, "public", options[:css_dir]) + empty_directory File.join(location, "public", options[:js_dir]) + empty_directory File.join(location, "public", options[:images_dir]) + end end - - add :setup, NewSite end -Generators.run_cli(Dir.pwd, 'mm-init', 1, %w(setup).concat(ARGV)) \ No newline at end of file +Middleman::Generator.start \ No newline at end of file diff --git a/lib/middleman/template/config.rbt b/lib/middleman/template/config.tt similarity index 77% rename from lib/middleman/template/config.rbt rename to lib/middleman/template/config.tt index 087496f6..0f43c0b6 100755 --- a/lib/middleman/template/config.rbt +++ b/lib/middleman/template/config.tt @@ -20,26 +20,26 @@ helpers do end end -<% if css_dir %> -set :css_dir, "<%= css_dir -%>" -<% else %> +<% if options[:css_dir] != "stylesheets" -%> +set :css_dir, "<%= options[:css_dir] -%>" +<% else -%> # Change the CSS directory # set :css_dir, "alternative_css_directory" -<% end %> +<% end -%> -<% if js_dir %> -set :js_dir, "<%= js_dir -%>" -<% else %> +<% if options[:js_dir] != "javascripts" -%> +set :js_dir, "<%= options[:js_dir] -%>" +<% else -%> # Change the JS directory # set :js_dir, "alternative_js_directory" -<% end %> +<% end -%> -<% if images_dir %> -set :images_dir, "<%= images_dir -%>" -<% else %> +<% if options[:images_dir] != "images" -%> +set :images_dir, "<%= options[:images_dir] -%>" +<% else -%> # Change the images directory # set :images_dir, "alternative_image_directory" -<% end %> +<% end -%> # Build-specific configuration configure :build do diff --git a/middleman.gemspec b/middleman.gemspec index 0094ab43..884585bc 100644 --- a/middleman.gemspec +++ b/middleman.gemspec @@ -22,22 +22,22 @@ Gem::Specification.new do |s| s.add_runtime_dependency("thin", ["~> 1.2.0"]) s.add_runtime_dependency("shotgun", ["~> 0.8.0"]) s.add_runtime_dependency("thor", ["~> 0.14.0"]) - s.add_runtime_dependency("tilt", ["~> 1.1"]) - s.add_runtime_dependency("sinatra", ["~> 1.0"]) + s.add_runtime_dependency("tilt", ["~> 1.2.0"]) + s.add_runtime_dependency("sinatra", ["~> 1.1.0"]) s.add_runtime_dependency("padrino-core", ["~> 0.9.0"]) s.add_runtime_dependency("padrino-helpers", ["~> 0.9.0"]) s.add_runtime_dependency("rack-test", ["~> 0.5.0"]) s.add_runtime_dependency("yui-compressor", ["~> 0.9.0"]) - s.add_runtime_dependency("haml", ["~> 3.0"]) - s.add_runtime_dependency("sass", ["3.1.0.alpha.218"]) - s.add_runtime_dependency("compass", ["0.11.beta.1"]) - s.add_runtime_dependency("oily_png") + s.add_runtime_dependency("haml", [">= 3.1.0.alpha.147"]) + s.add_runtime_dependency("sass", [">= 3.1.0.alpha.218"]) + s.add_runtime_dependency("compass", ["0.11.beta.2"]) + s.add_runtime_dependency("oily_png", ["~> 0.3.0"]) s.add_runtime_dependency("json_pure", ["~> 1.4.0"]) s.add_runtime_dependency("smusher", ["~> 0.4.5"]) s.add_runtime_dependency("compass-slickmap", ["~> 0.4.0"]) s.add_runtime_dependency("coffee-script", ["~> 2.1.0"]) s.add_runtime_dependency("less", ["~> 1.2.0"]) - s.add_development_dependency("cucumber", [">= 0"]) + s.add_development_dependency("cucumber", ["~> 0.10.0"]) s.add_development_dependency("rspec", [">= 0"]) end