railties 4.0.13 → 4.1.0.beta1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +155 -385
- data/README.rdoc +1 -1
- data/bin/rails +1 -1
- data/lib/rails.rb +11 -13
- data/lib/rails/all.rb +1 -0
- data/lib/rails/api/task.rb +9 -12
- data/lib/rails/app_rails_loader.rb +2 -2
- data/lib/rails/application.rb +154 -149
- data/lib/rails/application/configuration.rb +1 -14
- data/lib/rails/application/default_middleware_stack.rb +99 -0
- data/lib/rails/application/finisher.rb +2 -0
- data/lib/rails/application_controller.rb +16 -0
- data/lib/rails/cli.rb +1 -2
- data/lib/rails/commands.rb +2 -94
- data/lib/rails/commands/application.rb +2 -28
- data/lib/rails/commands/commands_tasks.rb +174 -0
- data/lib/rails/commands/console.rb +2 -2
- data/lib/rails/commands/dbconsole.rb +1 -1
- data/lib/rails/commands/plugin.rb +23 -0
- data/lib/rails/commands/runner.rb +1 -1
- data/lib/rails/commands/server.rb +46 -30
- data/lib/rails/configuration.rb +4 -1
- data/lib/rails/console/helpers.rb +6 -0
- data/lib/rails/engine.rb +29 -18
- data/lib/rails/engine/commands.rb +1 -1
- data/lib/rails/engine/railties.rb +0 -8
- data/lib/rails/generators.rb +4 -3
- data/lib/rails/generators/actions.rb +1 -1
- data/lib/rails/generators/active_model.rb +0 -8
- data/lib/rails/generators/app_base.rb +213 -74
- data/lib/rails/generators/base.rb +17 -16
- data/lib/rails/generators/erb/scaffold/templates/_form.html.erb +1 -1
- data/lib/rails/generators/erb/scaffold/templates/index.html.erb +1 -3
- data/lib/rails/generators/migration.rb +18 -26
- data/lib/rails/generators/named_base.rb +4 -7
- data/lib/rails/generators/rails/app/app_generator.rb +91 -5
- data/lib/rails/generators/rails/app/templates/Gemfile +20 -15
- data/lib/rails/generators/rails/app/templates/Rakefile +1 -1
- data/lib/rails/generators/rails/app/templates/app/assets/javascripts/application.js.tt +2 -0
- data/lib/rails/generators/rails/app/templates/app/assets/stylesheets/application.css +5 -3
- data/lib/rails/generators/rails/app/templates/app/views/layouts/application.html.erb.tt +5 -1
- data/lib/rails/generators/rails/app/templates/config/application.rb +2 -0
- data/lib/rails/generators/rails/app/templates/config/databases/frontbase.yml +7 -10
- data/lib/rails/generators/rails/app/templates/config/databases/ibm_db.yml +11 -31
- data/lib/rails/generators/rails/app/templates/config/databases/jdbc.yml +25 -29
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcmysql.yml +8 -10
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcpostgresql.yml +8 -11
- data/lib/rails/generators/rails/app/templates/config/databases/jdbcsqlite3.yml +6 -3
- data/lib/rails/generators/rails/app/templates/config/databases/mysql.yml +8 -22
- data/lib/rails/generators/rails/app/templates/config/databases/oracle.yml +7 -9
- data/lib/rails/generators/rails/app/templates/config/databases/postgresql.yml +9 -12
- data/lib/rails/generators/rails/app/templates/config/databases/sqlite3.yml +8 -8
- data/lib/rails/generators/rails/app/templates/config/databases/sqlserver.yml +7 -17
- data/lib/rails/generators/rails/app/templates/config/environment.rb +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/development.rb.tt +2 -5
- data/lib/rails/generators/rails/app/templates/config/environments/production.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/environments/test.rb.tt +1 -4
- data/lib/rails/generators/rails/app/templates/config/initializers/session_store.rb.tt +1 -1
- data/lib/rails/generators/rails/app/templates/config/routes.rb +1 -1
- data/lib/rails/generators/rails/app/templates/config/{initializers/secret_token.rb.tt → secrets.yml} +10 -2
- data/lib/rails/generators/rails/app/templates/public/404.html +20 -11
- data/lib/rails/generators/rails/app/templates/public/422.html +20 -11
- data/lib/rails/generators/rails/app/templates/public/500.html +19 -10
- data/lib/rails/generators/rails/controller/USAGE +1 -0
- data/lib/rails/generators/rails/controller/controller_generator.rb +35 -1
- data/lib/rails/generators/rails/generator/USAGE +1 -0
- data/lib/rails/generators/rails/generator/generator_generator.rb +2 -0
- data/lib/rails/generators/rails/model/USAGE +5 -5
- data/lib/rails/generators/rails/{plugin_new → plugin}/USAGE +0 -0
- data/lib/rails/generators/rails/{plugin_new/plugin_new_generator.rb → plugin/plugin_generator.rb} +10 -4
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/%name%.gemspec +1 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Gemfile +16 -1
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/MIT-LICENSE +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/README.rdoc +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/Rakefile +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/controllers/%name%/application_controller.rb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/helpers/%name%/application_helper.rb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/mailers/.empty_directory +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/models/.empty_directory +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/views/layouts/%name%/application.html.erb.tt +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/bin/rails.tt +0 -4
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/config/routes.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/gitignore +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/engine.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/%name%/version.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/lib/tasks/%name%_tasks.rake +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/application.rb +1 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/boot.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/javascripts.js +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/routes.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/rails/stylesheets.css +5 -3
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/%name%_test.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/integration/navigation_test.rb +0 -0
- data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/test_helper.rb +0 -0
- data/lib/rails/generators/rails/scaffold_controller/scaffold_controller_generator.rb +1 -1
- data/lib/rails/generators/rails/scaffold_controller/templates/controller.rb +2 -2
- data/lib/rails/generators/resource_helpers.rb +20 -5
- data/lib/rails/generators/test_unit/generator/generator_generator.rb +26 -0
- data/lib/rails/generators/test_unit/generator/templates/generator_test.rb +16 -0
- data/lib/rails/generators/test_unit/mailer/mailer_generator.rb +8 -1
- data/lib/rails/generators/test_unit/mailer/templates/preview.rb +11 -0
- data/lib/rails/generators/testing/assertions.rb +1 -1
- data/lib/rails/generators/testing/behaviour.rb +3 -13
- data/lib/rails/info.rb +5 -3
- data/lib/rails/info_controller.rb +5 -15
- data/lib/rails/mailers_controller.rb +73 -0
- data/lib/rails/paths.rb +13 -18
- data/lib/rails/rack/debugger.rb +2 -2
- data/lib/rails/rack/logger.rb +1 -1
- data/lib/rails/railtie.rb +38 -2
- data/lib/rails/source_annotation_extractor.rb +2 -2
- data/lib/rails/tasks.rb +0 -2
- data/lib/rails/tasks/documentation.rake +0 -5
- data/lib/rails/tasks/engine.rake +1 -1
- data/lib/rails/tasks/framework.rake +2 -12
- data/lib/rails/templates/layouts/application.html.erb +2 -2
- data/lib/rails/templates/rails/mailers/email.html.erb +98 -0
- data/lib/rails/templates/rails/mailers/index.html.erb +8 -0
- data/lib/rails/templates/rails/mailers/mailer.html.erb +6 -0
- data/lib/rails/test_help.rb +4 -1
- data/lib/rails/test_unit/sub_test_task.rb +44 -3
- data/lib/rails/test_unit/testing.rake +9 -111
- data/lib/rails/version.rb +3 -3
- data/lib/rails/welcome_controller.rb +4 -3
- metadata +99 -76
- data/lib/rails/commands/plugin_new.rb +0 -9
- data/lib/rails/generators/actions/create_migration.rb +0 -68
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
data/lib/rails/generators/rails/{plugin_new → plugin}/templates/app/mailers/.empty_directory
RENAMED
File without changes
|
File without changes
|
File without changes
|
@@ -3,9 +3,5 @@
|
|
3
3
|
ENGINE_ROOT = File.expand_path('../..', __FILE__)
|
4
4
|
ENGINE_PATH = File.expand_path('../../lib/<%= name -%>/engine', __FILE__)
|
5
5
|
|
6
|
-
# Set up gems listed in the Gemfile.
|
7
|
-
ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
|
8
|
-
require 'bundler/setup' if File.exist?(ENV['BUNDLE_GEMFILE'])
|
9
|
-
|
10
6
|
require 'rails/all'
|
11
7
|
require 'rails/engine/commands'
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -7,6 +7,7 @@ require 'rails/all'
|
|
7
7
|
<%= comment_if :skip_active_record %>require "active_record/railtie"
|
8
8
|
require "action_controller/railtie"
|
9
9
|
require "action_mailer/railtie"
|
10
|
+
<%= comment_if :skip_action_view %>require "action_view/railtie"
|
10
11
|
<%= comment_if :skip_sprockets %>require "sprockets/railtie"
|
11
12
|
<%= comment_if :skip_test_unit %>require "rails/test_unit/railtie"
|
12
13
|
<% end -%>
|
File without changes
|
File without changes
|
File without changes
|
@@ -5,9 +5,11 @@
|
|
5
5
|
* Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets,
|
6
6
|
* or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path.
|
7
7
|
*
|
8
|
-
* You're free to add application-wide styles to this file and they'll appear at the
|
9
|
-
* compiled file
|
8
|
+
* You're free to add application-wide styles to this file and they'll appear at the bottom of the
|
9
|
+
* compiled file so the styles you add here take precedence over styles defined in any styles
|
10
|
+
* defined in the other CSS/SCSS files in this directory. It is generally better to create a new
|
11
|
+
* file per style scope.
|
10
12
|
*
|
11
|
-
*= require_self
|
12
13
|
*= require_tree .
|
14
|
+
*= require_self
|
13
15
|
*/
|
File without changes
|
data/lib/rails/generators/rails/{plugin_new → plugin}/templates/test/integration/navigation_test.rb
RENAMED
File without changes
|
File without changes
|
@@ -13,7 +13,7 @@ module Rails
|
|
13
13
|
argument :attributes, type: :array, default: [], banner: "field:type field:type"
|
14
14
|
|
15
15
|
def create_controller_files
|
16
|
-
template "controller.rb", File.join('app/controllers',
|
16
|
+
template "controller.rb", File.join('app/controllers', controller_class_path, "#{controller_file_name}_controller.rb")
|
17
17
|
end
|
18
18
|
|
19
19
|
hook_for :template_engine, :test_framework, as: :scaffold
|
@@ -59,9 +59,9 @@ class <%= controller_class_name %>Controller < ApplicationController
|
|
59
59
|
# Only allow a trusted parameter "white list" through.
|
60
60
|
def <%= "#{singular_table_name}_params" %>
|
61
61
|
<%- if attributes_names.empty? -%>
|
62
|
-
params[
|
62
|
+
params[:<%= singular_table_name %>]
|
63
63
|
<%- else -%>
|
64
|
-
params.require(
|
64
|
+
params.require(:<%= singular_table_name %>).permit(<%= attributes_names.map { |name| ":#{name}" }.join(', ') %>)
|
65
65
|
<%- end -%>
|
66
66
|
end
|
67
67
|
end
|
@@ -9,11 +9,19 @@ module Rails
|
|
9
9
|
|
10
10
|
def self.included(base) #:nodoc:
|
11
11
|
base.class_option :force_plural, type: :boolean, desc: "Forces the use of a plural ModelName"
|
12
|
+
base.class_option :model_name, type: :string, desc: "ModelName to be used"
|
12
13
|
end
|
13
14
|
|
14
15
|
# Set controller variables on initialization.
|
15
16
|
def initialize(*args) #:nodoc:
|
16
17
|
super
|
18
|
+
if options[:model_name]
|
19
|
+
controller_name = name
|
20
|
+
self.name = options[:model_name]
|
21
|
+
assign_names!(self.name)
|
22
|
+
else
|
23
|
+
controller_name = name
|
24
|
+
end
|
17
25
|
|
18
26
|
if name == name.pluralize && name.singularize != name.pluralize && !options[:force_plural]
|
19
27
|
unless ResourceHelpers.skip_warn
|
@@ -24,19 +32,26 @@ module Rails
|
|
24
32
|
assign_names!(name)
|
25
33
|
end
|
26
34
|
|
27
|
-
|
35
|
+
assign_controller_names!(controller_name.pluralize)
|
28
36
|
end
|
29
37
|
|
30
38
|
protected
|
31
39
|
|
32
|
-
attr_reader :controller_name
|
40
|
+
attr_reader :controller_name, :controller_file_name
|
33
41
|
|
34
42
|
def controller_class_path
|
35
|
-
|
43
|
+
if options[:model_name]
|
44
|
+
@controller_class_path
|
45
|
+
else
|
46
|
+
class_path
|
47
|
+
end
|
36
48
|
end
|
37
49
|
|
38
|
-
def
|
39
|
-
@
|
50
|
+
def assign_controller_names!(name)
|
51
|
+
@controller_name = name
|
52
|
+
@controller_class_path = name.include?('/') ? name.split('/') : name.split('::')
|
53
|
+
@controller_class_path.map! { |m| m.underscore }
|
54
|
+
@controller_file_name = @controller_class_path.pop
|
40
55
|
end
|
41
56
|
|
42
57
|
def controller_file_path
|
@@ -0,0 +1,26 @@
|
|
1
|
+
require 'rails/generators/test_unit'
|
2
|
+
|
3
|
+
module TestUnit # :nodoc:
|
4
|
+
module Generators # :nodoc:
|
5
|
+
class GeneratorGenerator < Base # :nodoc:
|
6
|
+
check_class_collision suffix: "GeneratorTest"
|
7
|
+
|
8
|
+
class_option :namespace, type: :boolean, default: true,
|
9
|
+
desc: "Namespace generator under lib/generators/name"
|
10
|
+
|
11
|
+
def create_generator_files
|
12
|
+
template 'generator_test.rb', File.join('test/lib/generators', class_path, "#{file_name}_generator_test.rb")
|
13
|
+
end
|
14
|
+
|
15
|
+
protected
|
16
|
+
|
17
|
+
def generator_path
|
18
|
+
if options[:namespace]
|
19
|
+
File.join("generators", regular_class_path, file_name, "#{file_name}_generator")
|
20
|
+
else
|
21
|
+
File.join("generators", regular_class_path, "#{file_name}_generator")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
require 'test_helper'
|
2
|
+
require '<%= generator_path %>'
|
3
|
+
|
4
|
+
<% module_namespacing do -%>
|
5
|
+
class <%= class_name %>GeneratorTest < Rails::Generators::TestCase
|
6
|
+
tests <%= class_name %>Generator
|
7
|
+
destination Rails.root.join('tmp/generators')
|
8
|
+
setup :prepare_destination
|
9
|
+
|
10
|
+
# test "generator runs without errors" do
|
11
|
+
# assert_nothing_raised do
|
12
|
+
# run_generator ["arguments"]
|
13
|
+
# end
|
14
|
+
# end
|
15
|
+
end
|
16
|
+
<% end -%>
|
@@ -4,11 +4,18 @@ module TestUnit # :nodoc:
|
|
4
4
|
module Generators # :nodoc:
|
5
5
|
class MailerGenerator < Base # :nodoc:
|
6
6
|
argument :actions, type: :array, default: [], banner: "method method"
|
7
|
-
|
7
|
+
|
8
|
+
def check_class_collision
|
9
|
+
class_collisions "#{class_name}Test", "#{class_name}Preview"
|
10
|
+
end
|
8
11
|
|
9
12
|
def create_test_files
|
10
13
|
template "functional_test.rb", File.join('test/mailers', class_path, "#{file_name}_test.rb")
|
11
14
|
end
|
15
|
+
|
16
|
+
def create_preview_files
|
17
|
+
template "preview.rb", File.join('test/mailers/previews', class_path, "#{file_name}_preview.rb")
|
18
|
+
end
|
12
19
|
end
|
13
20
|
end
|
14
21
|
end
|
@@ -21,7 +21,7 @@ module Rails
|
|
21
21
|
# end
|
22
22
|
# end
|
23
23
|
def assert_file(relative, *contents)
|
24
|
-
absolute = File.expand_path(relative, destination_root)
|
24
|
+
absolute = File.expand_path(relative, destination_root).shellescape
|
25
25
|
assert File.exist?(absolute), "Expected file #{relative.inspect} to exist, but does not"
|
26
26
|
|
27
27
|
read = File.read(absolute) if block_given? || !contents.empty?
|
@@ -61,11 +61,9 @@ module Rails
|
|
61
61
|
# You can provide a configuration hash as second argument. This method returns the output
|
62
62
|
# printed by the generator.
|
63
63
|
def run_generator(args=self.default_arguments, config={})
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
self.generator_class.start(args, config.reverse_merge(destination_root: destination_root))
|
68
|
-
end
|
64
|
+
capture(:stdout) do
|
65
|
+
args += ['--skip-bundle'] unless args.include? '--dev'
|
66
|
+
self.generator_class.start(args, config.reverse_merge(destination_root: destination_root))
|
69
67
|
end
|
70
68
|
end
|
71
69
|
|
@@ -102,14 +100,6 @@ module Rails
|
|
102
100
|
dirname, file_name = File.dirname(absolute), File.basename(absolute).sub(/\.rb$/, '')
|
103
101
|
Dir.glob("#{dirname}/[0-9]*_*.rb").grep(/\d+_#{file_name}.rb$/).first
|
104
102
|
end
|
105
|
-
|
106
|
-
# TODO: remove this once Bundler 1.5.2 is released
|
107
|
-
def without_thor_debug # :nodoc:
|
108
|
-
thor_debug, ENV['THOR_DEBUG'] = ENV['THOR_DEBUG'], nil
|
109
|
-
yield
|
110
|
-
ensure
|
111
|
-
ENV['THOR_DEBUG'] = thor_debug
|
112
|
-
end
|
113
103
|
end
|
114
104
|
end
|
115
105
|
end
|
data/lib/rails/info.rb
CHANGED
@@ -23,7 +23,7 @@ module Rails
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def frameworks
|
26
|
-
%w( active_record action_pack action_mailer active_support )
|
26
|
+
%w( active_record action_pack action_view action_mailer active_support )
|
27
27
|
end
|
28
28
|
|
29
29
|
def framework_version(framework)
|
@@ -61,8 +61,10 @@ module Rails
|
|
61
61
|
end
|
62
62
|
end
|
63
63
|
|
64
|
-
# The Ruby version and platform, e.g. "
|
65
|
-
property 'Ruby version'
|
64
|
+
# The Ruby version and platform, e.g. "2.0.0-p247 (x86_64-darwin12.4.0)".
|
65
|
+
property 'Ruby version' do
|
66
|
+
"#{RUBY_VERSION}-p#{RUBY_PATCHLEVEL} (#{RUBY_PLATFORM})"
|
67
|
+
end
|
66
68
|
|
67
69
|
# The RubyGems version, if it's installed.
|
68
70
|
property 'RubyGems version' do
|
@@ -1,9 +1,9 @@
|
|
1
|
+
require 'rails/application_controller'
|
1
2
|
require 'action_dispatch/routing/inspector'
|
2
3
|
|
3
|
-
class Rails::InfoController <
|
4
|
-
self.view_paths = File.expand_path('../templates', __FILE__)
|
4
|
+
class Rails::InfoController < Rails::ApplicationController # :nodoc:
|
5
5
|
prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
|
6
|
-
layout -> { request.xhr? ?
|
6
|
+
layout -> { request.xhr? ? false : 'application' }
|
7
7
|
|
8
8
|
before_filter :require_local!
|
9
9
|
|
@@ -13,21 +13,11 @@ class Rails::InfoController < ActionController::Base # :nodoc:
|
|
13
13
|
|
14
14
|
def properties
|
15
15
|
@info = Rails::Info.to_html
|
16
|
+
@page_title = 'Properties'
|
16
17
|
end
|
17
18
|
|
18
19
|
def routes
|
19
20
|
@routes_inspector = ActionDispatch::Routing::RoutesInspector.new(_routes.routes)
|
20
|
-
|
21
|
-
|
22
|
-
protected
|
23
|
-
|
24
|
-
def require_local!
|
25
|
-
unless local_request?
|
26
|
-
render text: '<p>For security purposes, this information is only available to local requests.</p>', status: :forbidden
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
def local_request?
|
31
|
-
Rails.application.config.consider_all_requests_local || request.local?
|
21
|
+
@page_title = 'Routes'
|
32
22
|
end
|
33
23
|
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
require 'rails/application_controller'
|
2
|
+
|
3
|
+
class Rails::MailersController < Rails::ApplicationController # :nodoc:
|
4
|
+
prepend_view_path ActionDispatch::DebugExceptions::RESCUES_TEMPLATE_PATH
|
5
|
+
|
6
|
+
before_filter :require_local!
|
7
|
+
before_filter :find_preview, only: :preview
|
8
|
+
|
9
|
+
def index
|
10
|
+
@previews = ActionMailer::Preview.all
|
11
|
+
@page_title = "Mailer Previews"
|
12
|
+
end
|
13
|
+
|
14
|
+
def preview
|
15
|
+
if params[:path] == @preview.preview_name
|
16
|
+
@page_title = "Mailer Previews for #{@preview.preview_name}"
|
17
|
+
render action: 'mailer'
|
18
|
+
else
|
19
|
+
email = File.basename(params[:path])
|
20
|
+
|
21
|
+
if @preview.email_exists?(email)
|
22
|
+
@email = @preview.call(email)
|
23
|
+
|
24
|
+
if params[:part]
|
25
|
+
part_type = Mime::Type.lookup(params[:part])
|
26
|
+
|
27
|
+
if part = find_part(part_type)
|
28
|
+
response.content_type = part_type
|
29
|
+
render text: part.respond_to?(:decoded) ? part.decoded : part
|
30
|
+
else
|
31
|
+
raise AbstractController::ActionNotFound, "Email part '#{part_type}' not found in #{@preview.name}##{email}"
|
32
|
+
end
|
33
|
+
else
|
34
|
+
@part = find_preferred_part(request.format, Mime::HTML, Mime::TEXT)
|
35
|
+
render action: 'email', layout: false, formats: %w[html]
|
36
|
+
end
|
37
|
+
else
|
38
|
+
raise AbstractController::ActionNotFound, "Email '#{email}' not found in #{@preview.name}"
|
39
|
+
end
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
protected
|
44
|
+
def find_preview
|
45
|
+
candidates = []
|
46
|
+
params[:path].to_s.scan(%r{/|$}){ candidates << $` }
|
47
|
+
preview = candidates.detect{ |candidate| ActionMailer::Preview.exists?(candidate) }
|
48
|
+
|
49
|
+
if preview
|
50
|
+
@preview = ActionMailer::Preview.find(preview)
|
51
|
+
else
|
52
|
+
raise AbstractController::ActionNotFound, "Mailer preview '#{params[:path]}' not found"
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
56
|
+
def find_preferred_part(*formats)
|
57
|
+
if @email.multipart?
|
58
|
+
formats.each do |format|
|
59
|
+
return find_part(format) if @email.parts.any?{ |p| p.mime_type == format }
|
60
|
+
end
|
61
|
+
else
|
62
|
+
@email
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
def find_part(format)
|
67
|
+
if @email.multipart?
|
68
|
+
@email.parts.find{ |p| p.mime_type == format }
|
69
|
+
elsif @email.mime_type == format
|
70
|
+
@email
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
data/lib/rails/paths.rb
CHANGED
@@ -81,34 +81,28 @@ module Rails
|
|
81
81
|
end
|
82
82
|
|
83
83
|
def autoload_once
|
84
|
-
filter_by
|
84
|
+
filter_by { |p| p.autoload_once? }
|
85
85
|
end
|
86
86
|
|
87
87
|
def eager_load
|
88
|
-
filter_by
|
88
|
+
filter_by { |p| p.eager_load? }
|
89
89
|
end
|
90
90
|
|
91
91
|
def autoload_paths
|
92
|
-
filter_by
|
92
|
+
filter_by { |p| p.autoload? }
|
93
93
|
end
|
94
94
|
|
95
95
|
def load_paths
|
96
|
-
filter_by
|
96
|
+
filter_by { |p| p.load_path? }
|
97
97
|
end
|
98
98
|
|
99
|
-
|
99
|
+
private
|
100
100
|
|
101
|
-
def filter_by(
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
paths -= path.children.map { |p| p.send(constraint) ? [] : p.existent }.flatten
|
107
|
-
all.concat(paths)
|
108
|
-
end
|
109
|
-
end
|
110
|
-
all.uniq!
|
111
|
-
all
|
101
|
+
def filter_by(&block)
|
102
|
+
all_paths.find_all(&block).flat_map { |path|
|
103
|
+
paths = path.existent
|
104
|
+
paths - path.children.map { |p| yield(p) ? [] : p.existent }.flatten
|
105
|
+
}.uniq
|
112
106
|
end
|
113
107
|
end
|
114
108
|
|
@@ -130,8 +124,9 @@ module Rails
|
|
130
124
|
end
|
131
125
|
|
132
126
|
def children
|
133
|
-
keys = @root.keys.
|
134
|
-
|
127
|
+
keys = @root.keys.find_all { |k|
|
128
|
+
k.start_with?(@current) && k != @current
|
129
|
+
}
|
135
130
|
@root.values_at(*keys.sort)
|
136
131
|
end
|
137
132
|
|