middleman/middleman-cli/lib/middleman-cli/extension.rb

43 lines
1.4 KiB
Ruby
Raw Normal View History

2012-05-03 00:59:36 +02:00
# CLI Module
module Middleman::Cli
# A thor task for creating new projects
2015-01-04 21:23:35 +01:00
class Extension < Thor::Group
2012-05-03 00:59:36 +02:00
include Thor::Actions
2012-05-03 00:59:36 +02:00
check_unknown_options!
2012-05-03 00:59:36 +02:00
# Required path for the new project to be generated
2014-04-29 19:50:21 +02:00
argument :name, type: :string
2013-12-28 19:14:15 +01:00
# Template files are relative to this file
# @return [String]
def self.source_root
2014-01-03 01:34:08 +01:00
File.join(File.dirname(__FILE__), 'templates')
end
2013-12-28 19:14:15 +01:00
2015-01-04 21:23:35 +01:00
class_option 'skip-git',
type: :boolean,
default: false,
desc: 'Skip Git ignores and keeps'
# Output a .gitignore file
class_option :git, type: :boolean, default: true
2012-05-03 00:59:36 +02:00
# The extension task
# @param [String] name
def extension
copy_file 'extension/gitignore', File.join(name, '.gitignore') unless options[:'skip-git']
2014-01-03 01:34:08 +01:00
template 'extension/Rakefile', File.join(name, 'Rakefile')
template 'extension/gemspec', File.join(name, "#{name}.gemspec")
template 'extension/Gemfile', File.join(name, 'Gemfile')
template 'extension/lib/middleman_extension.rb', File.join(name, 'lib', 'middleman_extension.rb')
template 'extension/lib/lib.rb', File.join(name, 'lib', "#{name}.rb")
template 'extension/features/support/env.rb', File.join(name, 'features', 'support', 'env.rb')
empty_directory File.join(name, 'fixtures')
2012-05-03 00:59:36 +02:00
end
2015-01-04 21:23:35 +01:00
# Add to CLI
Base.register(self, 'extension', 'extension [options]', 'Create a new Middleman extension')
2012-05-03 00:59:36 +02:00
end
end