padrino-gen 0.11.4 → 0.12.0.rc1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 8ab4eea6e67ab8f8b201278704e124704844cade
4
- data.tar.gz: ed5c452b5c97cd8c00475e6d30956df6962b7de4
3
+ metadata.gz: 34257b397db80982537c1b0e65fdb8bec6380419
4
+ data.tar.gz: bfbb59c39f77c8305b62b95e5fb86399d4d9f289
5
5
  SHA512:
6
- metadata.gz: 01b7c42188cd0c6c3b79e2ef15d530d1b81159fa1098764a19199062a46a4a42044deb8534d9890cedd60ad1f7718cf7ea6bdfc95f6ab3581bd0db674ea4d964
7
- data.tar.gz: 44b6c205f8ff6e69bdd0a1088567e15cece7be98b1c1bf9c5433330d310dcb58bc94cfe0b65df94070adb8da8e821b6b99211c9e0f645946845530215770ddda
6
+ metadata.gz: 7a33c18c27dcab467595384094a24afa5d073162148a8dc7999a4286c567f6598e0d04d0ae36bef692bebe87c670e92e4ed056431593a91e4086d83d8aec8bf7
7
+ data.tar.gz: 3afec25a54e43dfc53f09b3bf048a698c3a13f0988881711364a61e3983bfef1ee6e67e96f5690ef99ff8503af321dddd45e9574aab866dba5e6f290ffe71293
data/README.rdoc CHANGED
@@ -38,12 +38,12 @@ You can also instruct the generator to skip a certain component to avoid using o
38
38
 
39
39
  The available components and their default options are listed below:
40
40
 
41
- test:: rspec (default), bacon, shoulda, cucumber, testspec, riot, minitest
42
- renderer:: haml (default), erb, erubis, liquid, slim
43
- stylesheet:: sass (default), less, compass
41
+ test:: none (default), bacon, shoulda, cucumber, testspec, riot, rspec, minitest, steak
42
+ renderer:: slim (default), erb, erubis, liquid, haml
43
+ stylesheet:: none (default), less, compass, sass, scss
44
44
  mock:: none (default), mocha, rr
45
45
  script:: none (default), jquery, prototype, mootools, rightjs, extcore, dojo
46
- orm:: none (default), datamapper, mongomapper, mongoid, activerecord, sequel, couchrest, ohm, mongomatic, ripple
46
+ orm:: none (default), datamapper, mongomapper, mongoid, activerecord, minirecord, sequel, couchrest, ohm, mongomatic, ripple
47
47
 
48
48
  In addition, you can generate projects based on existing templates:
49
49
 
data/lib/padrino-gen.rb CHANGED
@@ -1,7 +1,7 @@
1
- require 'active_support/ordered_hash'
2
1
  require 'padrino-core/support_lite'
3
2
  require 'padrino-core/tasks'
4
3
  require 'padrino-gen/command'
4
+ require 'active_support/ordered_hash'
5
5
 
6
6
  module Padrino
7
7
  ##
@@ -68,7 +68,7 @@ module Padrino
68
68
  end
69
69
 
70
70
  # Add our generators to Padrino::Generators.
71
- Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-gen/generators/{project,app,mailer,controller,model,migration,plugin,component}.rb']
71
+ Padrino::Generators.load_paths << Dir[File.dirname(__FILE__) + '/padrino-gen/generators/{project,app,mailer,controller,model,migration,plugin,component,task}.rb']
72
72
 
73
73
  # Add our tasks to padrino-core.
74
74
  Padrino::Tasks.files << Dir[File.dirname(__FILE__) + "/padrino-gen/padrino-tasks/**/*.rb"]
@@ -198,6 +198,14 @@ module Padrino
198
198
  File.exist?(destination_root('config/boot.rb'))
199
199
  end
200
200
 
201
+ ##
202
+ # Returns true if constant name already exists.
203
+ #
204
+ def already_exists?(name, project_name = nil)
205
+ project_name = project_name ? (Object.const_get(project_name) rescue nil) : nil
206
+ Object.const_defined?(name) || (project_name && project_name.const_defined?(name))
207
+ end
208
+
201
209
  ##
202
210
  # Returns the field with an unacceptable name(for symbol) else returns nil.
203
211
  #
@@ -35,19 +35,25 @@ module Padrino
35
35
  if in_app_root?
36
36
  @project_name = options[:namespace].underscore.camelize
37
37
  @project_name = fetch_project_name(@app_folder) if @project_name.empty?
38
- lowercase_app_folder = @app_folder.downcase
39
- self.behavior = :revoke if options[:destroy]
40
- app_skeleton(lowercase_app_folder, options[:tiny])
41
- empty_directory destination_root("public/#{lowercase_app_folder}")
42
- append_file destination_root('config/apps.rb'), "\nPadrino.mount('#{@project_name}::#{@app_name}', :app_file => Padrino.root('#{lowercase_app_folder}/app.rb')).to('/#{lowercase_app_folder}')"
43
-
44
- return if self.behavior == :revoke
45
- say
46
- say '=' * 65, :green
47
- say "Your #{@app_name} application has been installed."
48
- say '=' * 65, :green
49
- say "This application has been mounted to /#{@app_name.downcase}"
50
- say "You can configure a different path by editing 'config/apps.rb'"
38
+ if already_exists?(@app_name, @project_name)
39
+ say "#{@app_name} already exists."
40
+ say "Please, change the name."
41
+ return
42
+ else
43
+ lowercase_app_folder = @app_folder.downcase
44
+ self.behavior = :revoke if options[:destroy]
45
+ app_skeleton(lowercase_app_folder, options[:tiny])
46
+ empty_directory destination_root("public/#{lowercase_app_folder}")
47
+ inject_into_file destination_root('config/apps.rb'), "\nPadrino.mount('#{@project_name}::#{@app_name}', :app_file => Padrino.root('#{lowercase_app_folder}/app.rb')).to('/#{lowercase_app_folder}')\n", :before => /^Padrino.mount.*\.to\('\/'\)$/
48
+
49
+ return if self.behavior == :revoke
50
+ say
51
+ say '=' * 65, :green
52
+ say "Your #{@app_name} application has been installed."
53
+ say '=' * 65, :green
54
+ say "This application has been mounted to /#{@app_name.downcase}"
55
+ say "You can configure a different path by editing 'config/apps.rb'"
56
+ end
51
57
  else
52
58
  say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
53
59
  end
@@ -14,11 +14,16 @@ module <%= @project_name %>
14
14
  #
15
15
  # You can customize caching store engines:
16
16
  #
17
- # set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))
18
- # set :cache, Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('127.0.0.1:11211', :exception_retry_limit => 1))
19
- # set :cache, Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0))
20
- # set :cache, Padrino::Cache::Store::Memory.new(50)
21
- # set :cache, Padrino::Cache::Store::File.new(Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
17
+ # set :cache, Padrino::Cache.new(:LRUHash) # Keeps cached values in memory
18
+ # set :cache, Padrino::Cache.new(:Memcached) # Uses default server at localhost
19
+ # set :cache, Padrino::Cache.new(:Memcached, '127.0.0.1:11211', :exception_retry_limit => 1)
20
+ # set :cache, Padrino::Cache.new(:Memcached, :backend => memcached_or_dalli_instance)
21
+ # set :cache, Padrino::Cache.new(:Redis) # Uses default server at localhost
22
+ # set :cache, Padrino::Cache.new(:Redis, :host => '127.0.0.1', :port => 6379, :db => 0)
23
+ # set :cache, Padrino::Cache.new(:Redis, :backend => redis_instance)
24
+ # set :cache, Padrino::Cache.new(:Mongo) # Uses default server at localhost
25
+ # set :cache, Padrino::Cache.new(:Mongo, :backend => mongo_client_instance)
26
+ # set :cache, Padrino::Cache.new(:File, :dir => Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
22
27
  #
23
28
 
24
29
  ##
@@ -52,6 +52,10 @@ module Padrino
52
52
  @project_name = fetch_component_choice(:namespace)
53
53
  execute_component_setup(comp, choice)
54
54
  store_component_choice(comp, choice)
55
+ if comp.to_s == 'orm' && choice.to_s != 'none'
56
+ inject_into_file destination_root('Rakefile'), "PadrinoTasks.use(:database)\n", :before => "PadrinoTasks.init"
57
+ inject_into_file destination_root('Rakefile'), "PadrinoTasks.use(#{choice.to_sym.inspect})\n", :before => "PadrinoTasks.init"
58
+ end
55
59
  end
56
60
  else
57
61
  say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
@@ -29,12 +29,14 @@ ActiveRecord::Base.configurations[:test] = {
29
29
  # Setup our logger
30
30
  ActiveRecord::Base.logger = logger
31
31
 
32
- # Raise exception on mass assignment protection for Active Record models.
33
- ActiveRecord::Base.mass_assignment_sanitizer = :strict
32
+ if ActiveRecord::VERSION::MAJOR.to_i < 4
33
+ # Raise exception on mass assignment protection for Active Record models.
34
+ ActiveRecord::Base.mass_assignment_sanitizer = :strict
34
35
 
35
- # Log the query plan for queries taking more than this (works
36
- # with SQLite, MySQL, and PostgreSQL).
37
- ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
36
+ # Log the query plan for queries taking more than this (works
37
+ # with SQLite, MySQL, and PostgreSQL).
38
+ ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
39
+ end
38
40
 
39
41
  # Include Active Record class name as root for JSON serialized output.
40
42
  ActiveRecord::Base.include_root_in_json = false
@@ -14,12 +14,14 @@ ActiveRecord::Base.configurations[:test] = {
14
14
  # Setup our logger.
15
15
  ActiveRecord::Base.logger = logger
16
16
 
17
- # Raise exception on mass assignment protection for Active Record models.
18
- ActiveRecord::Base.mass_assignment_sanitizer = :strict
17
+ if ActiveRecord::VERSION::MAJOR.to_i < 4
18
+ # Raise exception on mass assignment protection for Active Record models.
19
+ ActiveRecord::Base.mass_assignment_sanitizer = :strict
19
20
 
20
- # Log the query plan for queries taking more than this (works
21
- # with SQLite, MySQL, and PostgreSQL).
22
- ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
21
+ # Log the query plan for queries taking more than this (works
22
+ # with SQLite, MySQL, and PostgreSQL).
23
+ ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
24
+ end
23
25
 
24
26
  # Doesn't include Active Record class name as root for JSON serialized output.
25
27
  ActiveRecord::Base.include_root_in_json = false
@@ -74,17 +74,8 @@ Mongoid::Config.sessions =
74
74
  MONGO
75
75
 
76
76
  def setup_orm
77
- require_dependencies 'mongoid', :version => (RUBY_VERSION >= '1.9' ? '~>3.0.0' : '~>2.0')
78
-
79
- if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
80
- require_dependencies('SystemTimer', :require => 'system_timer')
81
- end
82
-
83
- if RUBY_VERSION >= '1.9'
84
- create_file('config/database.rb', MONGOID3.gsub(/!NAME!/, @project_name.underscore))
85
- else
86
- create_file('config/database.rb', MONGOID.gsub(/!NAME!/, @project_name.underscore))
87
- end
77
+ require_dependencies 'mongoid', :version => '~>3.0.0'
78
+ create_file('config/database.rb', MONGOID3.gsub(/!NAME!/, @project_name.underscore))
88
79
  end
89
80
 
90
81
  MONGOID_MODEL = (<<-MODEL) unless defined?(MONGOID_MODEL)
@@ -11,7 +11,6 @@ MONGO
11
11
  def setup_orm
12
12
  require_dependencies 'mongo_mapper'
13
13
  require_dependencies 'bson_ext', :require => 'mongo'
14
- require_dependencies('SystemTimer', :require => 'system_timer') if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
15
14
  create_file("config/database.rb", MONGO.gsub(/!NAME!/, @project_name.underscore))
16
15
  end
17
16
 
@@ -39,7 +39,10 @@ RSPEC_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(RSPEC_RAKE)
39
39
  begin
40
40
  require 'rspec/core/rake_task'
41
41
 
42
- spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }
42
+ spec_tasks = Dir['spec/*/'].inject([]) do |result, d|
43
+ result << File.basename(d) unless Dir["\#{d}*"].empty?
44
+ result
45
+ end
43
46
 
44
47
  spec_tasks.each do |folder|
45
48
  RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
@@ -0,0 +1,93 @@
1
+ STEAK_SETUP = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_SETUP)
2
+ PADRINO_ENV = 'test' unless defined?(PADRINO_ENV)
3
+ require File.expand_path(File.dirname(__FILE__) + "/../config/boot")
4
+
5
+ RSpec.configure do |conf|
6
+ conf.include Rack::Test::Methods
7
+ conf.include Capybara
8
+ end
9
+
10
+ def app
11
+ ##
12
+ # You can handle all padrino applications using instead:
13
+ # Padrino.application
14
+ CLASS_NAME.tap { |app| }
15
+ end
16
+
17
+ Capybara.app = app
18
+ TEST
19
+
20
+ STEAK_CONTROLLER_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_CONTROLLER_TEST)
21
+ require 'spec_helper'
22
+
23
+ describe "!NAME!Controller" do
24
+ before do
25
+ get "/"
26
+ end
27
+
28
+ it "returns hello world" do
29
+ last_response.body.should == "Hello World"
30
+ end
31
+ end
32
+ TEST
33
+
34
+ STEAK_CONTROLLER_ACCEPTANCE_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_CONTROLLER_ACCEPTANCE_TEST)
35
+ require 'spec_helper'
36
+
37
+ feature "!NAME!Controller" do
38
+ background do
39
+ visit "/"
40
+ end
41
+
42
+ scenario "returns hello world" do
43
+ page.should.have_content == "Hello World"
44
+ end
45
+ end
46
+ TEST
47
+
48
+ STEAK_RAKE = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_RAKE)
49
+ require 'rspec/core/rake_task'
50
+
51
+ spec_tasks = Dir['spec/*/'].map { |d| File.basename(d) }
52
+
53
+ spec_tasks.each do |folder|
54
+ RSpec::Core::RakeTask.new("spec:\#{folder}") do |t|
55
+ t.pattern = "./spec/\#{folder}/**/*_spec.rb"
56
+ t.rspec_opts = %w(-fs --color)
57
+ end
58
+ end
59
+
60
+ desc "Run complete application spec suite"
61
+ task 'spec' => spec_tasks.map { |f| "spec:\#{f}" }
62
+ TEST
63
+
64
+ STEAK_MODEL_TEST = (<<-TEST).gsub(/^ {12}/, '') unless defined?(STEAK_MODEL_TEST)
65
+ require 'spec_helper'
66
+
67
+ describe !NAME! do
68
+ end
69
+ TEST
70
+
71
+ def setup_test
72
+ require_dependencies 'rack-test', :require => 'rack/test', :group => 'test'
73
+ require_dependencies 'steak', :group => 'test'
74
+ insert_test_suite_setup STEAK_SETUP, :path => "spec/spec_helper.rb"
75
+ create_file destination_root("spec/spec.rake"), STEAK_RAKE
76
+ end
77
+
78
+ # Generates a controller test given the controllers name
79
+ def generate_controller_test(name)
80
+ spec_contents = STEAK_CONTROLLER_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
81
+ controller_spec_path = File.join('spec',options[:app],'controllers',"#{name.to_s.underscore}_controller_spec.rb")
82
+ create_file destination_root(controller_spec_path), spec_contents, :skip => true
83
+
84
+ acceptance_contents = STEAK_CONTROLLER_ACCEPTANCE_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize)
85
+ controller_acceptance_path = File.join('spec',options[:app],'acceptance','controllers',"#{name.to_s.underscore}_controller_spec.rb")
86
+ create_file destination_root(controller_acceptance_path), acceptance_contents, :skip => true
87
+ end
88
+
89
+ def generate_model_test(name)
90
+ rspec_contents = STEAK_MODEL_TEST.gsub(/!NAME!/, name.to_s.underscore.camelize).gsub(/!DNAME!/, name.to_s.underscore)
91
+ model_spec_path = File.join('spec',options[:app],'models',"#{name.to_s.underscore}_spec.rb")
92
+ create_file destination_root(model_spec_path), rspec_contents, :skip => true
93
+ end
@@ -32,22 +32,31 @@ module Padrino
32
32
  if in_app_root?
33
33
  app = options[:app]
34
34
  check_app_existence(app)
35
- self.behavior = :revoke if options[:destroy]
36
- if invalids = invalid_fields(fields)
37
- say 'Invalid field name:', :red
38
- say " #{invalids.join(", ")}"
35
+ camel_name = name.to_s.underscore.camelize
36
+ @project_name = ""
37
+ @project_name = fetch_project_name
38
+ if already_exists?(camel_name, @project_name)
39
+ say "#{camel_name} already exists."
40
+ say "Please, change the name."
39
41
  return
42
+ else
43
+ self.behavior = :revoke if options[:destroy]
44
+ if invalids = invalid_fields(fields)
45
+ say 'Invalid field name:', :red
46
+ say " #{invalids.join(", ")}"
47
+ return
48
+ end
49
+ unless include_component_module_for(:orm)
50
+ say "<= You need an ORM adapter for run this generator. Sorry!"
51
+ raise SystemExit
52
+ end
53
+ include_component_module_for(:test)
54
+ migration_name = "create_#{name.pluralize.underscore}"
55
+ apply_default_fields fields
56
+ create_model_file(name, :fields => fields, :app => app)
57
+ generate_model_test(name) if test?
58
+ create_model_migration(migration_name, name, fields) unless options[:skip_migration]
40
59
  end
41
- unless include_component_module_for(:orm)
42
- say "<= You need an ORM adapter for run this generator. Sorry!"
43
- raise SystemExit
44
- end
45
- include_component_module_for(:test)
46
- migration_name = "create_#{name.pluralize.underscore}"
47
- apply_default_fields fields
48
- create_model_file(name, :fields => fields, :app => app)
49
- generate_model_test(name) if test?
50
- create_model_migration(migration_name, name, fields) unless options[:skip_migration]
51
60
  else
52
61
  say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
53
62
  end
@@ -28,7 +28,7 @@
28
28
  Padrino.configure_apps do
29
29
  # enable :sessions
30
30
  set :session_secret, '<%= SecureRandom.hex(32) %>'
31
- set :protection, true
31
+ set :protection, :except => :path_traversal
32
32
  set :protect_from_csrf, true
33
33
  end
34
34
 
@@ -16,6 +16,7 @@ Bundler.require(:default, PADRINO_ENV)
16
16
  # ## Configure your I18n
17
17
  #
18
18
  # I18n.default_locale = :en
19
+ # I18n.enforce_available_locales = false
19
20
  #
20
21
  # ## Configure your HTML5 data helpers
21
22
  #
@@ -128,7 +128,7 @@ module Padrino
128
128
  raw_link, _ = *open(template_file).read.scan(/<a\s+href\s?\=\"(.*?)\"\>raw/)
129
129
  raw_link ? "https://gist.github.com#{raw_link[0]}" : template_file
130
130
  when File.extname(template_file).blank? # referencing official plugin (i.e hoptoad)
131
- "https://github.com/padrino/padrino-recipes/raw/master/#{kind.to_s.pluralize}/#{template_file}_#{kind}.rb"
131
+ "https://raw.github.com/padrino/padrino-recipes/master/#{kind.to_s.pluralize}/#{template_file}_#{kind}.rb"
132
132
  else # local file on system
133
133
  File.expand_path(template_file)
134
134
  end
@@ -0,0 +1,45 @@
1
+ module Padrino
2
+ module Generators
3
+ ##
4
+ # Responsible for generating new task file for Padrino application.
5
+ #
6
+ class Task < Thor::Group
7
+ include Thor::Actions
8
+ include Padrino::Generators::Actions
9
+ include Padrino::Generators::Components::Actions
10
+
11
+ Padrino::Generators.add_generator(:task, self)
12
+
13
+ class << self
14
+ def source_root; File.expand_path(File.dirname(__FILE__)); end
15
+ def banner; "padrino-gen task [name]"; end
16
+ end
17
+
18
+ desc "Description:\n\n\tpadrino-gen task generates a new task file."
19
+
20
+ argument :name, :desc => 'The name of your application task'
21
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
22
+ class_option :description, :desc => 'The description of your application task', :aliases => '-d', :default => nil, :type => :string
23
+ class_option :namespace, :desc => 'The namespace of your application task', :aliases => '-n', :default => nil, :type => :string
24
+
25
+ # Show help if no ARGV given
26
+ require_arguments!
27
+
28
+ def create_task
29
+ self.destination_root = options[:root]
30
+ if in_app_root?
31
+ app = options[:app]
32
+ @task_name = name.to_s.underscore
33
+ @namespace = options[:namespace].underscore if options[:namespace]
34
+ @desc = options[:description]
35
+ filename = @task_name + ".rake"
36
+ filename = "#{@namespace}_#{filename}" if @namespace
37
+
38
+ template 'templates/task.rb.tt', destination_root('tasks', filename)
39
+ else
40
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
41
+ end
42
+ end
43
+ end
44
+ end
45
+ end
@@ -0,0 +1,7 @@
1
+ <%= "namespace :#{@namespace} do" if @namespace %>
2
+ <%= "desc \"#{@desc}\"" if @desc %>
3
+ task :<%= @task_name %> => :environment do
4
+ # This is a custom task.
5
+ end
6
+ <%= "end" if @namespace %>
7
+
@@ -48,9 +48,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
48
48
  ActiveRecord::Base.establish_connection(config)
49
49
  ActiveRecord::Base.connection
50
50
  rescue StandardError => e
51
- $stderr.puts *(e.backtrace)
52
- $stderr.puts e.inspect
53
- $stderr.puts "Couldn't create database for #{config.inspect}"
51
+ catch_error(:create, e, config)
54
52
  end
55
53
  end
56
54
  return # Skip the else clause of begin/rescue
@@ -81,9 +79,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
81
79
  ActiveRecord::Base.connection.create_database(config[:database], config.merge(:encoding => @encoding))
82
80
  ActiveRecord::Base.establish_connection(config)
83
81
  rescue StandardError => e
84
- $stderr.puts *(e.backtrace)
85
- $stderr.puts e.inspect
86
- $stderr.puts "Couldn't create database for #{config.inspect}"
82
+ catch_error(:create, e, config)
87
83
  end
88
84
  end
89
85
  else
@@ -101,9 +97,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
101
97
  # Only connect to local databases
102
98
  local_database?(config) { drop_database(config) }
103
99
  rescue StandardError => e
104
- $stderr.puts *(e.backtrace)
105
- $stderr.puts e.inspect
106
- $stderr.puts "Couldn't drop #{config[:database]}"
100
+ catch_error(:drop, e, config)
107
101
  end
108
102
  end
109
103
  end
@@ -115,9 +109,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
115
109
  begin
116
110
  drop_database(config)
117
111
  rescue StandardError => e
118
- $stderr.puts *(e.backtrace)
119
- $stderr.puts e.inspect
120
- $stderr.puts "Couldn't drop #{config[:database]}"
112
+ catch_error(:drop, e, config)
121
113
  end
122
114
  end
123
115
 
@@ -220,7 +212,7 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
220
212
  desc "Raises an error if there are pending migrations"
221
213
  task :abort_if_pending_migrations => :environment do
222
214
  if defined? ActiveRecord
223
- pending_migrations = ActiveRecord::Migrator.new(:up, 'db/migrate').pending_migrations
215
+ pending_migrations = ActiveRecord::Migrator.open(ActiveRecord::Migrator.migrations_paths).pending_migrations
224
216
 
225
217
  if pending_migrations.any?
226
218
  puts "You have #{pending_migrations.size} pending migrations:"
@@ -363,6 +355,17 @@ if PadrinoTasks.load?(:activerecord, defined?(ActiveRecord))
363
355
  FireRuby::Database.db_string_for(config.symbolize_keys)
364
356
  end
365
357
 
358
+ def catch_error(type, error, config)
359
+ $stderr.puts *(error.backtrace)
360
+ $stderr.puts error.inspect
361
+ case type
362
+ when :create
363
+ $stderr.puts "Couldn't create database for #{config.inspect}"
364
+ when :drop
365
+ $stderr.puts "Couldn't drop #{config[:database]}"
366
+ end
367
+ end
368
+
366
369
  task 'db:migrate' => 'ar:migrate'
367
370
  task 'db:create' => 'ar:create'
368
371
  task 'db:drop' => 'ar:drop'
data/padrino-gen.gemspec CHANGED
@@ -14,6 +14,7 @@ Gem::Specification.new do |s|
14
14
  s.required_rubygems_version = ">= 1.3.6"
15
15
  s.version = Padrino.version
16
16
  s.date = Time.now.strftime("%Y-%m-%d")
17
+ s.license = "MIT"
17
18
 
18
19
  s.extra_rdoc_files = Dir["*.rdoc"]
19
20
  s.files = `git ls-files`.split("\n") | Dir.glob("{lib}/**/*")
data/test/helper.rb CHANGED
@@ -7,7 +7,9 @@ require 'webrat'
7
7
  require 'fakeweb'
8
8
  require 'thor/group'
9
9
  require 'padrino-gen'
10
- require 'padrino-core/support_lite' unless defined?(SupportLite)
10
+ require 'padrino-core'
11
+ require 'padrino-mailer'
12
+ require 'padrino-helpers'
11
13
 
12
14
  Padrino::Generators.load_components!
13
15
 
@@ -31,6 +33,23 @@ class MiniTest::Spec
31
33
  "Padrino::Generators::#{name.to_s.camelize}".constantize.start(params)
32
34
  end
33
35
 
36
+ # generate_with_parts(:app, "demo", "--root=/tmp/sample_project", :apps => "subapp")
37
+ # This method is intended to reproduce the real environment.
38
+ def generate_with_parts(name, *params)
39
+ features, constants = [$", Object.constants].map{|x| Marshal.load(Marshal.dump(x)) }
40
+
41
+ if root = params.find{|x| x.index(/\-r=|\-\-root=/) }
42
+ root = root.split(/=/)[1]
43
+ options, model_path = {}, File.expand_path(File.join(root, "/models/**/*.rb"))
44
+ options = params.pop if params.last.is_a?(Hash)
45
+ Dir[model_path].each{|path| require path }
46
+ Array(options[:apps]).each{|app_name| require File.expand_path(File.join(root, "/#{app_name}/app.rb")) } if options[:apps]
47
+ end
48
+ "Padrino::Generators::#{name.to_s.camelize}".constantize.start(params)
49
+ ($" - features).each{|x| $".delete(x) }
50
+ (Object.constants - constants).each{|constant| Object.instance_eval{ remove_const(constant) }}
51
+ end
52
+
34
53
  # assert_has_tag(:h1, :content => "yellow") { "<h1>yellow</h1>" }
35
54
  # In this case, block is the html to evaluate
36
55
  def assert_has_tag(name, attributes = {}, &block)
@@ -96,5 +96,26 @@ describe "AppGenerator" do
96
96
  assert_no_dir_exists("#{@apptmp}/sample_project/demo/views")
97
97
  assert_no_match_in_file(/Padrino\.mount\("Demo"\).to\("\/demo"\)/,"#{@apptmp}/sample_project/config/apps.rb")
98
98
  end
99
+
100
+ should "abort if app name already exists" do
101
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
102
+ out, err = capture_io { generate(:app, 'kernel', "--root=#{@apptmp}/sample_project") }
103
+ assert_match(/Kernel already exists/, out)
104
+ assert_no_dir_exists("#{@apptmp}/sample_project/public/kernel")
105
+ assert_no_dir_exists("#{@apptmp}/sample_project/kernel/controllers")
106
+ assert_no_dir_exists("#{@apptmp}/sample_project/kernel/helpers")
107
+ assert_no_file_exists("#{@apptmp}/sample_project/kernel/app.rb")
108
+ end
109
+
110
+ should "abort if app name already exists in root" do
111
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
112
+ capture_io { generate(:app, 'subapp', "--root=#{@apptmp}/sample_project") }
113
+ out, err = capture_io { generate_with_parts(:app, 'subapp', "--root=#{@apptmp}/sample_project", :apps => "subapp") }
114
+ assert_dir_exists("#{@apptmp}/sample_project/public/subapp")
115
+ assert_dir_exists("#{@apptmp}/sample_project/subapp/controllers")
116
+ assert_dir_exists("#{@apptmp}/sample_project/subapp/helpers")
117
+ assert_file_exists("#{@apptmp}/sample_project/subapp/app.rb")
118
+ assert_match(/Subapp already exists/, out)
119
+ end
99
120
  end
100
121
  end
@@ -140,6 +140,14 @@ describe "ControllerGenerator" do
140
140
  assert_file_exists("#{@apptmp}/sample_project/test/subby/controllers/demo_items_controller_test.rb")
141
141
  end
142
142
 
143
+ should "generate controller test for steak" do
144
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=steak') }
145
+ capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
146
+ capture_io { generate(:controller, 'DemoItems','-a=/subby', "-r=#{@apptmp}/sample_project") }
147
+ assert_match_in_file(/describe "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/controllers/demo_items_controller_spec.rb")
148
+ assert_match_in_file(/feature "DemoItemsController" do/m, "#{@apptmp}/sample_project/spec/subby/acceptance/controllers/demo_items_controller_spec.rb")
149
+ end
150
+
143
151
  should "generate controller test for cucumber" do
144
152
  capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--script=none', '-t=cucumber') }
145
153
  capture_io { generate(:app, 'subby', "-r=#{@apptmp}/sample_project") }
@@ -4,7 +4,7 @@ describe "Generator" do
4
4
 
5
5
  context "the generator" do
6
6
  should "have default generators" do
7
- %w{controller mailer migration model app plugin component}.each do |gen|
7
+ %w{controller mailer migration model app plugin component task}.each do |gen|
8
8
  assert Padrino::Generators.mappings.has_key?(gen.to_sym)
9
9
  assert_equal "Padrino::Generators::#{gen.camelize}", Padrino::Generators.mappings[gen.to_sym].name
10
10
  assert Padrino::Generators.mappings[gen.to_sym].respond_to?(:start)
@@ -97,6 +97,23 @@ describe "ModelGenerator" do
97
97
  assert_match_in_file(/ t.string :email/m, migration_file_path)
98
98
  assert_match_in_file(/ drop_table :people/m, migration_file_path)
99
99
  end
100
+
101
+ should "abort if model name already exists" do
102
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", "-d=activerecord") }
103
+ out, err = capture_io { generate(:model, 'kernel', "--root=#{@apptmp}/sample_project") }
104
+ assert_match(/Kernel already exists/, out)
105
+ assert_no_file_exists("#{@apptmp}/sample_project/db/migrate/001_create_kernel.rb")
106
+ assert_no_file_exists("#{@apptmp}/sample_project/models/kernel.rb")
107
+ end
108
+
109
+ should "abort if model name already exists in root" do
110
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", "-d=activerecord") }
111
+ capture_io { generate(:app, 'user', "--root=#{@apptmp}/sample_project") }
112
+ out, err = capture_io { generate_with_parts(:model, 'user', "--root=#{@apptmp}/sample_project", :apps => "user") }
113
+ assert_file_exists("#{@apptmp}/sample_project/user/app.rb")
114
+ assert_no_file_exists("#{@apptmp}/sample_project/models/user.rb")
115
+ assert_match(/User already exists/, out)
116
+ end
100
117
  end
101
118
 
102
119
  # ACTIVERECORD
@@ -68,7 +68,7 @@ describe "PluginGenerator" do
68
68
 
69
69
  should "resolve official template" do
70
70
  template_file = 'sampleblog'
71
- resolved_path = "https://github.com/padrino/padrino-recipes/raw/master/templates/sampleblog_template.rb"
71
+ resolved_path = "https://raw.github.com/padrino/padrino-recipes/master/templates/sampleblog_template.rb"
72
72
  project_gen = Padrino::Generators::Project.new(['sample_project'], ["-p=#{template_file}", "-r=#{@apptmp}"], {})
73
73
  project_gen.expects(:apply).with(resolved_path).returns(true).once
74
74
  capture_io { project_gen.invoke_all }
@@ -83,7 +83,7 @@ describe "PluginGenerator" do
83
83
 
84
84
  should "resolve official plugin" do
85
85
  template_file = 'hoptoad'
86
- resolved_path = "https://github.com/padrino/padrino-recipes/raw/master/plugins/hoptoad_plugin.rb"
86
+ resolved_path = "https://raw.github.com/padrino/padrino-recipes/master/plugins/hoptoad_plugin.rb"
87
87
  plugin_gen = Padrino::Generators::Plugin.new([ template_file], ["-r=#{@apptmp}/sample_project"],{})
88
88
  plugin_gen.expects(:in_app_root?).returns(true).once
89
89
  plugin_gen.expects(:apply).with(resolved_path).returns(true).once
@@ -92,7 +92,7 @@ describe "PluginGenerator" do
92
92
 
93
93
  should "print a warning if template cannot be found" do
94
94
  template_file = 'hwat'
95
- resolved_path = "https://github.com/padrino/padrino-recipes/raw/master/plugins/hwat_plugin.rb"
95
+ resolved_path = "https://raw.github.com/padrino/padrino-recipes/master/plugins/hwat_plugin.rb"
96
96
  plugin_gen = Padrino::Generators::Plugin.new([ template_file], ["-r=#{@apptmp}/sample_project"],{})
97
97
  plugin_gen.expects(:in_app_root?).returns(true).once
98
98
  plugin_gen.expects(:say).with("The template at #{resolved_path} could not be found!", :red).returns(true).once
@@ -377,13 +377,8 @@ describe "ProjectGenerator" do
377
377
  should "properly generate for mongoid" do
378
378
  out, err = capture_io { generate(:project, 'project.com', "--root=#{@apptmp}", '--orm=mongoid', '--script=none') }
379
379
  assert_match(/applying.*?mongoid.*?orm/, out)
380
- if RUBY_VERSION >= '1.9'
381
- assert_match_in_file(/gem 'mongoid', '~>3.0.0'/, "#{@apptmp}/project.com/Gemfile")
382
- assert_match_in_file(/Mongoid::Config.sessions =/, "#{@apptmp}/project.com/config/database.rb")
383
- else
384
- assert_match_in_file(/gem 'mongoid', '~>2.0'/, "#{@apptmp}/project.com/Gemfile")
385
- assert_match_in_file(/Mongoid.database/, "#{@apptmp}/project.com/config/database.rb")
386
- end
380
+ assert_match_in_file(/gem 'mongoid', '~>3.0.0'/, "#{@apptmp}/project.com/Gemfile")
381
+ assert_match_in_file(/Mongoid::Config.sessions =/, "#{@apptmp}/project.com/config/database.rb")
387
382
  end
388
383
 
389
384
 
@@ -557,6 +552,20 @@ describe "ProjectGenerator" do
557
552
  assert_match_in_file(/task 'test' => test_tasks/,"#{@apptmp}/sample_project/test/test.rake")
558
553
  end
559
554
 
555
+ should "properly generate for steak" do
556
+ out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=steak', '--script=none') }
557
+ assert_match(/applying.*?steak.*?test/, out)
558
+ assert_match_in_file(/gem 'rack-test'/, "#{@apptmp}/sample_project/Gemfile")
559
+ assert_match_in_file(/:require => 'rack\/test'/, "#{@apptmp}/sample_project/Gemfile")
560
+ assert_match_in_file(/:group => 'test'/, "#{@apptmp}/sample_project/Gemfile")
561
+ assert_match_in_file(/gem 'steak'/, "#{@apptmp}/sample_project/Gemfile")
562
+ assert_match_in_file(/PADRINO_ENV = 'test' unless defined\?\(PADRINO_ENV\)/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
563
+ assert_match_in_file(/RSpec.configure/, "#{@apptmp}/sample_project/spec/spec_helper.rb")
564
+ assert_file_exists("#{@apptmp}/sample_project/spec/spec.rake")
565
+ assert_match_in_file(/RSpec::Core::RakeTask\.new\("spec:\#/,"#{@apptmp}/sample_project/spec/spec.rake")
566
+ assert_match_in_file(/task 'spec' => spec_tasks/,"#{@apptmp}/sample_project/spec/spec.rake")
567
+ end
568
+
560
569
  should "properly generate for minitest" do
561
570
  out, err = capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}", '--test=minitest', '--script=none') }
562
571
  assert_match(/applying.*?minitest.*?test/, out)
@@ -0,0 +1,53 @@
1
+ require File.expand_path(File.dirname(__FILE__) + '/helper')
2
+
3
+ describe "TaskGenerator" do
4
+ def setup
5
+ @apptmp = "#{Dir.tmpdir}/padrino-tests/#{UUID.new.generate}"
6
+ `mkdir -p #{@apptmp}`
7
+ end
8
+
9
+ def teardown
10
+ `rm -rf #{@apptmp}`
11
+ end
12
+
13
+ context 'the task generator' do
14
+ should "fail outside app root" do
15
+ out, err = capture_io { generate(:task, 'foo', "-r=#{@apptmp}") }
16
+ assert_match(/not at the root/, out)
17
+ assert_no_file_exists('/tmp/tasks/foo.rake')
18
+ end
19
+
20
+ should "generate filename properly" do
21
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
22
+ capture_io { generate(:task, 'DemoTask', "--namespace=Sample", "--description='This is a sample'", "-r=#{@apptmp}/sample_project") }
23
+ assert_file_exists("#{@apptmp}/sample_project/tasks/sample_demo_task.rake")
24
+ end
25
+
26
+ should "generate task file with description" do
27
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
28
+ capture_io { generate(:task, 'foo', "--description=This is a sample", "-r=#{@apptmp}/sample_project") }
29
+ file_path = "#{@apptmp}/sample_project/tasks/foo.rake"
30
+ assert_no_match_in_file(/namespace/, file_path)
31
+ assert_match_in_file(/desc "This is a sample"/, file_path)
32
+ assert_match_in_file(/task :foo => :environment do/, file_path)
33
+ end
34
+
35
+ should "generate task file with namespace" do
36
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
37
+ capture_io { generate(:task, 'foo', "--namespace=Sample", "-r=#{@apptmp}/sample_project") }
38
+ file_path = "#{@apptmp}/sample_project/tasks/sample_foo.rake"
39
+ assert_match_in_file(/namespace :sample do/, file_path)
40
+ assert_match_in_file(/task :foo => :environment do/, file_path)
41
+ assert_no_match_in_file(/desc/, file_path)
42
+ end
43
+
44
+ should "generate task file with snake case name when using camelized name" do
45
+ capture_io { generate(:project, 'sample_project', "--root=#{@apptmp}") }
46
+ capture_io { generate(:task, 'DemoTask', "--namespace=Sample", "--description=This is a sample", "-r=#{@apptmp}/sample_project") }
47
+ file_path = "#{@apptmp}/sample_project/tasks/sample_demo_task.rake"
48
+ assert_match_in_file(/namespace :sample do/, file_path)
49
+ assert_match_in_file(/desc "This is a sample"/, file_path)
50
+ assert_match_in_file(/task :demo_task => :environment do/, file_path)
51
+ end
52
+ end
53
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: padrino-gen
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.4
4
+ version: 0.12.0.rc1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Padrino Team
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2013-09-24 00:00:00.000000000 Z
14
+ date: 2013-12-31 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: padrino-core
@@ -19,14 +19,14 @@ dependencies:
19
19
  requirements:
20
20
  - - '='
21
21
  - !ruby/object:Gem::Version
22
- version: 0.11.4
22
+ version: 0.12.0.rc1
23
23
  type: :runtime
24
24
  prerelease: false
25
25
  version_requirements: !ruby/object:Gem::Requirement
26
26
  requirements:
27
27
  - - '='
28
28
  - !ruby/object:Gem::Version
29
- version: 0.11.4
29
+ version: 0.12.0.rc1
30
30
  - !ruby/object:Gem::Dependency
31
31
  name: bundler
32
32
  requirement: !ruby/object:Gem::Requirement
@@ -99,6 +99,7 @@ files:
99
99
  - lib/padrino-gen/generators/components/tests/riot.rb
100
100
  - lib/padrino-gen/generators/components/tests/rspec.rb
101
101
  - lib/padrino-gen/generators/components/tests/shoulda.rb
102
+ - lib/padrino-gen/generators/components/tests/steak.rb
102
103
  - lib/padrino-gen/generators/components/tests/testspec.rb
103
104
  - lib/padrino-gen/generators/controller.rb
104
105
  - lib/padrino-gen/generators/mailer.rb
@@ -112,6 +113,7 @@ files:
112
113
  - lib/padrino-gen/generators/project/config/boot.rb
113
114
  - lib/padrino-gen/generators/project/public/favicon.ico
114
115
  - lib/padrino-gen/generators/runner.rb
116
+ - lib/padrino-gen/generators/task.rb
115
117
  - lib/padrino-gen/generators/templates/Gemfile.tt
116
118
  - lib/padrino-gen/generators/templates/Rakefile.tt
117
119
  - lib/padrino-gen/generators/templates/controller.rb.tt
@@ -122,6 +124,7 @@ files:
122
124
  - lib/padrino-gen/generators/templates/helper.rb.tt
123
125
  - lib/padrino-gen/generators/templates/initializer.rb.tt
124
126
  - lib/padrino-gen/generators/templates/mailer.rb.tt
127
+ - lib/padrino-gen/generators/templates/task.rb.tt
125
128
  - lib/padrino-gen/padrino-tasks/activerecord.rb
126
129
  - lib/padrino-gen/padrino-tasks/database.rb
127
130
  - lib/padrino-gen/padrino-tasks/datamapper.rb
@@ -147,6 +150,7 @@ files:
147
150
  - test/test_model_generator.rb
148
151
  - test/test_plugin_generator.rb
149
152
  - test/test_project_generator.rb
153
+ - test/test_task_generator.rb
150
154
  - lib/padrino-gen/generators/templates/static/js/dojo.js
151
155
  - lib/padrino-gen/generators/templates/static/js/ext.js
152
156
  - lib/padrino-gen/generators/templates/static/js/jquery.js
@@ -162,7 +166,8 @@ files:
162
166
  - lib/padrino-gen/generators/templates/static/ujs/prototype.js
163
167
  - lib/padrino-gen/generators/templates/static/ujs/right.js
164
168
  homepage: http://www.padrinorb.com
165
- licenses: []
169
+ licenses:
170
+ - MIT
166
171
  metadata: {}
167
172
  post_install_message:
168
173
  rdoc_options:
@@ -176,9 +181,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
176
181
  version: '0'
177
182
  required_rubygems_version: !ruby/object:Gem::Requirement
178
183
  requirements:
179
- - - '>='
184
+ - - '>'
180
185
  - !ruby/object:Gem::Version
181
- version: 1.3.6
186
+ version: 1.3.1
182
187
  requirements: []
183
188
  rubyforge_project: padrino-gen
184
189
  rubygems_version: 2.0.6
@@ -202,4 +207,5 @@ test_files:
202
207
  - test/test_model_generator.rb
203
208
  - test/test_plugin_generator.rb
204
209
  - test/test_project_generator.rb
210
+ - test/test_task_generator.rb
205
211
  has_rdoc: