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
@@ -1,59 +1,61 @@
1
- class <%= @app_name %> < Padrino::Application
2
- register Padrino::Rendering
3
- register Padrino::Mailer
4
- register Padrino::Helpers
1
+ module <%= @project_name %>
2
+ class <%= @app_name %> < Padrino::Application
3
+ register Padrino::Rendering
4
+ register Padrino::Mailer
5
+ register Padrino::Helpers
5
6
 
6
- enable :sessions
7
+ enable :sessions
7
8
 
8
- ##
9
- # Caching support
10
- #
11
- # register Padrino::Cache
12
- # enable :caching
13
- #
14
- # You can customize caching store engines:
15
- #
16
- # set :cache, Padrino::Cache::Store::Memcache.new(::Memcached.new('127.0.0.1:11211', :exception_retry_limit => 1))
17
- # set :cache, Padrino::Cache::Store::Memcache.new(::Dalli::Client.new('127.0.0.1:11211', :exception_retry_limit => 1))
18
- # set :cache, Padrino::Cache::Store::Redis.new(::Redis.new(:host => '127.0.0.1', :port => 6379, :db => 0))
19
- # set :cache, Padrino::Cache::Store::Memory.new(50)
20
- # set :cache, Padrino::Cache::Store::File.new(Padrino.root('tmp', app_name.to_s, 'cache')) # default choice
21
- #
9
+ ##
10
+ # Caching support
11
+ #
12
+ # register Padrino::Cache
13
+ # enable :caching
14
+ #
15
+ # You can customize caching store engines:
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
22
+ #
22
23
 
23
- ##
24
- # Application configuration options
25
- #
26
- # set :raise_errors, true # Raise exceptions (will stop application) (default for test)
27
- # set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development)
28
- # set :show_exceptions, true # Shows a stack trace in browser (default for development)
29
- # set :logging, true # Logging in STDOUT for development and file for production (default only for development)
30
- # set :public_folder, "foo/bar" # Location for static assets (default root/public)
31
- # set :reload, false # Reload application files (default in development)
32
- # set :default_builder, "foo" # Set a custom form builder (default 'StandardFormBuilder')
33
- # set :locale_path, "bar" # Set path for I18n translations (default your_app/locales)
34
- # disable :sessions # Disabled sessions by default (enable if needed)
35
- # disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined)
36
- # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
37
- #
24
+ ##
25
+ # Application configuration options
26
+ #
27
+ # set :raise_errors, true # Raise exceptions (will stop application) (default for test)
28
+ # set :dump_errors, true # Exception backtraces are written to STDERR (default for production/development)
29
+ # set :show_exceptions, true # Shows a stack trace in browser (default for development)
30
+ # set :logging, true # Logging in STDOUT for development and file for production (default only for development)
31
+ # set :public_folder, 'foo/bar' # Location for static assets (default root/public)
32
+ # set :reload, false # Reload application files (default in development)
33
+ # set :default_builder, 'foo' # Set a custom form builder (default 'StandardFormBuilder')
34
+ # set :locale_path, 'bar' # Set path for I18n translations (default your_app/locales)
35
+ # disable :sessions # Disabled sessions by default (enable if needed)
36
+ # disable :flash # Disables sinatra-flash (enabled by default if Sinatra::Flash is defined)
37
+ # layout :my_layout # Layout can be in views/layouts/foo.ext or views/foo.ext (default :application)
38
+ #
38
39
 
39
- ##
40
- # You can configure for a specified environment like:
41
- #
42
- # configure :development do
43
- # set :foo, :bar
44
- # disable :asset_stamp # no asset timestamping for dev
45
- # end
46
- #
40
+ ##
41
+ # You can configure for a specified environment like:
42
+ #
43
+ # configure :development do
44
+ # set :foo, :bar
45
+ # disable :asset_stamp # no asset timestamping for dev
46
+ # end
47
+ #
47
48
 
48
- ##
49
- # You can manage errors like:
50
- #
51
- # error 404 do
52
- # render 'errors/404'
53
- # end
54
- #
55
- # error 505 do
56
- # render 'errors/505'
57
- # end
58
- #
49
+ ##
50
+ # You can manage errors like:
51
+ #
52
+ # error 404 do
53
+ # render 'errors/404'
54
+ # end
55
+ #
56
+ # error 505 do
57
+ # render 'errors/505'
58
+ # end
59
+ #
60
+ end
59
61
  end
@@ -19,12 +19,11 @@ module Padrino
19
19
  include Padrino::Generators::Actions
20
20
 
21
21
  desc "Description:\n\n\tpadrino-gen app generates a new Padrino application"
22
-
23
- argument :name, :desc => "The name of your padrino application"
24
-
25
- class_option :root, :desc => "The root destination", :aliases => '-r', :default => ".", :type => :string
26
- class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
27
- class_option :tiny, :desc => "Generate tiny app skeleton", :aliases => '-i', :default => false, :type => :boolean
22
+ argument :name, :desc => 'The name of your padrino application'
23
+ class_option :root, :desc => 'The root destination', :aliases => '-r', :default => '.', :type => :string
24
+ class_option :destroy, :aliases => '-d', :default => false, :type => :boolean
25
+ class_option :tiny, :desc => 'Generate tiny app skeleton', :aliases => '-i', :default => false, :type => :boolean
26
+ class_option :namespace, :desc => 'The name space of your padrino project', :aliases => '-n', :default => '', :type => :string
28
27
 
29
28
  # Show help if no argv given
30
29
  require_arguments!
@@ -34,24 +33,25 @@ module Padrino
34
33
  # @api private
35
34
  def create_app
36
35
  self.destination_root = options[:root]
37
- @app_name = name.gsub(/\W/, "_").underscore.camelize
36
+ @app_folder = name.gsub(/\W/, '_').underscore
37
+ @app_name = name.gsub(/\W/, '_').underscore.camelize
38
38
  if in_app_root?
39
+ @project_name = options[:namespace].underscore.camelize
40
+ @project_name = fetch_project_name(@app_folder) if @project_name.empty?
39
41
  self.behavior = :revoke if options[:destroy]
40
- app_skeleton(@app_name.downcase, options[:tiny])
41
- empty_directory destination_root("public/#{@app_name.downcase}")
42
- append_file destination_root("config/apps.rb"), "\nPadrino.mount(\"#{@app_name}\").to(\"/#{@app_name.downcase}\")"
42
+ app_skeleton(@app_folder.downcase, options[:tiny])
43
+ empty_directory destination_root("public/#{@app_folder.downcase}")
44
+ append_file destination_root('config/apps.rb'), "\nPadrino.mount('#{@project_name}::#{@app_name}', :app_file => Padrino.root('#{@app_folder.downcase}/app.rb')).to('/#{@app_folder.downcase}')"
43
45
 
44
46
  return if self.behavior == :revoke
45
47
  say
46
- say "="*65, :green
48
+ say '=' * 65, :green
47
49
  say "Your #{@app_name} application has been installed."
48
- say "="*65, :green
50
+ say '='*65, :green
49
51
  say "This application has been mounted to /#{@app_name.downcase}"
50
- say "You can configure a different path by editing 'config/apps.rb"
51
- say "="*65, :green
52
- say
52
+ say "You can configure a different path by editing 'config/apps.rb'"
53
53
  else
54
- say "You are not at the root of a Padrino application! (config/boot.rb not found)"
54
+ say 'You are not at the root of a Padrino application! (config/boot.rb not found)'
55
55
  end
56
56
  end
57
57
  end # App
@@ -20,8 +20,8 @@ module Padrino
20
20
  # @api private
21
21
  def load_boot
22
22
  begin
23
- ENV['PADRINO_LOG_LEVEL'] ||= "test"
24
- ENV['BUNDLE_GEMFILE'] = File.join(options[:root], "Gemfile") if options[:root]
23
+ ENV['PADRINO_LOG_LEVEL'] ||= 'test'
24
+ ENV['BUNDLE_GEMFILE'] = File.join(options[:root], 'Gemfile') if options[:root]
25
25
  boot = options[:root] ? File.join(options[:root], 'config/boot.rb') : 'config/boot.rb'
26
26
  if File.exist?(boot)
27
27
  require File.expand_path(boot)
@@ -47,7 +47,7 @@ module Padrino
47
47
  generator_class = Padrino::Generators.mappings[generator_kind]
48
48
 
49
49
  if generator_class
50
- args = ARGV.empty? && generator_class.require_arguments? ? ["-h"] : ARGV
50
+ args = ARGV.empty? && generator_class.require_arguments? ? ['-h'] : ARGV
51
51
  generator_class.start(args)
52
52
  else
53
53
  puts "Please specify generator to use (#{Padrino::Generators.mappings.keys.join(", ")})"
@@ -139,7 +139,7 @@ module Padrino
139
139
  # @api private
140
140
  def insert_test_suite_setup(suite_text, options={})
141
141
  options.reverse_merge!(:path => "test/test_config.rb")
142
- create_file(options[:path], suite_text.gsub(/CLASS_NAME/, @app_name))
142
+ create_file(options[:path], suite_text.gsub(/CLASS_NAME/, "#{@project_name}::#{@app_name}"))
143
143
  end
144
144
 
145
145
  # For mocking components
@@ -3,7 +3,7 @@ AR = (<<-AR) unless defined?(AR)
3
3
  # You can use other adapters like:
4
4
  #
5
5
  # ActiveRecord::Base.configurations[:development] = {
6
- # :adapter => 'mysql',
6
+ # :adapter => 'mysql2',
7
7
  # :encoding => 'utf8',
8
8
  # :reconnect => true,
9
9
  # :database => 'your_database',
@@ -29,11 +29,11 @@ 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
32
+ # Raise exception on mass assignment protection for Active Record models.
33
33
  ActiveRecord::Base.mass_assignment_sanitizer = :strict
34
34
 
35
35
  # Log the query plan for queries taking more than this (works
36
- # with SQLite, MySQL, and PostgreSQL)
36
+ # with SQLite, MySQL, and PostgreSQL).
37
37
  ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
38
38
 
39
39
  # Include Active Record class name as root for JSON serialized output.
@@ -45,11 +45,11 @@ ActiveRecord::Base.store_full_sti_class = true
45
45
  # Use ISO 8601 format for JSON serialized times and dates.
46
46
  ActiveSupport.use_standard_json_time_format = true
47
47
 
48
- # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
49
- # if you're including raw json in an HTML page.
48
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper
49
+ # if you're including raw JSON in an HTML page.
50
50
  ActiveSupport.escape_html_entities_in_json = false
51
51
 
52
- # Now we can estabilish connection with our db
52
+ # Now we can establish connection with our db.
53
53
  ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
54
54
  AR
55
55
 
@@ -94,14 +94,15 @@ SQLITE
94
94
 
95
95
  def setup_orm
96
96
  ar = AR
97
- db = @app_name.underscore
97
+ db = @project_name.underscore
98
+ # We're now defaulting to mysql2 since mysql is deprecated
98
99
  case options[:adapter]
99
- when 'mysql'
100
+ when 'mysql-gem'
100
101
  ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_development'")
101
102
  ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_production'")
102
103
  ar.gsub! /!DB_TEST!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_test'")
103
- require_dependencies 'mysql'
104
- when 'mysql2'
104
+ require_dependencies 'mysql', :version => "~> 2.8.1"
105
+ when 'mysql', 'mysql2'
105
106
  ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_development'")
106
107
  ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_production'")
107
108
  ar.gsub! /!DB_TEST!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_test'")
@@ -117,7 +118,7 @@ def setup_orm
117
118
  ar.gsub! /!DB_TEST!/, SQLITE.gsub(/!DB_NAME!/,"Padrino.root('db', '#{db}_test.db')")
118
119
  require_dependencies 'sqlite3'
119
120
  end
120
- require_dependencies 'activerecord', :require => 'active_record'
121
+ require_dependencies 'activerecord', :require => 'active_record', :version => ">= 3.1"
121
122
  insert_middleware 'ActiveRecord::ConnectionAdapters::ConnectionManagement'
122
123
  create_file("config/database.rb", ar)
123
124
  end
@@ -148,7 +149,7 @@ class !FILECLASS! < ActiveRecord::Migration
148
149
  end
149
150
  MIGRATION
150
151
 
151
- AR_MODEL_UP_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(AR_MODEL_UP_MG)
152
+ AR_MODEL_UP_MG = (<<-MIGRATION) unless defined?(AR_MODEL_UP_MG)
152
153
  create_table :!TABLE! do |t|
153
154
  !FIELDS!
154
155
  t.timestamps
@@ -161,9 +162,11 @@ MIGRATION
161
162
 
162
163
  def create_model_migration(migration_name, name, columns)
163
164
  output_model_migration(migration_name, name, columns,
164
- :base => AR_MIGRATION,
165
- :column_format => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
166
- :up => AR_MODEL_UP_MG, :down => AR_MODEL_DOWN_MG)
165
+ :base => AR_MIGRATION,
166
+ :column_format => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
167
+ :up => AR_MODEL_UP_MG,
168
+ :down => AR_MODEL_DOWN_MG
169
+ )
167
170
  end
168
171
 
169
172
  AR_CHANGE_MG = (<<-MIGRATION).gsub(/^/, ' ') unless defined?(AR_CHANGE_MG)
@@ -174,8 +177,9 @@ MIGRATION
174
177
 
175
178
  def create_migration_file(migration_name, name, columns)
176
179
  output_migration_file(migration_name, name, columns,
177
- :base => AR_MIGRATION, :change_format => AR_CHANGE_MG,
178
- :add => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
179
- :remove => Proc.new { |field, kind| "t.remove :#{field}" }
180
+ :base => AR_MIGRATION,
181
+ :change_format => AR_CHANGE_MG,
182
+ :add => Proc.new { |field, kind| "t.#{kind.underscore.gsub(/_/, '')} :#{field}" },
183
+ :remove => Proc.new { |field, kind| "t.remove :#{field}" }
180
184
  )
181
185
  end
@@ -25,7 +25,7 @@ COUCHREST
25
25
  def setup_orm
26
26
  require_dependencies 'couchrest_model', :version => '~>1.1.0'
27
27
  require_dependencies 'json_pure'
28
- create_file("config/database.rb", COUCHREST.gsub(/!NAME!/, @app_name.underscore))
28
+ create_file("config/database.rb", COUCHREST.gsub(/!NAME!/, @project_name.underscore))
29
29
  end
30
30
 
31
31
  CR_MODEL = (<<-MODEL) unless defined?(CR_MODEL)
@@ -22,9 +22,10 @@ DM
22
22
 
23
23
  def setup_orm
24
24
  dm = DM
25
- db = @app_name.underscore
25
+ db = @project_name.underscore
26
26
  %w(
27
27
  dm-core
28
+ dm-types
28
29
  dm-aggregates
29
30
  dm-constraints
30
31
  dm-migrations
@@ -14,11 +14,11 @@ 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
17
+ # Raise exception on mass assignment protection for Active Record models.
18
18
  ActiveRecord::Base.mass_assignment_sanitizer = :strict
19
19
 
20
20
  # Log the query plan for queries taking more than this (works
21
- # with SQLite, MySQL, and PostgreSQL)
21
+ # with SQLite, MySQL, and PostgreSQL).
22
22
  ActiveRecord::Base.auto_explain_threshold_in_seconds = 0.5
23
23
 
24
24
  # Doesn't include Active Record class name as root for JSON serialized output.
@@ -30,11 +30,11 @@ ActiveRecord::Base.store_full_sti_class = true
30
30
  # Use ISO 8601 format for JSON serialized times and dates.
31
31
  ActiveSupport.use_standard_json_time_format = true
32
32
 
33
- # Don't escape HTML entities in JSON, leave that for the #json_escape helper.
34
- # if you're including raw json in an HTML page.
33
+ # Don't escape HTML entities in JSON, leave that for the #json_escape helper
34
+ # if you're including raw JSON in an HTML page.
35
35
  ActiveSupport.escape_html_entities_in_json = false
36
36
 
37
- # Now we can estabilish connection with our db
37
+ # Now we can establish connection with our db.
38
38
  ActiveRecord::Base.establish_connection(ActiveRecord::Base.configurations[Padrino.env])
39
39
  MR
40
40
 
@@ -77,14 +77,14 @@ SQLITE = (<<-SQLITE) unless defined?(SQLITE)
77
77
  SQLITE
78
78
  def setup_orm
79
79
  ar = MR
80
- db = @app_name.underscore
80
+ db = @project_name.underscore
81
81
  case options[:adapter]
82
- when 'mysql'
82
+ when 'mysql-gem'
83
83
  ar.gsub! /!DB_DEVELOPMENT!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_development'")
84
84
  ar.gsub! /!DB_PRODUCTION!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_production'")
85
85
  ar.gsub! /!DB_TEST!/, MYSQL.gsub(/!DB_NAME!/,"'#{db}_test'")
86
- require_dependencies 'mysql'
87
- when 'mysql2'
86
+ require_dependencies 'mysql', :version => "~> 2.8.1"
87
+ when 'mysql', 'mysql2'
88
88
  ar.gsub! /!DB_DEVELOPMENT!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_development'")
89
89
  ar.gsub! /!DB_PRODUCTION!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_production'")
90
90
  ar.gsub! /!DB_TEST!/, MYSQL2.gsub(/!DB_NAME!/,"'#{db}_test'")
@@ -1,5 +1,4 @@
1
1
  MONGOID = (<<-MONGO) unless defined?(MONGOID)
2
-
3
2
  # Connection.new takes host, port
4
3
  host = 'localhost'
5
4
  port = Mongo::Connection::DEFAULT_PORT
@@ -23,14 +22,69 @@ Mongoid.database = Mongo::Connection.new(host, port).db(database_name)
23
22
  # ]
24
23
  # end
25
24
  #
26
- # More installation and setup notes are on http://mongoid.org/docs/
25
+ # More installation and setup notes are on http://mongoid.org/
26
+ MONGO
27
+
28
+ MONGOID3 = (<<-MONGO) unless defined?(MONGOID3)
29
+ # Connection.new takes host, port
30
+
31
+ host = 'localhost'
32
+ port = 27017
33
+
34
+ database_name = case Padrino.env
35
+ when :development then '!NAME!_development'
36
+ when :production then '!NAME!_production'
37
+ when :test then '!NAME!_test'
38
+ end
39
+
40
+ # Use MONGO_URI if it's set as an environmental variable
41
+ Mongoid::Config.sessions =
42
+ if ENV['MONGO_URI']
43
+ {default: {uri: ENV['MONGO_URI'] }}
44
+ else
45
+ {default: {hosts: ["#\{host\}:#\{port\}"], database: database_name}}
46
+ end
47
+
48
+ # If you want to use a YML file for config, use this instead:
49
+ #
50
+ #  Mongoid.load!(File.join(Padrino.root, 'config', 'database.yml'), Padrino.env)
51
+ #
52
+ # And add a config/database.yml file like this:
53
+ # development:
54
+ # sessions:
55
+ # default:
56
+ # database: !NAME!_development
57
+ # hosts:
58
+ # - localhost:27017
59
+ # production:
60
+ # sessions:
61
+ # default:
62
+ # database: !NAME!_production
63
+ # hosts:
64
+ # - localhost:27017
65
+ # test:
66
+ # sessions:
67
+ # default:
68
+ # database: !NAME!_test
69
+ # hosts:
70
+ # - localhost:27017
71
+ #
72
+ #
73
+ # More installation and setup notes are on http://mongoid.org/en/mongoid/docs/installation.html#configuration
27
74
  MONGO
28
75
 
29
76
  def setup_orm
30
- require_dependencies 'bson_ext', :require => 'mongo'
31
- require_dependencies 'mongoid'
32
- require_dependencies('SystemTimer', :require => 'system_timer') if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
33
- create_file("config/database.rb", MONGOID.gsub(/!NAME!/, @app_name.underscore))
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
34
88
  end
35
89
 
36
90
  MONGOID_MODEL = (<<-MODEL) unless defined?(MONGOID_MODEL)
@@ -9,10 +9,10 @@ end
9
9
  MONGO
10
10
 
11
11
  def setup_orm
12
- require_dependencies 'bson_ext', :require => 'mongo'
13
12
  require_dependencies 'mongo_mapper'
13
+ require_dependencies 'bson_ext', :require => 'mongo'
14
14
  require_dependencies('SystemTimer', :require => 'system_timer') if RUBY_VERSION =~ /1\.8/ && (!defined?(RUBY_ENGINE) || RUBY_ENGINE == 'ruby')
15
- create_file("config/database.rb", MONGO.gsub(/!NAME!/, @app_name.underscore))
15
+ create_file("config/database.rb", MONGO.gsub(/!NAME!/, @project_name.underscore))
16
16
  end
17
17
 
18
18
  MM_MODEL = (<<-MODEL) unless defined?(MM_MODEL)
@@ -9,9 +9,9 @@ MONGO
9
9
 
10
10
  def setup_orm
11
11
  mongomatic = MONGOMATIC
12
- require_dependencies 'bson_ext', :require => 'mongo'
13
12
  require_dependencies 'mongomatic'
14
- create_file("config/database.rb", MONGOMATIC.gsub(/!NAME!/, @app_name.underscore))
13
+ require_dependencies 'bson_ext', :require => 'mongo'
14
+ create_file("config/database.rb", MONGOMATIC.gsub(/!NAME!/, @project_name.underscore))
15
15
  end
16
16
 
17
17
  MONGOMATIC_MODEL = (<<-MODEL) unless defined?(MONGOMATIC_MODEL)
@@ -20,24 +20,71 @@ OHM = (<<-OHM) unless defined?(OHM)
20
20
  # when :production then Ohm.connect(:db => 1)
21
21
  # when :test then Ohm.connect(:db => 2)
22
22
  # end
23
+
24
+ # This monkey patch provides traditional (hash of arrays) error handling for ohm models
25
+ # Also add compatiblity with admin generator.
26
+ module Ohm
27
+ class Model
28
+
29
+ alias_method :old_errors, :errors
30
+ def errors
31
+ @errors ||= ErrorsHash.new(self.class.to_reference, self.old_errors)
32
+ end
33
+
34
+ def update_attributes(attrs)
35
+ attrs.each do |key, value|
36
+ send(:"\#{key}=", value)
37
+ end if attrs
38
+ end
39
+
40
+ class << self
41
+ alias_method :old_attribute, :attribute
42
+ def attribute(name, cast=nil)
43
+ attributes << name
44
+ old_attribute(name, cast)
45
+ end
46
+
47
+ def attributes
48
+ @_attributes ||= []
49
+ end
50
+ end
51
+
52
+ class ErrorsHash < Hash
53
+ def initialize(scope, errors)
54
+ @scope = scope
55
+ self.replace Hash.new { |hash, key| hash[key] = [] }
56
+
57
+ errors.each do |key, value|
58
+ self[key] << value
59
+ end
60
+ end
61
+
62
+ def push(arr)
63
+ self[arr[0]] << arr[1]
64
+ end
65
+
66
+ def full_messages
67
+ self.map do |key, value|
68
+ value.uniq.map do |reason|
69
+ I18n::t("ohm.%s.%s.%s" % [@scope, key, reason])
70
+ end.join(', ')
71
+ end
72
+ end
73
+ end
74
+ end
75
+ end # unless Ohm::Model.new.errors.is_a?(Hash)
23
76
  OHM
24
77
 
25
78
  def setup_orm
26
- ohm = OHM
27
- require_dependencies 'json'
28
- require_dependencies 'ohm', :require => 'ohm'
29
- require_dependencies 'ohm-contrib', :require => 'ohm/contrib'
30
- create_file("config/database.rb", ohm)
79
+ require_dependencies 'ohm'
80
+ create_file("config/database.rb", OHM)
31
81
  end
32
82
 
33
83
  OHM_MODEL = (<<-MODEL) unless defined?(OHM_MODEL)
34
84
  class !NAME! < Ohm::Model
35
- include Ohm::Timestamping
36
- include Ohm::Typecast
37
-
38
85
  # Examples:
39
86
  # attribute :name
40
- # attribute :email, String
87
+ # attribute :email
41
88
  # reference :venue, Venue
42
89
  # set :participants, Person
43
90
  # counter :votes
@@ -56,7 +103,7 @@ MODEL
56
103
  def create_model_file(name, options={})
57
104
  model_path = destination_root(options[:app], 'models', "#{name.to_s.underscore}.rb")
58
105
  field_tuples = options[:fields].map { |value| value.split(":") }
59
- column_declarations = field_tuples.map { |field, kind| "attribute :#{field}, #{kind.underscore.camelize}" }.join("\n ")
106
+ column_declarations = field_tuples.map { |field, kind| "attribute :#{field}" }.join("\n ")
60
107
  model_contents = OHM_MODEL.gsub(/!NAME!/, name.to_s.underscore.camelize)
61
108
  model_contents.gsub!(/!FIELDS!/, column_declarations)
62
109
  create_file(model_path, model_contents)
@@ -35,7 +35,7 @@ RIAK
35
35
 
36
36
  def setup_orm
37
37
  require_dependencies 'ripple'
38
- create_file("config/riak.yml", RIPPLE_DB.gsub(/!NAME!/, @app_name.underscore))
38
+ create_file("config/riak.yml", RIPPLE_DB.gsub(/!NAME!/, @project_name.underscore))
39
39
  create_file("config/database.rb", RIPPLE_CFG)
40
40
  end
41
41
 
@@ -10,23 +10,32 @@ SEQUEL
10
10
 
11
11
  def setup_orm
12
12
  sequel = SEQUEL
13
- db = @app_name.underscore
13
+ db = @project_name.underscore
14
14
  require_dependencies 'sequel'
15
- require_dependencies case options[:adapter]
15
+ case options[:adapter]
16
+ when 'mysql-gem'
17
+ sequel.gsub!(/!DB_DEVELOPMENT!/, "\"mysql://localhost/#{db}_development\"")
18
+ sequel.gsub!(/!DB_PRODUCTION!/, "\"mysql://localhost/#{db}_production\"")
19
+ sequel.gsub!(/!DB_TEST!/,"\"mysql://localhost/#{db}_test\"")
20
+ require_dependencies 'mysql', :version => "~> 2.8.1"
21
+ 'mysql'
16
22
  when 'mysql', 'mysql2'
17
- sequel.gsub!(/!DB_DEVELOPMENT!/, "\"#{options[:adapter]}://localhost/#{db}_development\"")
18
- sequel.gsub!(/!DB_PRODUCTION!/, "\"#{options[:adapter]}://localhost/#{db}_production\"")
19
- sequel.gsub!(/!DB_TEST!/,"\"#{options[:adapter]}://localhost/#{db}_test\"")
20
- options[:adapter]
23
+ sequel.gsub!(/!DB_DEVELOPMENT!/, "\"mysql2://localhost/#{db}_development\"")
24
+ sequel.gsub!(/!DB_PRODUCTION!/, "\"mysql2://localhost/#{db}_production\"")
25
+ sequel.gsub!(/!DB_TEST!/,"\"mysql2://localhost/#{db}_test\"")
26
+ require_dependencies 'mysql2'
27
+ 'mysql2'
21
28
  when 'postgres'
22
29
  sequel.gsub!(/!DB_DEVELOPMENT!/, "\"postgres://localhost/#{db}_development\"")
23
30
  sequel.gsub!(/!DB_PRODUCTION!/, "\"postgres://localhost/#{db}_production\"")
24
31
  sequel.gsub!(/!DB_TEST!/,"\"postgres://localhost/#{db}_test\"")
32
+ require_dependencies 'pg'
25
33
  'pg'
26
34
  else
27
35
  sequel.gsub!(/!DB_DEVELOPMENT!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_development.db\")")
28
36
  sequel.gsub!(/!DB_PRODUCTION!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_production.db\")")
29
37
  sequel.gsub!(/!DB_TEST!/,"\"sqlite://\" + Padrino.root('db', \"#{db}_test.db\")")
38
+ require_dependencies 'sqlite3'
30
39
  'sqlite3'
31
40
  end
32
41
  create_file("config/database.rb", sequel)
@@ -27,7 +27,7 @@ end
27
27
  COMPASS
28
28
 
29
29
  COMPASS_REGISTER = <<-COMPASSR unless defined?(COMPASS_REGISTER)
30
- register CompassInitializer\n
30
+ register CompassInitializer\n
31
31
  COMPASSR
32
32
 
33
33
  def setup_stylesheet
@@ -19,6 +19,7 @@ LESS
19
19
  def setup_stylesheet
20
20
  require_dependencies 'less'
21
21
  require_dependencies 'rack-less'
22
+ require_dependencies 'therubyracer'
22
23
  initializer :less, LESS_INIT
23
24
  empty_directory destination_root('/app/stylesheets')
24
25
  end