padrino-gen 0.10.7 → 0.11.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (69) hide show
  1. checksums.yaml +7 -0
  2. data/lib/padrino-gen/generators/actions.rb +139 -102
  3. data/lib/padrino-gen/generators/app/app.rb.tt +55 -53
  4. data/lib/padrino-gen/generators/app.rb +16 -16
  5. data/lib/padrino-gen/generators/cli.rb +3 -3
  6. data/lib/padrino-gen/generators/components/actions.rb +1 -1
  7. data/lib/padrino-gen/generators/components/orms/activerecord.rb +22 -18
  8. data/lib/padrino-gen/generators/components/orms/couchrest.rb +1 -1
  9. data/lib/padrino-gen/generators/components/orms/datamapper.rb +2 -1
  10. data/lib/padrino-gen/generators/components/orms/{mini_record.rb → minirecord.rb} +9 -9
  11. data/lib/padrino-gen/generators/components/orms/mongoid.rb +60 -6
  12. data/lib/padrino-gen/generators/components/orms/mongomapper.rb +2 -2
  13. data/lib/padrino-gen/generators/components/orms/mongomatic.rb +2 -2
  14. data/lib/padrino-gen/generators/components/orms/ohm.rb +57 -10
  15. data/lib/padrino-gen/generators/components/orms/ripple.rb +1 -1
  16. data/lib/padrino-gen/generators/components/orms/sequel.rb +15 -6
  17. data/lib/padrino-gen/generators/components/stylesheets/compass.rb +1 -1
  18. data/lib/padrino-gen/generators/components/stylesheets/less.rb +1 -0
  19. data/lib/padrino-gen/generators/components/tests/bacon.rb +0 -2
  20. data/lib/padrino-gen/generators/components/tests/minitest.rb +0 -1
  21. data/lib/padrino-gen/generators/components/tests/riot.rb +0 -1
  22. data/lib/padrino-gen/generators/components/tests/rspec.rb +14 -15
  23. data/lib/padrino-gen/generators/components/tests/shoulda.rb +0 -1
  24. data/lib/padrino-gen/generators/components/tests/testspec.rb +0 -1
  25. data/lib/padrino-gen/generators/controller.rb +14 -11
  26. data/lib/padrino-gen/generators/mailer.rb +14 -11
  27. data/lib/padrino-gen/generators/migration.rb +5 -5
  28. data/lib/padrino-gen/generators/model.rb +8 -7
  29. data/lib/padrino-gen/generators/plugin.rb +15 -9
  30. data/lib/padrino-gen/generators/project/.gitignore +2 -1
  31. data/lib/padrino-gen/generators/project/config/apps.rb.tt +10 -8
  32. data/lib/padrino-gen/generators/project/config.ru +0 -0
  33. data/lib/padrino-gen/generators/project/public/favicon.ico +0 -0
  34. data/lib/padrino-gen/generators/project.rb +53 -25
  35. data/lib/padrino-gen/generators/runner.rb +1 -1
  36. data/lib/padrino-gen/generators/templates/Gemfile.tt +8 -3
  37. data/lib/padrino-gen/generators/templates/Rakefile.tt +8 -0
  38. data/lib/padrino-gen/generators/templates/controller.rb.tt +8 -9
  39. data/lib/padrino-gen/generators/templates/gem/README.md.tt +29 -0
  40. data/lib/padrino-gen/generators/templates/gem/gemspec.tt +19 -0
  41. data/lib/padrino-gen/generators/templates/gem/lib/libname/version.tt +3 -0
  42. data/lib/padrino-gen/generators/templates/gem/lib/libname.tt +6 -0
  43. data/lib/padrino-gen/generators/templates/helper.rb.tt +1 -1
  44. data/lib/padrino-gen/generators/templates/mailer.rb.tt +1 -1
  45. data/lib/padrino-gen/generators/templates/static/js/dojo.js +238 -1
  46. data/lib/padrino-gen/generators/templates/static/js/ext.js +38 -1
  47. data/lib/padrino-gen/generators/templates/static/js/jquery.js +4 -4
  48. data/lib/padrino-gen/generators/templates/static/js/mootools.js +335 -276
  49. data/lib/padrino-gen/generators/templates/static/js/protopak.js +1 -1
  50. data/lib/padrino-gen/generators/templates/static/js/right.js +7 -1
  51. data/lib/padrino-gen/generators/templates/static/ujs/jquery.js +76 -75
  52. data/lib/padrino-gen/padrino-tasks/activerecord.rb +8 -2
  53. data/lib/padrino-gen/padrino-tasks/database.rb +11 -0
  54. data/lib/padrino-gen/padrino-tasks/datamapper.rb +38 -12
  55. data/lib/padrino-gen/padrino-tasks/minirecord.rb +19 -0
  56. data/lib/padrino-gen/padrino-tasks/mongoid.rb +76 -18
  57. data/lib/padrino-gen/padrino-tasks/mongomapper.rb +9 -1
  58. data/lib/padrino-gen/padrino-tasks/sequel.rb +6 -1
  59. data/lib/padrino-gen.rb +2 -2
  60. data/padrino-gen.gemspec +0 -0
  61. data/test/helper.rb +1 -1
  62. data/test/test_app_generator.rb +23 -4
  63. data/test/test_controller_generator.rb +8 -8
  64. data/test/test_mailer_generator.rb +5 -5
  65. data/test/test_model_generator.rb +26 -23
  66. data/test/test_plugin_generator.rb +23 -0
  67. data/test/test_project_generator.rb +82 -47
  68. metadata +17 -17
  69. data/lib/padrino-gen/padrino-tasks/seed.rb +0 -5
@@ -52,7 +52,6 @@ describe "!NAME! Model" do
52
52
  end
53
53
  TEST
54
54
 
55
- # Setup the testing configuration helper and dependencies
56
55
  def setup_test
57
56
  require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
58
57
  require_dependencies 'bacon', :group => 'test'
@@ -60,7 +59,6 @@ def setup_test
60
59
  create_file destination_root("test/test.rake"), BACON_RAKE
61
60
  end
62
61
 
63
- # Generates a controller test given the controllers name
64
62
  def generate_controller_test(name)
65
63
  bacon_contents = BACON_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
66
64
  controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
@@ -62,7 +62,6 @@ def setup_test
62
62
  create_file destination_root("test/test.rake"), MINITEST_RAKE
63
63
  end
64
64
 
65
- # Generates a controller test given the controllers name
66
65
  def generate_controller_test(name)
67
66
  minitest_contents = MINITEST_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
68
67
  controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
@@ -86,7 +86,6 @@ def setup_test
86
86
  create_file destination_root("test/test.rake"), RIOT_RAKE
87
87
  end
88
88
 
89
- # Generates a controller test given the controllers name
90
89
  def generate_controller_test(name)
91
90
  riot_contents = RIOT_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
92
91
  controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
@@ -29,29 +29,29 @@ end
29
29
  TEST
30
30
 
31
31
  RSPEC_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
32
- require 'rspec/core/rake_task'
32
+ begin
33
+ require 'rspec/core/rake_task'
33
34
 
34
- spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }
35
+ spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }
35
36
 
36
- spec_tasks.each do |folder|
37
- RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
38
- t.pattern = "./spec/\#{folder}/**/*_spec.rb"
39
- t.rspec_opts = %w(-fs --color)
37
+ spec_tasks.each do |folder|
38
+ RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
39
+ t.pattern = "./spec/\#{folder}/**/*_spec.rb"
40
+ t.rspec_opts = %w(-fs --color)
41
+ end
40
42
  end
41
- end
42
43
 
43
- desc "Run complete application spec suite"
44
- task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
44
+ desc "Run complete application spec suite"
45
+ task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
46
+ rescue LoadError
47
+ puts "RSpec is not part of this bundle, skip specs."
48
+ end
45
49
  TEST
46
50
 
47
51
  RSPEC_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_MODEL_TEST)
48
52
  require 'spec_helper'
49
53
 
50
- describe "!NAME! Model" do
51
- let(:!DNAME!) { !NAME!.new }
52
- it 'can be created' do
53
- !DNAME!.should_not be_nil
54
- end
54
+ describe !NAME! do
55
55
  end
56
56
  TEST
57
57
 
@@ -62,7 +62,6 @@ def setup_test
62
62
  create_file destination_root("spec/spec.rake"), RSPEC_RAKE
63
63
  end
64
64
 
65
- # Generates a controller test given the controllers name
66
65
  def generate_controller_test(name)
67
66
  rspec_contents = RSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
68
67
  controller_spec_path = File.join('spec',options[:app],'controllers',"#{name.to_s.underscore}_controller_spec.rb")
@@ -69,7 +69,6 @@ def setup_test
69
69
  create_file destination_root("test/test.rake"), SHOULDA_RAKE
70
70
  end
71
71
 
72
- # Generates a controller test given the controllers name
73
72
  def generate_controller_test(name)
74
73
  shoulda_contents = SHOULDA_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
75
74
  controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
@@ -59,7 +59,6 @@ def setup_test
59
59
  create_file destination_root("test/test.rake"), TESTSPEC_RAKE
60
60
  end
61
61
 
62
- # Generates a controller test given the controllers name
63
62
  def generate_controller_test(name)
64
63
  testspec_contents = TESTSPEC_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
65
64
  controller_test_path = File.join('test',options[:app],'controllers',"#{name.to_s.underscore}_controller_test.rb")
@@ -20,11 +20,12 @@ module Padrino
20
20
 
21
21
  desc "Description:\n\n\tpadrino-gen controller generates a new Padrino controller"
22
22
 
23
- argument :name, :desc => "The name of your padrino controller"
24
- argument :fields, :desc => "The fields for the controller", :type => :array, :default => []
25
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
26
- class_option :app, :desc => "The application destination path", :aliases => '-a', :default => "/app", :type => :string
27
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
23
+ argument :name, :desc => 'The name of your padrino controller'
24
+ argument :fields, :desc => 'The fields for the controller', :default => [], :type => :array
25
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
26
+ class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
27
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
28
+ class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
28
29
 
29
30
  # Show help if no argv given
30
31
  require_arguments!
@@ -37,17 +38,19 @@ module Padrino
37
38
  if in_app_root?
38
39
  app = options[:app]
39
40
  check_app_existence(app)
40
- @app_name = fetch_app_name(app)
41
- @actions = controller_actions(fields)
42
- @controller = name.to_s.underscore
41
+ @project_name = options[:namespace].underscore.camelize
42
+ @project_name = fetch_project_name(app) if @project_name.empty?
43
+ @app_name = fetch_app_name(app)
44
+ @actions = controller_actions(fields)
45
+ @controller = name.to_s.underscore
43
46
  self.behavior = :revoke if options[:destroy]
44
- template "templates/controller.rb.tt", destination_root(app, "controllers", "#{name.to_s.underscore}.rb")
45
- template "templates/helper.rb.tt", destination_root(app, "helpers", "#{name.to_s.underscore}_helper.rb")
47
+ template 'templates/controller.rb.tt', destination_root(app, 'controllers', "#{name.to_s.underscore}.rb")
48
+ template 'templates/helper.rb.tt', destination_root(app, 'helpers', "#{name.to_s.underscore}_helper.rb")
46
49
  empty_directory destination_root(app, "/views/#{name.to_s.underscore}")
47
50
  include_component_module_for(:test)
48
51
  generate_controller_test(name) if test?
49
52
  else
50
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
53
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
51
54
  end
52
55
  end
53
56
  end # Controller
@@ -11,7 +11,7 @@ module Padrino
11
11
  # Define the source template root
12
12
  def self.source_root; File.expand_path(File.dirname(__FILE__)); end
13
13
  # Defines the banner for this CLI generator
14
- def self.banner; "padrino-gen mailer [name]"; end
14
+ def self.banner; 'padrino-gen mailer [name]'; end
15
15
 
16
16
  # Include related modules
17
17
  include Thor::Actions
@@ -20,11 +20,12 @@ module Padrino
20
20
 
21
21
  desc "Description:\n\n\tpadrino-gen mailer generates a new Padrino mailer"
22
22
 
23
- argument :name, :desc => "The name of your padrino mailer"
24
- argument :actions, :desc => "The delivery actions to add to your mailer", :type => :array, :default => []
25
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
26
- class_option :app, :desc => "The application destination path", :aliases => '-a', :default => "/app", :type => :string
27
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
23
+ argument :name, :desc => 'The name of your padrino mailer'
24
+ argument :actions, :desc => 'The delivery actions to add to your mailer', :type => :array, :default => []
25
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
26
+ class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '/app', :type => :string
27
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
28
+ class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
28
29
 
29
30
  # Show help if no argv given
30
31
  require_arguments!
@@ -37,15 +38,17 @@ module Padrino
37
38
  if in_app_root?
38
39
  app = options[:app]
39
40
  check_app_existence(app)
40
- self.behavior = :revoke if options[:destroy]
41
- @app_name = fetch_app_name(app)
42
- @actions = actions.map{|a| a.to_sym}
43
- @short_name = name.to_s.gsub(/_mailer/i, '').underscore.downcase
41
+ self.behavior = :revoke if options[:destroy]
42
+ @project_name = options[:namespace].underscore.camelize
43
+ @project_name = fetch_project_name(app) if @project_name.empty?
44
+ @app_name = fetch_app_name(app)
45
+ @actions = actions.map{|a| a.to_sym}
46
+ @short_name = name.to_s.gsub(/_mailer/i, '').underscore.downcase
44
47
  @mailer_basename = @short_name.underscore
45
48
  template "templates/mailer.rb.tt", destination_root(app, 'mailers', "#{@mailer_basename}.rb")
46
49
  empty_directory destination_root(app, 'views', 'mailers', @mailer_basename)
47
50
  else
48
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
51
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
49
52
  end
50
53
  end
51
54
  end # Mailer
@@ -20,9 +20,9 @@ module Padrino
20
20
 
21
21
  desc "Description:\n\n\tpadrino-gen migration generates a new migration file"
22
22
 
23
- argument :name, :desc => "The name of your padrino migration"
24
- argument :columns, :desc => "The columns for the migration", :type => :array, :default => []
25
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
23
+ argument :name, :desc => 'The name of your padrino migration'
24
+ argument :columns, :desc => 'The columns for the migration', :type => :array, :default => []
25
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
26
26
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
27
27
 
28
28
  # Show help if no argv given
@@ -36,11 +36,11 @@ module Padrino
36
36
  if include_component_module_for(:orm)
37
37
  create_migration_file(name, name, columns)
38
38
  else
39
- say "<= You need an ORM adapter for run this generator. Sorry!"
39
+ say '<= You need an ORM adapter for run this generator. Sorry!'
40
40
  raise SystemExit
41
41
  end
42
42
  else
43
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
43
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
44
44
  end
45
45
  end
46
46
  end # Migration
@@ -20,12 +20,12 @@ module Padrino
20
20
 
21
21
  desc "Description:\n\n\tpadrino-gen model generates a new model and migration files"
22
22
 
23
- argument :name, :desc => "The name of your padrino model"
24
- argument :fields, :desc => "The fields for the model", :type => :array, :default => []
25
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
26
- class_option :app, :desc => "The application destination path", :aliases => '-a', :default => ".", :type => :string
23
+ argument :name, :desc => 'The name of your padrino model'
24
+ argument :fields, :desc => 'The fields for the model', :type => :array, :default => []
25
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
26
+ class_option :app, :desc => 'The application destination path', :aliases => '-a', :default => '.', :type => :string
27
27
  class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
28
- class_option :skip_migration, :aliases => "-s", :default => false, :type => :boolean
28
+ class_option :skip_migration, :aliases => '-s', :default => false, :type => :boolean
29
29
 
30
30
  # Show help if no argv given
31
31
  require_arguments!
@@ -40,7 +40,7 @@ module Padrino
40
40
  check_app_existence(app)
41
41
  self.behavior = :revoke if options[:destroy]
42
42
  if invalids = invalid_fields(fields)
43
- say "Invalid field name:", :red
43
+ say 'Invalid field name:', :red
44
44
  say " #{invalids.join(", ")}"
45
45
  return
46
46
  end
@@ -50,11 +50,12 @@ module Padrino
50
50
  end
51
51
  include_component_module_for(:test)
52
52
  migration_name = "create_#{name.pluralize.underscore}"
53
+ apply_default_fields fields
53
54
  create_model_file(name, :fields => fields, :app => app)
54
55
  generate_model_test(name) if test?
55
56
  create_model_migration(migration_name, name, fields) unless options[:skip_migration]
56
57
  else
57
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
58
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
58
59
  end
59
60
  end
60
61
  end # Model
@@ -36,7 +36,21 @@ module Padrino
36
36
  #
37
37
  # @api private
38
38
  def setup_plugin
39
- if options[:list] # list method ran here
39
+ if options[:list] || plugin_file.nil? # list method ran here
40
+ list_plugins
41
+ else # executing the plugin instructions
42
+ if in_app_root?
43
+ self.behavior = :revoke if options[:destroy]
44
+ self.destination_root = options[:root]
45
+ execute_runner(:plugin, plugin_file)
46
+ else
47
+ say "You are not at the root of a Padrino application! (config/boot.rb not found)"
48
+ end
49
+ end
50
+ end
51
+
52
+ no_tasks do
53
+ def list_plugins
40
54
  plugins = {}
41
55
  uri = URI.parse(PLUGIN_URL)
42
56
  http = Net::HTTP.new(uri.host, uri.port)
@@ -49,14 +63,6 @@ module Padrino
49
63
  end
50
64
  say "Available plugins:", :green
51
65
  say plugins.map { |plugin| " - #{plugin}" }.join("\n")
52
- else # executing the plugin instructions
53
- if in_app_root?
54
- self.behavior = :revoke if options[:destroy]
55
- self.destination_root = options[:root]
56
- execute_runner(:plugin, plugin_file)
57
- else
58
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
59
- end
60
66
  end
61
67
  end
62
68
  end # Plugins
@@ -4,4 +4,5 @@ tmp/**/*
4
4
  bin/*
5
5
  vendor/gems/*
6
6
  !vendor/gems/cache/
7
- .sass-cache/*
7
+ .sass-cache/*
8
+ db/*.db
@@ -2,15 +2,15 @@
2
2
  # This file mounts each app in the Padrino project to a specified sub-uri.
3
3
  # You can mount additional applications using any of these commands below:
4
4
  #
5
- # Padrino.mount("blog").to('/blog')
6
- # Padrino.mount("blog", :app_class => "BlogApp").to('/blog')
7
- # Padrino.mount("blog", :app_file => "path/to/blog/app.rb").to('/blog')
5
+ # Padrino.mount('blog').to('/blog')
6
+ # Padrino.mount('blog', :app_class => 'BlogApp').to('/blog')
7
+ # Padrino.mount('blog', :app_file => 'path/to/blog/app.rb').to('/blog')
8
8
  #
9
9
  # You can also map apps to a specified host:
10
10
  #
11
- # Padrino.mount("Admin").host("admin.example.org")
12
- # Padrino.mount("WebSite").host(/.*\.?example.org/)
13
- # Padrino.mount("Foo").to("/foo").host("bar.example.org")
11
+ # Padrino.mount('Admin').host('admin.example.org')
12
+ # Padrino.mount('WebSite').host(/.*\.?example.org/)
13
+ # Padrino.mount('Foo').to('/foo').host('bar.example.org')
14
14
  #
15
15
  # Note 1: Mounted apps (by default) should be placed into the project root at '/app_name'.
16
16
  # Note 2: If you use the host matching remember to respect the order of the rules.
@@ -18,7 +18,7 @@
18
18
  # By default, this file mounts the primary app which was generated with this project.
19
19
  # However, the mounted app can be modified as needed:
20
20
  #
21
- # Padrino.mount("AppName", :app_file => "path/to/file", :app_class => "BlogApp").to('/')
21
+ # Padrino.mount('AppName', :app_file => 'path/to/file', :app_class => 'BlogApp').to('/')
22
22
  #
23
23
 
24
24
  ##
@@ -28,7 +28,9 @@
28
28
  Padrino.configure_apps do
29
29
  # enable :sessions
30
30
  set :session_secret, '<%= SecureRandom.hex(32) %>'
31
+ set :protection, true
32
+ set :protect_from_csrf, true
31
33
  end
32
34
 
33
35
  # Mounts the core application for this project
34
- Padrino.mount(<%= @app_name.inspect %>).to('/')
36
+ Padrino.mount('<%= @project_name.to_s %>::<%= @app_name.to_s %>', :app_file => Padrino.root('app/app.rb')).to('/')
File without changes
@@ -24,23 +24,24 @@ module Padrino
24
24
 
25
25
  desc "Description:\n\n\tpadrino-gen project generates a new Padrino project"
26
26
 
27
- argument :name, :desc => "The name of your padrino project"
27
+ argument :name, :desc => 'The name of your padrino project'
28
28
 
29
- class_option :app , :desc => "The application name", :aliases => '-n', :default => nil, :type => :string
30
- class_option :bundle, :desc => "Run bundle install", :aliases => '-b', :default => false, :type => :boolean
31
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
32
- class_option :dev, :desc => "Use padrino from a git checkout", :default => false, :type => :boolean
33
- class_option :tiny, :desc => "Generate tiny app skeleton", :aliases => '-i', :default => false, :type => :boolean
34
- class_option :adapter, :desc => "SQL adapter for ORM (sqlite, mysql, mysql2, postgres)", :aliases => '-a', :default => "sqlite", :type => :string
35
- class_option :template, :desc => "Generate project from template", :aliases => '-p', :default => nil, :type => :string
29
+ class_option :app , :desc => 'The application name', :aliases => '-n', :default => nil, :type => :string
30
+ class_option :bundle, :desc => 'Run bundle install', :aliases => '-b', :default => false, :type => :boolean
31
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
32
+ class_option :dev, :desc => 'Use padrino from a git checkout', :default => false, :type => :boolean
33
+ class_option :tiny, :desc => 'Generate tiny app skeleton', :aliases => '-i', :default => false, :type => :boolean
34
+ class_option :adapter, :desc => 'SQL adapter for ORM (sqlite, mysql, mysql2, mysql-gem, postgres)', :aliases => '-a', :default => 'sqlite', :type => :string
35
+ class_option :template, :desc => 'Generate project from template', :aliases => '-p', :default => nil, :type => :string
36
+ class_option :gem, :desc => 'Generate project as a gem', :aliases => '-g', :default => false, :type => :boolean
36
37
 
37
38
  # Definitions for the available customizable components
38
- component_option :orm, "database engine", :aliases => '-d', :choices => [:activerecord, :mini_record, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest, :ohm, :mongomatic, :ripple], :default => :none
39
- component_option :test, "testing framework", :aliases => '-t', :choices => [:rspec, :shoulda, :cucumber, :bacon, :testspec, :riot, :minitest], :default => :none
40
- component_option :mock, "mocking library", :aliases => '-m', :choices => [:mocha, :rr], :default => :none
41
- component_option :script, "javascript library", :aliases => '-s', :choices => [:jquery, :prototype, :rightjs, :mootools, :extcore, :dojo], :default => :none
42
- component_option :renderer, "template engine", :aliases => '-e', :choices => [:haml, :erb, :liquid, :slim], :default => :haml
43
- component_option :stylesheet, "stylesheet engine", :aliases => '-c', :choices => [:less, :sass, :compass, :scss], :default => :none
39
+ component_option :orm, 'database engine', :aliases => '-d', :choices => [:activerecord, :minirecord, :datamapper, :mongomapper, :mongoid, :sequel, :couchrest, :ohm, :mongomatic, :ripple], :default => :none
40
+ component_option :test, 'testing framework', :aliases => '-t', :choices => [:rspec, :shoulda, :cucumber, :bacon, :testspec, :riot, :minitest], :default => :none
41
+ component_option :mock, 'mocking library', :aliases => '-m', :choices => [:mocha, :rr], :default => :none
42
+ component_option :script, 'javascript library', :aliases => '-s', :choices => [:jquery, :prototype, :rightjs, :mootools, :extcore, :dojo], :default => :none
43
+ component_option :renderer, 'template engine', :aliases => '-e', :choices => [:haml, :erb, :liquid, :slim], :default => :slim
44
+ component_option :stylesheet, 'stylesheet engine', :aliases => '-c', :choices => [:less, :sass, :compass, :scss], :default => :none
44
45
 
45
46
  # Show help if no argv given
46
47
  require_arguments!
@@ -49,20 +50,30 @@ module Padrino
49
50
  #
50
51
  # @api private
51
52
  def setup_project
52
- valid_constant?(options[:app] || name)
53
- @app_name = (options[:app] || name).gsub(/\W/, "_").underscore.camelize
53
+ valid_constant? name
54
+ app = (options[:app] || "App")
55
+
56
+ @project_name = name.gsub(/\W/, '_').underscore.camelize
57
+ @app_name = app.gsub(/\W/, '_').underscore.camelize
54
58
  self.destination_root = File.join(options[:root], name)
55
59
  if options[:template] # Run the template to create project
56
60
  execute_runner(:template, options[:template])
57
61
  else # generate project without template
58
- directory("project/", destination_root)
59
- empty_directory destination_root("public/images")
60
- empty_directory destination_root("public/javascripts")
61
- empty_directory destination_root("public/stylesheets")
62
- empty_directory destination_root("tmp")
62
+ directory('project/', destination_root)
63
+ empty_directory destination_root('public/images')
64
+ empty_directory destination_root('public/javascripts')
65
+ empty_directory destination_root('public/stylesheets')
66
+ empty_directory destination_root('tmp')
63
67
  store_component_config('.components')
64
68
  app_skeleton('app', options[:tiny])
65
- template "templates/Gemfile.tt", destination_root("Gemfile")
69
+ template 'templates/Gemfile.tt', destination_root('Gemfile')
70
+ template 'templates/Rakefile.tt', destination_root('Rakefile')
71
+ if options.gem?
72
+ template 'templates/gem/gemspec.tt', destination_root(name + '.gemspec')
73
+ template 'templates/gem/README.md.tt', destination_root('README.md')
74
+ template 'templates/gem/lib/libname.tt', destination_root("lib/#{name}.rb")
75
+ template 'templates/gem/lib/libname/version.tt', destination_root("lib/#{name}/version.rb")
76
+ end
66
77
  end
67
78
  end
68
79
 
@@ -77,6 +88,7 @@ module Padrino
77
88
  execute_component_setup(comp, choice)
78
89
  end
79
90
  store_component_config('.components')
91
+ store_component_choice(:namespace, @project_name)
80
92
  end
81
93
 
82
94
  # Bundle all required components using bundler and Gemfile
@@ -93,14 +105,30 @@ module Padrino
93
105
  # @api private
94
106
  def finish_message
95
107
  say
96
- say "="*65, :green
108
+ say '=' * 65, :green
97
109
  say "#{name} is ready for development!", :green
98
- say "="*65, :green
110
+ say '=' * 65, :green
99
111
  say "$ cd #{options[:root]}/#{name}"
100
- say "$ bundle install" unless options[:bundle]
112
+ say "$ bundle" unless options[:bundle]
101
113
  say "="*65, :green
102
114
  say
103
115
  end
116
+
117
+ # Returns the git author name config or a fill-in value
118
+ #
119
+ # @api private
120
+ def git_author_name
121
+ git_author_name = `git config user.name`.chomp
122
+ git_author_name.empty? ? "TODO: Write your name" : git_author_name
123
+ end
124
+
125
+ # Returns the git author email config or a fill-in value
126
+ #
127
+ # @api private
128
+ def git_author_email
129
+ git_author_email = `git config user.email`.chomp
130
+ git_author_email.empty? ? "TODO: Write your email address" : git_author_email
131
+ end
104
132
  end # Project
105
133
  end # Generators
106
134
  end # Padrino
@@ -132,7 +132,7 @@ module Padrino
132
132
  else # local file on system
133
133
  File.expand_path(template_file)
134
134
  end
135
- self.apply(template_path)
135
+ self.apply(template_path) rescue say("The template at #{template_path} could not be found!", :red)
136
136
  end
137
137
  end # Runner
138
138
  end # Generators
@@ -1,12 +1,17 @@
1
- source :rubygems
1
+ source 'https://rubygems.org'
2
+
3
+ # Distribute your app as a gem
4
+ <% unless options.gem? %># <% end %>gemspec
2
5
 
3
6
  # Server requirements
4
7
  # gem 'thin' # or mongrel
5
8
  # gem 'trinidad', :platform => 'jruby'
6
9
 
10
+ # Optional JSON codec (faster performance)
11
+ # gem 'oj'
12
+
7
13
  # Project requirements
8
14
  gem 'rake'
9
- gem 'sinatra-flash', :require => 'sinatra/flash'
10
15
 
11
16
  # Component requirements
12
17
 
@@ -16,7 +21,7 @@ gem 'sinatra-flash', :require => 'sinatra/flash'
16
21
  <% if options.dev? %># <% end %>gem 'padrino', '<%= Padrino.version %>'
17
22
 
18
23
  # Or Padrino Edge
19
- # gem 'padrino', :git => 'git://github.com/padrino/padrino-framework.git'
24
+ # gem 'padrino', :github => 'padrino/padrino-framework'
20
25
 
21
26
  # Or Individual Gems
22
27
  <% unless options.dev? %># <% end %>%w(core gen helpers cache mailer admin).each do |g|
@@ -0,0 +1,8 @@
1
+ require 'bundler/setup'
2
+ require 'padrino-core/cli/rake'
3
+
4
+ <%- if options[:orm] -%>
5
+ PadrinoTasks.use(:database)
6
+ PadrinoTasks.use(<%= options[:orm].to_sym.inspect %>)
7
+ <%- end -%>
8
+ PadrinoTasks.init
@@ -1,22 +1,21 @@
1
- <%= @app_name %>.controllers <%= ":#{@controller}" if @controller %> do
2
- # get :index, :map => "/foo/bar" do
3
- # session[:foo] = "bar"
1
+ <%= @project_name %>::<%= @app_name %>.controllers <%= ":#{@controller}" if @controller %> do
2
+ # get :index, :map => '/foo/bar' do
3
+ # session[:foo] = 'bar'
4
4
  # render 'index'
5
5
  # end
6
6
 
7
- # get :sample, :map => "/sample/url", :provides => [:any, :js] do
7
+ # get :sample, :map => '/sample/url', :provides => [:any, :js] do
8
8
  # case content_type
9
9
  # when :js then ...
10
10
  # else ...
11
11
  # end
12
12
 
13
13
  # get :foo, :with => :id do
14
- # "Maps to url '/foo/#{params[:id]}'"
14
+ # 'Maps to url '/foo/#{params[:id]}''
15
15
  # end
16
16
 
17
- # get "/example" do
18
- # "Hello world!"
17
+ # get '/example' do
18
+ # 'Hello world!'
19
19
  # end
20
-
21
- <%= @actions %>
20
+ <%= "\n#{@actions}" %>
22
21
  end
@@ -0,0 +1,29 @@
1
+ # <%=name.camelcase%>
2
+
3
+ A padrino gem
4
+
5
+ ## Usage
6
+
7
+ Add the following to your `Gemfile`:
8
+
9
+ ```ruby
10
+ gem '<%=name%>'
11
+ ```
12
+
13
+ and mount the app in your `apps.rb`:
14
+
15
+ ```ruby
16
+ Padrino.mount("<%=name.camelcase%>::App").to("/<%=name%>")
17
+ ```
18
+
19
+ ## Development
20
+
21
+ For development, this gem can be run as a standalone Padrino application
22
+ as you would expect from a normal one:
23
+
24
+ ```ruby
25
+ $ bundle exec padrino start
26
+ ```
27
+
28
+ The Rakefile also works like the normal Padrino one and supports all standard
29
+ components.
@@ -0,0 +1,19 @@
1
+ # -*- encoding: utf-8 -*-
2
+ require File.expand_path('../lib/<%=name%>/version', __FILE__)
3
+
4
+ Gem::Specification.new do |gem|
5
+ gem.authors = [<%=git_author_name.inspect%>]
6
+ gem.email = [<%=git_author_email.inspect%>]
7
+ gem.description = %q{TODO: Write a gem description}
8
+ gem.summary = %q{TODO: Write a gem summary}
9
+ gem.homepage = ""
10
+
11
+ gem.files = `git ls-files`.split($\)
12
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
13
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
14
+ gem.name = <%=name.underscore.inspect%>
15
+ gem.require_paths = ["lib", "app"]
16
+ gem.version = <%=name.camelcase%>::VERSION
17
+
18
+ gem.add_dependency "padrino-core"
19
+ end
@@ -0,0 +1,3 @@
1
+ module <%=name.camelcase%>
2
+ VERSION = '0.0.1'
3
+ end
@@ -0,0 +1,6 @@
1
+ require 'padrino-core'
2
+
3
+ module <%=name.camelcase%>
4
+ extend Padrino::Module
5
+ gem! <%=name.inspect%>
6
+ end