Skip to content

Commit

Permalink
Merge pull request #1708 from tyabe/add_no-helper_option
Browse files Browse the repository at this point in the history
[padrino-gen] Add 'no-helper' option to controller generator
  • Loading branch information
ujifgc committed Jul 1, 2014
2 parents ab3e5c3 + c6cd246 commit 773c027
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 11 deletions.
23 changes: 12 additions & 11 deletions padrino-gen/lib/padrino-gen/generators/controller.rb
Expand Up @@ -16,15 +16,16 @@ def self.banner; "padrino-gen controller [name]"; end

desc "Description:\n\n\tpadrino-gen controller generates a new Padrino controller"

argument :name, :desc => 'The name of your padrino controller'
argument :fields, :desc => 'The fields for the controller', :default => [], :type => :array
class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
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
argument :name, :desc => 'The name of your padrino controller'
argument :fields, :desc => 'The fields for the controller', :default => [], :type => :array
class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
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
class_option :'no-helper',:desc => 'Not generate helper', :default => false, :type => :boolean

# Show help if no ARGV given
require_arguments!
Expand Down Expand Up @@ -52,12 +53,12 @@ def create_controller

self.behavior = :revoke if options[:destroy]
template 'templates/controller.rb.tt', destination_root(app, 'controllers', "#{name.to_s.underscore}.rb")
template 'templates/helper.rb.tt', destination_root(app, 'helpers', "#{name.to_s.underscore}_helper.rb")
template 'templates/helper.rb.tt', destination_root(app, 'helpers', "#{name.to_s.underscore}_helper.rb") unless options[:'no-helper']
empty_directory destination_root(app, "/views/#{name.to_s.underscore}")
include_component_module_for(:test)
if test?
generate_controller_test(name)
generate_helper_test(@helper_name, @project_name, @app_name)
generate_helper_test(@helper_name, @project_name, @app_name) unless options[:'no-helper']
end
else
say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
Expand Down
13 changes: 13 additions & 0 deletions padrino-gen/test/test_controller_generator.rb
Expand Up @@ -185,6 +185,19 @@ def teardown
assert_match_in_file(/get :test do\n\n end\n/m, @controller_path)
assert_match_in_file(/post :yada do\n\n end\n/m, @controller_path)
end

describe "with 'no-helper' option" do
it 'should not generate helper within existing project' do
capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=rspec') }
capture_io { generate(:controller, 'DemoItems', "-r=#{@apptmp}/sample_project", '--no-helper') }
assert_file_exists("#{@apptmp}/sample_project/app/views/demo_items")
assert_file_exists("#{@apptmp}/sample_project/app/controllers/demo_items.rb")
assert_file_exists("#{@apptmp}/sample_project/spec/app/controllers/demo_items_controller_spec.rb")
assert_no_file_exists("#{@apptmp}/sample_project/app/helpers/demo_items_helper.rb")
assert_no_file_exists("#{@apptmp}/sample_project/spec/app/helpers/demo_items_helper_spec.rb")
end
end

end

describe "the controller destroy option" do
Expand Down

0 comments on commit 773c027

Please sign in to comment.