mirror of
https://github.com/middleman/middleman.git
synced 2022-11-09 12:20:27 -05:00
Fix custom commands for Ruby 1.9.x
This commit is contained in:
parent
21388f2103
commit
98b2b293c1
9 changed files with 67 additions and 34 deletions
|
@ -50,7 +50,7 @@ module Middleman
|
||||||
|
|
||||||
def start_cli!
|
def start_cli!
|
||||||
require 'middleman'
|
require 'middleman'
|
||||||
Middleman::CLI::Base.start
|
Middleman::Cli::Base.start
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -45,3 +45,8 @@ Feature: Builder
|
||||||
Scenario: Build with errors
|
Scenario: Build with errors
|
||||||
Given a built app at "build-with-errors-app"
|
Given a built app at "build-with-errors-app"
|
||||||
Then the exit status should be 1
|
Then the exit status should be 1
|
||||||
|
|
||||||
|
Scenario: Build alias (b)
|
||||||
|
Given a fixture app "test-app"
|
||||||
|
When I run `middleman b`
|
||||||
|
Then was successfully built
|
|
@ -15,6 +15,18 @@ Feature: Middleman CLI
|
||||||
| index.html.erb |
|
| index.html.erb |
|
||||||
| layout.erb |
|
| layout.erb |
|
||||||
| stylesheets/site.css.scss |
|
| stylesheets/site.css.scss |
|
||||||
|
|
||||||
|
Scenario: Create a new project (alias i)
|
||||||
|
When I run `middleman i MY_PROJECT`
|
||||||
|
Then a directory named "MY_PROJECT" should exist
|
||||||
|
|
||||||
|
Scenario: Create a new project (alias i)
|
||||||
|
When I run `middleman new MY_PROJECT`
|
||||||
|
Then a directory named "MY_PROJECT" should exist
|
||||||
|
|
||||||
|
Scenario: Create a new project (alias i)
|
||||||
|
When I run `middleman n MY_PROJECT`
|
||||||
|
Then a directory named "MY_PROJECT" should exist
|
||||||
|
|
||||||
Scenario: Create a new project with Rack
|
Scenario: Create a new project with Rack
|
||||||
When I run `middleman init MY_PROJECT --rack`
|
When I run `middleman init MY_PROJECT --rack`
|
||||||
|
|
|
@ -7,4 +7,4 @@ class HelloWorld < Thor
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Middleman::CLI::Base.register(HelloWorld, :hello, "hello", "Say hello")
|
Middleman::Cli::Base.register(HelloWorld, :hello, "hello", "Say hello")
|
|
@ -15,10 +15,10 @@ module Middleman
|
||||||
autoload :Templates, "middleman/templates"
|
autoload :Templates, "middleman/templates"
|
||||||
autoload :Guard, "middleman/guard"
|
autoload :Guard, "middleman/guard"
|
||||||
|
|
||||||
module CLI
|
module Cli
|
||||||
autoload :Base, "middleman/cli"
|
autoload :Base, "middleman/cli"
|
||||||
autoload :Build, "middleman/cli/build"
|
autoload :Build, "middleman/cli/build"
|
||||||
autoload :Templates, "middleman/cli/templates"
|
autoload :Init, "middleman/cli/init"
|
||||||
autoload :Server, "middleman/cli/server"
|
autoload :Server, "middleman/cli/server"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ require 'thor'
|
||||||
require "thor/group"
|
require "thor/group"
|
||||||
|
|
||||||
# CLI Module
|
# CLI Module
|
||||||
module Middleman::CLI
|
module Middleman::Cli
|
||||||
|
|
||||||
class Base < Thor
|
class Base < Thor
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
|
@ -22,6 +22,19 @@ module Middleman::CLI
|
||||||
say "Middleman #{Middleman::VERSION}"
|
say "Middleman #{Middleman::VERSION}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def method_missing(meth, *args)
|
||||||
|
meth = meth.to_s
|
||||||
|
|
||||||
|
if self.class.map.has_key?(meth)
|
||||||
|
meth = self.class.map[meth]
|
||||||
|
end
|
||||||
|
|
||||||
|
# initialize_thorfiles(meth)
|
||||||
|
klass, task = Thor::Util.find_class_and_task_by_namespace("#{meth}:#{meth}")
|
||||||
|
args.unshift(task) if task
|
||||||
|
klass.start(args, :shell => self.shell)
|
||||||
|
end
|
||||||
|
|
||||||
private
|
private
|
||||||
|
|
||||||
def help_check
|
def help_check
|
||||||
|
@ -31,6 +44,6 @@ module Middleman::CLI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
require "middleman/cli/templates"
|
require "middleman/cli/init"
|
||||||
require "middleman/cli/server"
|
require "middleman/cli/server"
|
||||||
require "middleman/cli/build"
|
require "middleman/cli/build"
|
|
@ -1,23 +1,25 @@
|
||||||
require "rack"
|
require "rack"
|
||||||
require "rack/test"
|
require "rack/test"
|
||||||
|
|
||||||
module Middleman::CLI
|
module Middleman::Cli
|
||||||
class Build < Thor::Group
|
class Build < Thor
|
||||||
include Thor::Actions
|
include Thor::Actions
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
desc "build [options]"
|
namespace :build
|
||||||
class_option :relative,
|
|
||||||
|
desc "build [options]", "Builds the static site for deployment"
|
||||||
|
method_option :relative,
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:aliases => "-r",
|
:aliases => "-r",
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Force relative urls'
|
:desc => 'Force relative urls'
|
||||||
class_option :clean,
|
method_option :clean,
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:aliases => "-c",
|
:aliases => "-c",
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Removes orpahand files or directories from build'
|
:desc => 'Removes orpahand files or directories from build'
|
||||||
class_option :glob,
|
method_option :glob,
|
||||||
:type => :string,
|
:type => :string,
|
||||||
:aliases => "-g",
|
:aliases => "-g",
|
||||||
:default => nil,
|
:default => nil,
|
||||||
|
@ -185,6 +187,5 @@ module Middleman::CLI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.register(Build, :build, "build [options]", "Builds the static site for deployment")
|
|
||||||
Base.map({ "b" => "build" })
|
Base.map({ "b" => "build" })
|
||||||
end
|
end
|
|
@ -1,32 +1,34 @@
|
||||||
module Middleman::CLI
|
module Middleman::Cli
|
||||||
class Templates < Thor::Group
|
class Init < Thor
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
desc "init NAME [options]"
|
namespace :init
|
||||||
|
|
||||||
|
desc "init NAME [options]", "Create new project NAME"
|
||||||
available_templates = ::Middleman::Templates.registered.keys.join(", ")
|
available_templates = ::Middleman::Templates.registered.keys.join(", ")
|
||||||
argument :name
|
# argument :name
|
||||||
class_option "template",
|
method_option "template",
|
||||||
:aliases => "-T",
|
:aliases => "-T",
|
||||||
:default => "default",
|
:default => "default",
|
||||||
:desc => "Use a project template: #{available_templates}"
|
:desc => "Use a project template: #{available_templates}"
|
||||||
class_option "css_dir",
|
method_option "css_dir",
|
||||||
:default => "stylesheets",
|
:default => "stylesheets",
|
||||||
:desc => 'The path to the css files'
|
:desc => 'The path to the css files'
|
||||||
class_option "js_dir",
|
method_option "js_dir",
|
||||||
:default => "javascripts",
|
:default => "javascripts",
|
||||||
:desc => 'The path to the javascript files'
|
:desc => 'The path to the javascript files'
|
||||||
class_option "images_dir",
|
method_option "images_dir",
|
||||||
:default => "images",
|
:default => "images",
|
||||||
:desc => 'The path to the image files'
|
:desc => 'The path to the image files'
|
||||||
class_option "rack",
|
method_option "rack",
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Include a config.ru file'
|
:desc => 'Include a config.ru file'
|
||||||
class_option "bundler",
|
method_option "bundler",
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Create a Gemfile and use Bundler to manage gems'
|
:desc => 'Create a Gemfile and use Bundler to manage gems'
|
||||||
def init
|
def init(name)
|
||||||
key = options[:template].to_sym
|
key = options[:template].to_sym
|
||||||
unless ::Middleman::Templates.registered.has_key?(key)
|
unless ::Middleman::Templates.registered.has_key?(key)
|
||||||
raise Thor::Error.new "Unknown project template '#{key}'"
|
raise Thor::Error.new "Unknown project template '#{key}'"
|
||||||
|
@ -37,7 +39,6 @@ module Middleman::CLI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.register(Templates, :init, "init NAME [options]", "Create new project NAME")
|
|
||||||
Base.map({
|
Base.map({
|
||||||
"i" => "init",
|
"i" => "init",
|
||||||
"new" => "init",
|
"new" => "init",
|
|
@ -1,23 +1,25 @@
|
||||||
module Middleman::CLI
|
module Middleman::Cli
|
||||||
class Server < Thor::Group
|
class Server < Thor
|
||||||
check_unknown_options!
|
check_unknown_options!
|
||||||
|
|
||||||
desc "server [options]"
|
namespace :server
|
||||||
class_option "environment",
|
|
||||||
|
desc "server [options]", "Start the preview server"
|
||||||
|
method_option "environment",
|
||||||
:aliases => "-e",
|
:aliases => "-e",
|
||||||
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
:default => ENV['MM_ENV'] || ENV['RACK_ENV'] || 'development',
|
||||||
:desc => "The environment Middleman will run under"
|
:desc => "The environment Middleman will run under"
|
||||||
class_option :host,
|
method_option :host,
|
||||||
:type => :string,
|
:type => :string,
|
||||||
:aliases => "-h",
|
:aliases => "-h",
|
||||||
# :required => true,
|
# :required => true,
|
||||||
:default => "0.0.0.0",
|
:default => "0.0.0.0",
|
||||||
:desc => "Bind to HOST address"
|
:desc => "Bind to HOST address"
|
||||||
class_option "port",
|
method_option "port",
|
||||||
:aliases => "-p",
|
:aliases => "-p",
|
||||||
:default => "4567",
|
:default => "4567",
|
||||||
:desc => "The port Middleman will listen on"
|
:desc => "The port Middleman will listen on"
|
||||||
class_option "debug",
|
method_option "debug",
|
||||||
:type => :boolean,
|
:type => :boolean,
|
||||||
:default => false,
|
:default => false,
|
||||||
:desc => 'Print debug messages'
|
:desc => 'Print debug messages'
|
||||||
|
@ -34,7 +36,6 @@ module Middleman::CLI
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
Base.register(Server, :server, "server [options]", "Start the preview server")
|
|
||||||
Base.map({ "s" => "server" })
|
Base.map({ "s" => "server" })
|
||||||
Base.default_task :server
|
Base.default_task :server
|
||||||
end
|
end
|
Loading…
Add table
Reference in a new issue