lib/padrino-gen/generators/controller.rb in padrino-gen-0.11.3 vs lib/padrino-gen/generators/controller.rb in padrino-gen-0.11.4
- old
+ new
@@ -3,19 +3,15 @@
##
# Responsible for generating route controllers and associated tests within a Padrino application.
#
class Controller < Thor::Group
- # Add this generator to our padrino-gen
Padrino::Generators.add_generator(:controller, self)
- # Define the source template root
def self.source_root; File.expand_path(File.dirname(__FILE__)); end
- # Defines the banner for this CLI generator
def self.banner; "padrino-gen controller [name]"; end
- # Include related modules
include Thor::Actions
include Padrino::Generators::Actions
include Padrino::Generators::Components::Actions
desc "Description:\n\n\tpadrino-gen controller generates a new Padrino controller"
@@ -28,16 +24,16 @@
class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
class_option :layout, :desc => 'The layout for the controller', :aliases => '-l', :default => '', :type => :string
class_option :parent, :desc => 'The parent of the controller', :aliases => '-p', :default => '', :type => :string
class_option :provides, :desc => 'the formats provided by the controller', :aliases => '-f', :default => '', :type => :string
- # Show help if no argv given
+ # Show help if no ARGV given
require_arguments!
+ ##
# Execute controller generation
#
- # @api private
def create_controller
self.destination_root = options[:root]
if in_app_root?
app = options[:app]
check_app_existence(app)
@@ -45,11 +41,11 @@
@project_name = fetch_project_name(app) if @project_name.empty?
@app_name = fetch_app_name(app)
@actions = controller_actions(fields)
@controller = name.to_s.underscore
@layout = options[:layout] if options[:layout] && !options[:layout].empty?
-
+
block_opts = []
block_opts << ":parent => :#{options[:parent]}" if options[:parent] && !options[:parent].empty?
block_opts << ":provides => [#{options[:provides]}]" if options[:provides] && !options[:provides].empty?
@block_opts_string = block_opts.join(', ') unless block_opts.empty?
@@ -61,8 +57,8 @@
generate_controller_test(name) if test?
else
say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
end
end
- end # Controller
- end # Generators
-end # Padrino
+ end
+ end
+end