railties 5.0.7.2 → 5.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/CHANGELOG.md +77 -567
- data/MIT-LICENSE +1 -1
- data/RDOC_MAIN.rdoc +3 -3
- data/README.rdoc +1 -1
- data/exe/rails +2 -2
- data/lib/rails.rb +18 -18
- data/lib/rails/all.rb +1 -1
- data/lib/rails/api/generator.rb +28 -0
- data/lib/rails/api/task.rb +54 -42
- data/lib/rails/app_loader.rb +9 -9
- data/lib/rails/application.rb +30 -35
- data/lib/rails/application/bootstrap.rb +13 -7
- data/lib/rails/application/configuration.rb +30 -53
- data/lib/rails/application/default_middleware_stack.rb +3 -5
- data/lib/rails/application/finisher.rb +16 -7
- data/lib/rails/application/routes_reloader.rb +16 -1
- data/lib/rails/application_controller.rb +10 -10
- data/lib/rails/backtrace_cleaner.rb +5 -5
- data/lib/rails/cli.rb +7 -5
- data/lib/rails/code_statistics.rb +16 -17
- data/lib/rails/code_statistics_calculator.rb +3 -3
- data/lib/rails/command.rb +111 -0
- data/lib/rails/command/actions.rb +42 -0
- data/lib/rails/command/base.rb +149 -0
- data/lib/rails/command/behavior.rb +123 -0
- data/lib/rails/command/environment_argument.rb +34 -0
- data/lib/rails/commands.rb +2 -4
- data/lib/rails/commands/application/application_command.rb +29 -0
- data/lib/rails/commands/console/console_command.rb +89 -0
- data/lib/rails/commands/dbconsole/dbconsole_command.rb +155 -0
- data/lib/rails/commands/destroy/destroy_command.rb +21 -0
- data/lib/rails/commands/generate/generate_command.rb +23 -0
- data/lib/rails/commands/help/USAGE +15 -0
- data/lib/rails/commands/help/help_command.rb +13 -0
- data/lib/rails/commands/new/new_command.rb +15 -0
- data/lib/rails/commands/plugin/plugin_command.rb +43 -0
- data/lib/rails/commands/rake/rake_command.rb +49 -0
- data/lib/rails/commands/runner/USAGE +17 -0
- data/lib/rails/commands/runner/runner_command.rb +46 -0
- data/lib/rails/commands/secrets/USAGE +52 -0
- data/lib/rails/commands/secrets/secrets_command.rb +36 -0
- data/lib/rails/commands/server/server_command.rb +177 -0
- data/lib/rails/commands/test/test_command.rb +20 -0
- data/lib/rails/commands/version/version_command.rb +9 -0
- data/lib/rails/configuration.rb +7 -7
- data/lib/rails/console/app.rb +4 -4
- data/lib/rails/dev_caching.rb +8 -8
- data/lib/rails/engine.rb +62 -63
- data/lib/rails/engine/commands.rb +6 -13
- data/lib/rails/engine/configuration.rb +2 -2
- data/lib/rails/gem_version.rb +3 -3
- data/lib/rails/generators.rb +229 -313
- data/lib/rails/generators/actions.rb +20 -21
- data/lib/rails/generators/actions/create_migration.rb +24 -25
- data/lib/rails/generators/active_model.rb +3 -3
- data/lib/rails/generators/app_base.rb +123 -93
- data/lib/rails/generators/base.rb +32 -33
- data/lib/rails/generators/css/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/erb.rb +14 -14
- data/lib/rails/generators/erb/controller/controller_generator.rb +1 -1
- data/lib/rails/generators/erb/mailer/mailer_generator.rb +12 -12
- data/lib/rails/generators/erb/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/generated_attribute.rb +27 -27
- data/lib/rails/generators/js/assets/assets_generator.rb +1 -1
- data/lib/rails/generators/migration.rb +8 -8
- data/lib/rails/generators/model_helpers.rb +2 -2
- data/lib/rails/generators/named_base.rb +56 -56
- data/lib/rails/generators/rails/app/app_generator.rb +98 -81
- data/lib/rails/generators/rails/app/templates/Gemfile +7 -2
- data/lib/rails/generators/rails/app/templates/app/assets/config/manifest.js.tt +0 -2
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +6 -4
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/cable.js +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +2 -2
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/bin/{setup → setup.tt} +6 -0
- data/lib/rails/generators/rails/app/templates/bin/{update → update.tt} +2 -1
- data/lib/rails/generators/rails/app/templates/bin/yarn +9 -0
- data/lib/rails/generators/rails/app/templates/config/cable.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +2 -1
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +2 -2
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +1 -0
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +10 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/initializers/application_controller_renderer.rb +4 -6
- data/lib/rails/generators/rails/app/templates/config/initializers/assets.rb.tt +8 -3
- data/lib/rails/generators/rails/app/templates/config/initializers/new_framework_defaults.rb.tt +6 -5
- data/lib/rails/generators/rails/app/templates/config/locales/en.yml +10 -0
- data/lib/rails/generators/rails/app/templates/config/puma.rb +16 -7
- data/lib/rails/generators/rails/app/templates/config/secrets.yml +12 -2
- data/lib/rails/generators/rails/app/templates/gitignore +5 -1
- data/lib/rails/generators/rails/app/templates/package.json +5 -0
- data/lib/rails/generators/rails/app/templates/public/404.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/422.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/500.html +6 -6
- data/lib/rails/generators/rails/app/templates/public/robots.txt +0 -4
- data/lib/rails/generators/rails/app/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/app/templates/test/test_helper.rb +0 -1
- data/lib/rails/generators/rails/assets/assets_generator.rb +10 -10
- data/lib/rails/generators/rails/controller/controller_generator.rb +15 -12
- data/lib/rails/generators/rails/encrypted_secrets/encrypted_secrets_generator.rb +66 -0
- data/lib/rails/generators/rails/encrypted_secrets/templates/config/secrets.yml.enc +3 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -3
- data/lib/rails/generators/rails/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/rails/model/model_generator.rb +1 -1
- data/lib/rails/generators/rails/plugin/plugin_generator.rb +21 -26
- data/lib/rails/generators/rails/plugin/templates/bin/rails.tt +1 -0
- data/lib/rails/generators/rails/plugin/templates/bin/test.tt +3 -9
- data/lib/rails/generators/rails/plugin/templates/test/application_system_test_case.rb +5 -0
- data/lib/rails/generators/rails/plugin/templates/test/test_helper.rb +0 -3
- data/lib/rails/generators/rails/resource/resource_generator.rb +2 -2
- data/lib/rails/generators/rails/scaffold/scaffold_generator.rb +5 -1
- data/lib/rails/generators/rails/scaffold/templates/scaffold.css +4 -8
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +2 -3
- data/lib/rails/generators/rails/system_test/USAGE +10 -0
- data/lib/rails/generators/rails/system_test/system_test_generator.rb +7 -0
- data/lib/rails/generators/rails/task/task_generator.rb +1 -2
- data/lib/rails/generators/resource_helpers.rb +13 -10
- data/lib/rails/generators/test_case.rb +5 -6
- data/lib/rails/generators/test_unit.rb +1 -1
- data/lib/rails/generators/test_unit/controller/controller_generator.rb +3 -3
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +3 -3
- data/lib/rails/generators/test_unit/helper/helper_generator.rb +1 -1
- data/lib/rails/generators/test_unit/integration/integration_generator.rb +2 -2
- data/lib/rails/generators/test_unit/job/job_generator.rb +3 -3
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +5 -5
- data/lib/rails/generators/test_unit/model/model_generator.rb +3 -4
- data/lib/rails/generators/test_unit/plugin/plugin_generator.rb +2 -2
- data/lib/rails/generators/test_unit/scaffold/scaffold_generator.rb +3 -3
- data/lib/rails/generators/test_unit/system/system_generator.rb +17 -0
- data/lib/rails/generators/test_unit/system/templates/application_system_test_case.rb +5 -0
- data/lib/rails/generators/test_unit/system/templates/system_test.rb +9 -0
- data/lib/rails/generators/testing/assertions.rb +4 -4
- data/lib/rails/generators/testing/behaviour.rb +20 -21
- data/lib/rails/info.rb +20 -20
- data/lib/rails/info_controller.rb +15 -15
- data/lib/rails/initializable.rb +6 -2
- data/lib/rails/mailers_controller.rb +11 -11
- data/lib/rails/paths.rb +4 -5
- data/lib/rails/plugin/test.rb +7 -0
- data/lib/rails/rack/logger.rb +44 -46
- data/lib/rails/railtie.rb +41 -38
- data/lib/rails/railtie/configurable.rb +6 -6
- data/lib/rails/railtie/configuration.rb +1 -1
- data/lib/rails/ruby_version_check.rb +1 -1
- data/lib/rails/secrets.rb +111 -0
- data/lib/rails/source_annotation_extractor.rb +15 -9
- data/lib/rails/tasks.rb +3 -2
- data/lib/rails/tasks/annotations.rake +3 -3
- data/lib/rails/tasks/dev.rake +2 -2
- data/lib/rails/tasks/engine.rake +4 -4
- data/lib/rails/tasks/framework.rake +4 -18
- data/lib/rails/tasks/initializers.rake +1 -1
- data/lib/rails/tasks/log.rake +14 -10
- data/lib/rails/tasks/middleware.rake +1 -1
- data/lib/rails/tasks/misc.rake +10 -10
- data/lib/rails/tasks/restart.rake +4 -4
- data/lib/rails/tasks/routes.rake +3 -12
- data/lib/rails/tasks/statistics.rake +3 -3
- data/lib/rails/tasks/tmp.rake +7 -7
- data/lib/rails/tasks/yarn.rake +11 -0
- data/lib/rails/templates/rails/mailers/email.html.erb +4 -1
- data/lib/rails/test_help.rb +28 -10
- data/lib/rails/test_unit/line_filtering.rb +69 -3
- data/lib/rails/test_unit/minitest_plugin.rb +139 -0
- data/lib/rails/test_unit/railtie.rb +2 -1
- data/lib/rails/test_unit/reporter.rb +3 -8
- data/lib/rails/test_unit/test_requirer.rb +28 -0
- data/lib/rails/test_unit/testing.rake +19 -14
- data/lib/rails/version.rb +1 -1
- data/lib/rails/welcome_controller.rb +1 -1
- metadata +53 -30
- data/lib/minitest/rails_plugin.rb +0 -49
- data/lib/rails/commands/application.rb +0 -17
- data/lib/rails/commands/commands_tasks.rb +0 -180
- data/lib/rails/commands/console.rb +0 -68
- data/lib/rails/commands/console_helper.rb +0 -34
- data/lib/rails/commands/dbconsole.rb +0 -173
- data/lib/rails/commands/destroy.rb +0 -11
- data/lib/rails/commands/generate.rb +0 -13
- data/lib/rails/commands/plugin.rb +0 -23
- data/lib/rails/commands/rake_proxy.rb +0 -41
- data/lib/rails/commands/runner.rb +0 -71
- data/lib/rails/commands/server.rb +0 -163
- data/lib/rails/commands/test.rb +0 -10
- data/lib/rails/engine/commands_tasks.rb +0 -118
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +0 -3
- data/lib/rails/rack/debugger.rb +0 -3
- data/lib/rails/test_unit/runner.rb +0 -141
@@ -1,5 +1,5 @@
|
|
1
1
|
begin
|
2
|
-
require
|
2
|
+
require "thor/group"
|
3
3
|
rescue LoadError
|
4
4
|
puts "Thor is not available.\nIf you ran this command from a git checkout " \
|
5
5
|
"of Rails, please make sure thor is installed,\nand run this command " \
|
@@ -20,14 +20,14 @@ module Rails
|
|
20
20
|
strict_args_position!
|
21
21
|
|
22
22
|
# Returns the source root for this generator using default_source_root as default.
|
23
|
-
def self.source_root(path=nil)
|
23
|
+
def self.source_root(path = nil)
|
24
24
|
@_source_root = path if path
|
25
25
|
@_source_root ||= default_source_root
|
26
26
|
end
|
27
27
|
|
28
28
|
# Tries to get the description from a USAGE file one folder above the source
|
29
29
|
# root otherwise uses a default description.
|
30
|
-
def self.desc(description=nil)
|
30
|
+
def self.desc(description = nil)
|
31
31
|
return super if description
|
32
32
|
|
33
33
|
@desc ||= if usage_path
|
@@ -40,15 +40,15 @@ module Rails
|
|
40
40
|
# Convenience method to get the namespace from the class name. It's the
|
41
41
|
# same as Thor default except that the Generator at the end of the class
|
42
42
|
# is removed.
|
43
|
-
def self.namespace(name=nil)
|
43
|
+
def self.namespace(name = nil)
|
44
44
|
return super if name
|
45
|
-
@namespace ||= super.sub(/_generator$/,
|
45
|
+
@namespace ||= super.sub(/_generator$/, "").sub(/:generators:/, ":")
|
46
46
|
end
|
47
47
|
|
48
48
|
# Convenience method to hide this generator from the available ones when
|
49
49
|
# running rails generator command.
|
50
50
|
def self.hide!
|
51
|
-
Rails::Generators.hide_namespace
|
51
|
+
Rails::Generators.hide_namespace(namespace)
|
52
52
|
end
|
53
53
|
|
54
54
|
# Invoke a generator based on the value supplied by the user to the
|
@@ -168,7 +168,7 @@ module Rails
|
|
168
168
|
names.each do |name|
|
169
169
|
unless class_options.key?(name)
|
170
170
|
defaults = if options[:type] == :boolean
|
171
|
-
{
|
171
|
+
{}
|
172
172
|
elsif [true, false].include?(default_value_for_option(name, options))
|
173
173
|
{ banner: "" }
|
174
174
|
else
|
@@ -195,7 +195,7 @@ module Rails
|
|
195
195
|
end
|
196
196
|
|
197
197
|
# Make class option aware of Rails::Generators.options and Rails::Generators.aliases.
|
198
|
-
def self.class_option(name, options={}) #:nodoc:
|
198
|
+
def self.class_option(name, options = {}) #:nodoc:
|
199
199
|
options[:desc] = "Indicates when to generate #{name.to_s.humanize.downcase}" unless options.key?(:desc)
|
200
200
|
options[:aliases] = default_aliases_for_option(name, options)
|
201
201
|
options[:default] = default_value_for_option(name, options)
|
@@ -208,7 +208,7 @@ module Rails
|
|
208
208
|
def self.default_source_root
|
209
209
|
return unless base_name && generator_name
|
210
210
|
return unless default_generator_root
|
211
|
-
path = File.join(default_generator_root,
|
211
|
+
path = File.join(default_generator_root, "templates")
|
212
212
|
path if File.exist?(path)
|
213
213
|
end
|
214
214
|
|
@@ -230,7 +230,7 @@ module Rails
|
|
230
230
|
Rails::Generators.subclasses << base
|
231
231
|
|
232
232
|
Rails::Generators.templates_path.each do |path|
|
233
|
-
if base.name.include?(
|
233
|
+
if base.name.include?("::")
|
234
234
|
base.source_paths << File.join(path, base.base_name, base.generator_name)
|
235
235
|
else
|
236
236
|
base.source_paths << File.join(path, base.generator_name)
|
@@ -239,11 +239,11 @@ module Rails
|
|
239
239
|
end
|
240
240
|
end
|
241
241
|
|
242
|
-
|
242
|
+
private
|
243
243
|
|
244
244
|
# Check whether the given class names are already taken by user
|
245
245
|
# application or Ruby on Rails.
|
246
|
-
def class_collisions(*class_names)
|
246
|
+
def class_collisions(*class_names)
|
247
247
|
return unless behavior == :invoke
|
248
248
|
|
249
249
|
class_names.flatten.each do |class_name|
|
@@ -251,20 +251,20 @@ module Rails
|
|
251
251
|
next if class_name.strip.empty?
|
252
252
|
|
253
253
|
# Split the class from its module nesting
|
254
|
-
nesting = class_name.split(
|
254
|
+
nesting = class_name.split("::")
|
255
255
|
last_name = nesting.pop
|
256
256
|
last = extract_last_module(nesting)
|
257
257
|
|
258
258
|
if last && last.const_defined?(last_name.camelize, false)
|
259
|
-
raise Error, "The name '#{class_name}' is either already used in your application "
|
260
|
-
"or reserved by Ruby on Rails. Please choose an alternative and run "
|
259
|
+
raise Error, "The name '#{class_name}' is either already used in your application " \
|
260
|
+
"or reserved by Ruby on Rails. Please choose an alternative and run " \
|
261
261
|
"this generator again."
|
262
262
|
end
|
263
263
|
end
|
264
264
|
end
|
265
265
|
|
266
266
|
# Takes in an array of nested modules and extracts the last module
|
267
|
-
def extract_last_module(nesting)
|
267
|
+
def extract_last_module(nesting) # :doc:
|
268
268
|
nesting.inject(Object) do |last_module, nest|
|
269
269
|
break unless last_module.const_defined?(nest, false)
|
270
270
|
last_module.const_get(nest)
|
@@ -272,14 +272,14 @@ module Rails
|
|
272
272
|
end
|
273
273
|
|
274
274
|
# Use Rails default banner.
|
275
|
-
def self.banner
|
276
|
-
"rails generate #{namespace.sub(/^rails:/,'')} #{
|
275
|
+
def self.banner # :doc:
|
276
|
+
"rails generate #{namespace.sub(/^rails:/, '')} #{arguments.map(&:usage).join(' ')} [options]".gsub(/\s+/, " ")
|
277
277
|
end
|
278
278
|
|
279
279
|
# Sets the base_name taking into account the current class namespace.
|
280
|
-
def self.base_name
|
280
|
+
def self.base_name # :doc:
|
281
281
|
@base_name ||= begin
|
282
|
-
if base = name.to_s.split(
|
282
|
+
if base = name.to_s.split("::").first
|
283
283
|
base.underscore
|
284
284
|
end
|
285
285
|
end
|
@@ -287,10 +287,10 @@ module Rails
|
|
287
287
|
|
288
288
|
# Removes the namespaces and get the generator name. For example,
|
289
289
|
# Rails::Generators::ModelGenerator will return "model" as generator name.
|
290
|
-
def self.generator_name
|
290
|
+
def self.generator_name # :doc:
|
291
291
|
@generator_name ||= begin
|
292
|
-
if generator = name.to_s.split(
|
293
|
-
generator.sub!(/Generator$/,
|
292
|
+
if generator = name.to_s.split("::").last
|
293
|
+
generator.sub!(/Generator$/, "")
|
294
294
|
generator.underscore
|
295
295
|
end
|
296
296
|
end
|
@@ -298,21 +298,21 @@ module Rails
|
|
298
298
|
|
299
299
|
# Returns the default value for the option name given doing a lookup in
|
300
300
|
# Rails::Generators.options.
|
301
|
-
def self.default_value_for_option(name, options)
|
301
|
+
def self.default_value_for_option(name, options) # :doc:
|
302
302
|
default_for_option(Rails::Generators.options, name, options, options[:default])
|
303
303
|
end
|
304
304
|
|
305
305
|
# Returns default aliases for the option name given doing a lookup in
|
306
306
|
# Rails::Generators.aliases.
|
307
|
-
def self.default_aliases_for_option(name, options)
|
307
|
+
def self.default_aliases_for_option(name, options) # :doc:
|
308
308
|
default_for_option(Rails::Generators.aliases, name, options, options[:aliases])
|
309
309
|
end
|
310
310
|
|
311
311
|
# Returns default for the option name given doing a lookup in config.
|
312
|
-
def self.default_for_option(config, name, options, default)
|
313
|
-
if generator_name
|
312
|
+
def self.default_for_option(config, name, options, default) # :doc:
|
313
|
+
if generator_name && (c = config[generator_name.to_sym]) && c.key?(name)
|
314
314
|
c[name]
|
315
|
-
elsif base_name
|
315
|
+
elsif base_name && (c = config[base_name.to_sym]) && c.key?(name)
|
316
316
|
c[name]
|
317
317
|
elsif config[:rails].key?(name)
|
318
318
|
config[:rails][name]
|
@@ -331,7 +331,7 @@ module Rails
|
|
331
331
|
def self.prepare_for_invocation(name, value) #:nodoc:
|
332
332
|
return super unless value.is_a?(String) || value.is_a?(Symbol)
|
333
333
|
|
334
|
-
if value && constants =
|
334
|
+
if value && constants = hooks[name]
|
335
335
|
value = name if TrueClass === value
|
336
336
|
Rails::Generators.find_by_namespace(value, *constants)
|
337
337
|
elsif klass = Rails::Generators.find_by_namespace(value)
|
@@ -343,7 +343,7 @@ module Rails
|
|
343
343
|
|
344
344
|
# Small macro to add ruby as an option to the generator with proper
|
345
345
|
# default value plus an instance helper method called shebang.
|
346
|
-
def self.add_shebang_option!
|
346
|
+
def self.add_shebang_option! # :doc:
|
347
347
|
class_option :ruby, type: :string, aliases: "-r", default: Thor::Util.ruby_command,
|
348
348
|
desc: "Path to the Ruby binary of your choice", banner: "PATH"
|
349
349
|
|
@@ -361,7 +361,7 @@ module Rails
|
|
361
361
|
}
|
362
362
|
end
|
363
363
|
|
364
|
-
def self.usage_path
|
364
|
+
def self.usage_path # :doc:
|
365
365
|
paths = [
|
366
366
|
source_root && File.expand_path("../USAGE", source_root),
|
367
367
|
default_generator_root && File.join(default_generator_root, "USAGE")
|
@@ -369,11 +369,10 @@ module Rails
|
|
369
369
|
paths.compact.detect { |path| File.exist? path }
|
370
370
|
end
|
371
371
|
|
372
|
-
def self.default_generator_root
|
372
|
+
def self.default_generator_root # :doc:
|
373
373
|
path = File.expand_path(File.join(base_name, generator_name), base_root)
|
374
374
|
path if File.exist?(path)
|
375
375
|
end
|
376
|
-
|
377
376
|
end
|
378
377
|
end
|
379
378
|
end
|
@@ -6,7 +6,7 @@ module Css # :nodoc:
|
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
7
7
|
|
8
8
|
def copy_stylesheet
|
9
|
-
copy_file "stylesheet.css", File.join(
|
9
|
+
copy_file "stylesheet.css", File.join("app/assets/stylesheets", class_path, "#{file_name}.css")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|
data/lib/rails/generators/erb.rb
CHANGED
@@ -1,25 +1,25 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/named_base"
|
2
2
|
|
3
3
|
module Erb # :nodoc:
|
4
4
|
module Generators # :nodoc:
|
5
5
|
class Base < Rails::Generators::NamedBase #:nodoc:
|
6
|
-
|
6
|
+
private
|
7
7
|
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def formats
|
9
|
+
[format]
|
10
|
+
end
|
11
11
|
|
12
|
-
|
13
|
-
|
14
|
-
|
12
|
+
def format
|
13
|
+
:html
|
14
|
+
end
|
15
15
|
|
16
|
-
|
17
|
-
|
18
|
-
|
16
|
+
def handler
|
17
|
+
:erb
|
18
|
+
end
|
19
19
|
|
20
|
-
|
21
|
-
|
22
|
-
|
20
|
+
def filename_with_extensions(name, format = self.format)
|
21
|
+
[name, format, handler].compact.join(".")
|
22
|
+
end
|
23
23
|
end
|
24
24
|
end
|
25
25
|
end
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "rails/generators/erb"
|
2
2
|
|
3
3
|
module Erb # :nodoc:
|
4
4
|
module Generators # :nodoc:
|
@@ -6,13 +6,13 @@ module Erb # :nodoc:
|
|
6
6
|
argument :actions, type: :array, default: [], banner: "method method"
|
7
7
|
|
8
8
|
def copy_view_files
|
9
|
-
view_base_path = File.join("app/views", class_path, file_name +
|
9
|
+
view_base_path = File.join("app/views", class_path, file_name + "_mailer")
|
10
10
|
empty_directory view_base_path
|
11
11
|
|
12
|
-
if
|
12
|
+
if behavior == :invoke
|
13
13
|
formats.each do |format|
|
14
|
-
layout_path = File.join(
|
15
|
-
template filename_with_extensions(:layout, format), layout_path
|
14
|
+
layout_path = File.join("app/views/layouts", class_path, filename_with_extensions("mailer", format))
|
15
|
+
template filename_with_extensions(:layout, format), layout_path unless File.exist?(layout_path)
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
@@ -26,15 +26,15 @@ module Erb # :nodoc:
|
|
26
26
|
end
|
27
27
|
end
|
28
28
|
|
29
|
-
|
29
|
+
private
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
31
|
+
def formats
|
32
|
+
[:text, :html]
|
33
|
+
end
|
34
34
|
|
35
|
-
|
36
|
-
|
37
|
-
|
35
|
+
def file_name
|
36
|
+
@_file_name ||= super.gsub(/_mailer/i, "")
|
37
|
+
end
|
38
38
|
end
|
39
39
|
end
|
40
40
|
end
|
@@ -1,5 +1,5 @@
|
|
1
|
-
require
|
2
|
-
require
|
1
|
+
require "rails/generators/erb"
|
2
|
+
require "rails/generators/resource_helpers"
|
3
3
|
|
4
4
|
module Erb # :nodoc:
|
5
5
|
module Generators # :nodoc:
|
@@ -21,7 +21,7 @@ module Erb # :nodoc:
|
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
|
-
|
24
|
+
private
|
25
25
|
|
26
26
|
def available_views
|
27
27
|
%w(index edit show new _form)
|
@@ -1,4 +1,4 @@
|
|
1
|
-
require
|
1
|
+
require "active_support/time"
|
2
2
|
|
3
3
|
module Rails
|
4
4
|
module Generators
|
@@ -12,7 +12,7 @@ module Rails
|
|
12
12
|
|
13
13
|
class << self
|
14
14
|
def parse(column_definition)
|
15
|
-
name, type, has_index = column_definition.split(
|
15
|
+
name, type, has_index = column_definition.split(":")
|
16
16
|
|
17
17
|
# if user provided "name:index" instead of "name:string:index"
|
18
18
|
# type should be set blank so GeneratedAttribute's constructor
|
@@ -56,7 +56,7 @@ module Rails
|
|
56
56
|
end
|
57
57
|
end
|
58
58
|
|
59
|
-
def initialize(name, type=nil, index_type=false, attr_options={})
|
59
|
+
def initialize(name, type = nil, index_type = false, attr_options = {})
|
60
60
|
@name = name
|
61
61
|
@type = type || :string
|
62
62
|
@has_index = INDEX_OPTIONS.include?(index_type)
|
@@ -66,40 +66,40 @@ module Rails
|
|
66
66
|
|
67
67
|
def field_type
|
68
68
|
@field_type ||= case type
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
69
|
+
when :integer then :number_field
|
70
|
+
when :float, :decimal then :text_field
|
71
|
+
when :time then :time_select
|
72
|
+
when :datetime, :timestamp then :datetime_select
|
73
|
+
when :date then :date_select
|
74
|
+
when :text then :text_area
|
75
|
+
when :boolean then :check_box
|
76
76
|
else
|
77
|
-
|
77
|
+
:text_field
|
78
78
|
end
|
79
79
|
end
|
80
80
|
|
81
81
|
def default
|
82
82
|
@default ||= case type
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
83
|
+
when :integer then 1
|
84
|
+
when :float then 1.5
|
85
|
+
when :decimal then "9.99"
|
86
|
+
when :datetime, :timestamp, :time then Time.now.to_s(:db)
|
87
|
+
when :date then Date.today.to_s(:db)
|
88
|
+
when :string then name == "type" ? "" : "MyString"
|
89
|
+
when :text then "MyText"
|
90
|
+
when :boolean then false
|
91
|
+
when :references, :belongs_to then nil
|
92
92
|
else
|
93
|
-
|
93
|
+
""
|
94
94
|
end
|
95
95
|
end
|
96
96
|
|
97
97
|
def plural_name
|
98
|
-
name.sub(/_id$/,
|
98
|
+
name.sub(/_id$/, "").pluralize
|
99
99
|
end
|
100
100
|
|
101
101
|
def singular_name
|
102
|
-
name.sub(/_id$/,
|
102
|
+
name.sub(/_id$/, "").singularize
|
103
103
|
end
|
104
104
|
|
105
105
|
def human_name
|
@@ -127,11 +127,11 @@ module Rails
|
|
127
127
|
end
|
128
128
|
|
129
129
|
def polymorphic?
|
130
|
-
|
130
|
+
attr_options[:polymorphic]
|
131
131
|
end
|
132
132
|
|
133
133
|
def required?
|
134
|
-
|
134
|
+
attr_options[:required]
|
135
135
|
end
|
136
136
|
|
137
137
|
def has_index?
|
@@ -143,7 +143,7 @@ module Rails
|
|
143
143
|
end
|
144
144
|
|
145
145
|
def password_digest?
|
146
|
-
name ==
|
146
|
+
name == "password" && type == :digest
|
147
147
|
end
|
148
148
|
|
149
149
|
def token?
|
@@ -151,7 +151,7 @@ module Rails
|
|
151
151
|
end
|
152
152
|
|
153
153
|
def inject_options
|
154
|
-
"".tap { |s| options_for_migration.each { |k,v| s << ", #{k}: #{v.inspect}" } }
|
154
|
+
"".tap { |s| options_for_migration.each { |k, v| s << ", #{k}: #{v.inspect}" } }
|
155
155
|
end
|
156
156
|
|
157
157
|
def inject_index_options
|
@@ -6,7 +6,7 @@ module Js # :nodoc:
|
|
6
6
|
source_root File.expand_path("../templates", __FILE__)
|
7
7
|
|
8
8
|
def copy_javascript
|
9
|
-
copy_file "javascript.js", File.join(
|
9
|
+
copy_file "javascript.js", File.join("app/assets/javascripts", class_path, "#{file_name}.js")
|
10
10
|
end
|
11
11
|
end
|
12
12
|
end
|