new extension cli

This commit is contained in:
Thomas Reynolds 2012-05-02 15:59:36 -07:00
parent a7adc20b47
commit 0be82d371e
10 changed files with 145 additions and 0 deletions

View file

@ -0,0 +1,13 @@
Feature: Middleman New Extension CLI
Scenario: Create a new extension scaffold
Given I run `middleman extension my-extension-library`
Then the exit status should be 0
When I cd to "my-extension-library"
Then the following files should exist:
| Gemfile |
| Rakefile |
| my-extension-library.gemspec |
| features/support/env.rb |
| lib/middleman_extension.rb |
| lib/my-extension-library.rb |

View file

@ -8,6 +8,7 @@ module Middleman::Cli
module Cli module Cli
autoload :Build, "middleman-core/cli/build" autoload :Build, "middleman-core/cli/build"
autoload :Init, "middleman-core/cli/init" autoload :Init, "middleman-core/cli/init"
autoload :Extension, "middleman-core/cli/extension"
autoload :Server, "middleman-core/cli/server" autoload :Server, "middleman-core/cli/server"
end end
@ -73,5 +74,6 @@ end
# Include the core CLI items # Include the core CLI items
require "middleman-core/cli/init" require "middleman-core/cli/init"
require "middleman-core/cli/extension"
require "middleman-core/cli/server" require "middleman-core/cli/server"
require "middleman-core/cli/build" require "middleman-core/cli/build"

View file

@ -0,0 +1,36 @@
# CLI Module
module Middleman::Cli
# A thor task for creating new projects
class Extension < Thor
include Thor::Actions
check_unknown_options!
namespace :extension
# Required path for the new project to be generated
argument :name, :type => :string
desc "extension NAME [options]", "Create Middleman extension scaffold NAME"
# The extension task
# @param [String] name
def extension
template "Rakefile", File.join(name, "Rakefile")
template "gemspec", File.join(name, "#{name}.gemspec")
template "Gemfile", File.join(name, "Gemfile")
template "lib/middleman_extension.rb", File.join(name, "lib", "middleman_extension.rb")
template "lib/lib.rb", File.join(name, "lib", "#{name}.rb")
template "features/support/env.rb", File.join(name, "features", "support", "env.rb")
empty_directory File.join(name, "fixtures")
end
# Template files are relative to this file
# @return [String]
def self.source_root
File.join(File.dirname(__FILE__), "..", "templates", "extension")
end
end
end

View file

@ -0,0 +1,4 @@
source :rubygems
# Specify your gem's dependencies in <%= name %>.gemspec
gemspec

View file

@ -0,0 +1,12 @@
require 'bundler'
Bundler::GemHelper.install_tasks
require 'cucumber/rake/task'
Cucumber::Rake::Task.new(:cucumber, 'Run features that should pass') do |t|
t.cucumber_opts = "--color --tags ~@wip --strict --format #{ENV['CUCUMBER_FORMAT'] || 'Fivemat'}"
end
require 'rake/clean'
task :test => ["cucumber"]

View file

@ -0,0 +1,4 @@
PROJECT_ROOT_PATH = File.dirname(File.dirname(File.dirname(__FILE__)))
require "middleman-core"
require "middleman-core/step_definitions"
require File.join(PROJECT_ROOT_PATH, 'lib', '<%= name %>')

View file

@ -0,0 +1,24 @@
# -*- encoding: utf-8 -*-
$:.push File.expand_path("../lib", __FILE__)
Gem::Specification.new do |s|
s.name = "<%= name %>"
s.version = "0.0.1"
s.platform = Gem::Platform::RUBY
# s.authors = ["Your Name"]
# s.email = ["email@example.com"]
# s.homepage = "http://example.com"
# s.summary = %q{A short summary of your extension}
# s.description = %q{A longer description of your extension}
s.files = `git ls-files`.split("\n")
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
s.require_paths = ["lib"]
# The version of middleman-core your extension depends on
s.add_runtime_dependency("middleman-core", [">= 3.0.0.beta.2"])
# Additional dependencies
# s.add_runtime_dependency("gem-name", "gem-version")
end

View file

@ -0,0 +1,49 @@
# Require core library
require "middleman-core"
# Extension namespace
module MyExtension
class << self
# Called when user `activate`s your extension
def registered(app, options={})
# Setup extension-specific config
app.set :config_variable, false
# Include class methods
# app.extend ClassMethods
# Include instance methods
# app.send :include, InstanceMethods
app.after_configuration do
# Do something
# config_variable is now either the default or the user's
# setting from config.rb
end
end
alias :included :registered
end
# module ClassMethods
# def a_class_method
# end
# end
# module InstanceMethods
# def an_instance_method
# end
# end
end
# Register extensions which can be activated
# Make sure we have the version of Middleman we expect
# ::Middleman::Extensions.register(:extension_name, ">= 3.0.0.beta.2") do
#
# # Return the extension module
# ::MyExtension
#
# end

View file

@ -0,0 +1 @@
require "<%= name %>"