Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
4d3eb70a
R
rails
项目概览
张重言
/
rails
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
rails
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
4d3eb70a
编写于
7月 01, 2014
作者:
R
Rafael Mendonça França
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #15970 from lengarvey/add_configuration_option_for_mail_preview
Add configuration to enable mail previews
上级
5de61ccb
84ed7b8d
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
80 addition
and
3 deletion
+80
-3
actionmailer/CHANGELOG.md
actionmailer/CHANGELOG.md
+9
-0
actionmailer/lib/action_mailer/preview.rb
actionmailer/lib/action_mailer/preview.rb
+12
-0
actionmailer/lib/action_mailer/railtie.rb
actionmailer/lib/action_mailer/railtie.rb
+9
-1
guides/source/configuring.md
guides/source/configuring.md
+12
-0
railties/lib/rails/application/finisher.rb
railties/lib/rails/application/finisher.rb
+0
-2
railties/test/application/configuration_test.rb
railties/test/application/configuration_test.rb
+24
-0
railties/test/application/mailer_previews_test.rb
railties/test/application/mailer_previews_test.rb
+14
-0
未找到文件。
actionmailer/CHANGELOG.md
浏览文件 @
4d3eb70a
*
Add
`config.action_mailer.preview_enabled`
configuration option.
This config option can be used to enable the mail preview in environments
other than development (such as staging).
Defaults to `true` in development and false elsewhere.
*Leonard Garvey*
*
Allow preview interceptors to be registered through
`config.action_mailer.preview_interceptors`
.
...
...
actionmailer/lib/action_mailer/preview.rb
浏览文件 @
4d3eb70a
...
...
@@ -11,6 +11,14 @@ module Previews #:nodoc:
#
mattr_accessor
:preview_path
,
instance_writer:
false
# Enable or disable mailer previews through app configuration:
#
# config.action_mailer.preview_enabled = true
#
# Defaults to true for development environment
#
mattr_accessor
:preview_enabled
,
instance_writer:
false
# :nodoc:
mattr_accessor
:preview_interceptors
,
instance_writer:
false
self
.
preview_interceptors
=
[]
...
...
@@ -94,6 +102,10 @@ def preview_path #:nodoc:
Base
.
preview_path
end
def
preview_enabled
#:nodoc:
Base
.
preview_enabled
end
def
inform_preview_interceptors
(
message
)
#:nodoc:
Base
.
preview_interceptors
.
each
do
|
interceptor
|
interceptor
.
previewing_email
(
message
)
...
...
actionmailer/lib/action_mailer/railtie.rb
浏览文件 @
4d3eb70a
...
...
@@ -18,8 +18,9 @@ class Railtie < Rails::Railtie # :nodoc:
options
.
assets_dir
||=
paths
[
"public"
].
first
options
.
javascripts_dir
||=
paths
[
"public/javascripts"
].
first
options
.
stylesheets_dir
||=
paths
[
"public/stylesheets"
].
first
options
.
preview_enabled
=
Rails
.
env
.
development?
if
options
.
preview_enabled
.
nil?
if
Rails
.
env
.
development?
if
options
.
preview_enabled
options
.
preview_path
||=
defined?
(
Rails
.
root
)
?
"
#{
Rails
.
root
}
/test/mailers/previews"
:
nil
end
...
...
@@ -37,6 +38,13 @@ class Railtie < Rails::Railtie # :nodoc:
register_observers
(
options
.
delete
(
:observers
))
options
.
each
{
|
k
,
v
|
send
(
"
#{
k
}
="
,
v
)
}
if
options
.
preview_enabled
app
.
routes
.
append
do
get
'/rails/mailers'
=>
"rails/mailers#index"
get
'/rails/mailers/*path'
=>
"rails/mailers#preview"
end
end
end
end
...
...
guides/source/configuring.md
浏览文件 @
4d3eb70a
...
...
@@ -453,6 +453,18 @@ There are a number of settings available on `config.action_mailer`:
config.action_mailer.interceptors = ["MailInterceptor"]
```
*
`config.action_mailer.preview_path`
specifies the location of mailer previews.
```ruby
config.action_mailer.preview_path = "#{Rails.root}/lib/mailer_previews"
```
*
`config.action_mailer.preview_enabled`
enable or disable mailer previews. By default this is
`true`
in development.
```ruby
config.action_mailer.preview_enabled = false
```
### Configuring Active Support
There are a few configuration options available in Active Support:
...
...
railties/lib/rails/application/finisher.rb
浏览文件 @
4d3eb70a
...
...
@@ -22,8 +22,6 @@ module Finisher
initializer
:add_builtin_route
do
|
app
|
if
Rails
.
env
.
development?
app
.
routes
.
append
do
get
'/rails/mailers'
=>
"rails/mailers#index"
get
'/rails/mailers/*path'
=>
"rails/mailers#preview"
get
'/rails/info/properties'
=>
"rails/info#properties"
get
'/rails/info/routes'
=>
"rails/info#routes"
get
'/rails/info'
=>
"rails/info#index"
...
...
railties/test/application/configuration_test.rb
浏览文件 @
4d3eb70a
...
...
@@ -965,5 +965,29 @@ def index
assert
db_config
.
is_a?
(
Hash
)
end
test
'config.mail_preview_enabled defaults to true in development'
do
Rails
.
env
=
"development"
require
"
#{
app_path
}
/config/environment"
assert
Rails
.
application
.
config
.
action_mailer
.
preview_enabled
end
test
'config.mail_preview_enabled defaults to false in production'
do
Rails
.
env
=
"production"
require
"
#{
app_path
}
/config/environment"
assert_equal
Rails
.
application
.
config
.
action_mailer
.
preview_enabled
,
false
end
test
'config.mail_preview_enabled can be set in the configuration file'
do
Rails
.
env
=
"production"
add_to_config
<<-
RUBY
config.action_mailer.preview_enabled = true
RUBY
require
"
#{
app_path
}
/config/environment"
assert_equal
Rails
.
application
.
config
.
action_mailer
.
preview_enabled
,
true
end
end
end
railties/test/application/mailer_previews_test.rb
浏览文件 @
4d3eb70a
...
...
@@ -26,6 +26,20 @@ def teardown
assert_equal
404
,
last_response
.
status
end
test
"/rails/mailers is accessible with correct configuraiton"
do
add_to_config
"config.action_mailer.preview_enabled = true"
app
(
"production"
)
get
"/rails/mailers"
assert_equal
200
,
last_response
.
status
end
test
"/rails/mailers is not accessible with preview_enabled = false"
do
add_to_config
"config.action_mailer.preview_enabled = false"
app
(
"development"
)
get
"/rails/mailers"
assert_equal
404
,
last_response
.
status
end
test
"mailer previews are loaded from the default preview_path"
do
mailer
'notifier'
,
<<-
RUBY
class Notifier < ActionMailer::Base
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录