Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
35362fc2
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,发现更多精彩内容 >>
提交
35362fc2
编写于
11月 25, 2014
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #17646 from andyjeffries/html_layout_fix
Creating mailer layouts by default, including html and body tags
上级
9685080a
a58da25d
变更
8
隐藏空白更改
内联
并排
Showing
8 changed file
with
54 addition
and
12 deletion
+54
-12
actionmailer/lib/rails/generators/mailer/mailer_generator.rb
actionmailer/lib/rails/generators/mailer/mailer_generator.rb
+1
-0
actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb
...b/rails/generators/mailer/templates/application_mailer.rb
+4
-0
actionmailer/lib/rails/generators/mailer/templates/mailer.rb
actionmailer/lib/rails/generators/mailer/templates/mailer.rb
+1
-2
railties/lib/rails/generators/erb/mailer/mailer_generator.rb
railties/lib/rails/generators/erb/mailer/mailer_generator.rb
+20
-0
railties/lib/rails/generators/erb/mailer/templates/layout.html.erb
...lib/rails/generators/erb/mailer/templates/layout.html.erb
+5
-0
railties/lib/rails/generators/erb/mailer/templates/layout.text.erb
...lib/rails/generators/erb/mailer/templates/layout.text.erb
+1
-0
railties/test/generators/mailer_generator_test.rb
railties/test/generators/mailer_generator_test.rb
+20
-6
railties/test/generators/namespaced_generators_test.rb
railties/test/generators/namespaced_generators_test.rb
+2
-4
未找到文件。
actionmailer/lib/rails/generators/mailer/mailer_generator.rb
浏览文件 @
35362fc2
...
...
@@ -8,6 +8,7 @@ class MailerGenerator < NamedBase
def
create_mailer_file
template
"mailer.rb"
,
File
.
join
(
'app/mailers'
,
class_path
,
"
#{
file_name
}
.rb"
)
template
"application_mailer.rb"
,
'app/mailers/application_mailer.rb'
end
hook_for
:template_engine
,
:test_framework
...
...
actionmailer/lib/rails/generators/mailer/templates/application_mailer.rb
0 → 100644
浏览文件 @
35362fc2
class
ApplicationMailer
<
ActionMailer
::
Base
default
from:
"from@example.com"
layout
'mailer'
end
actionmailer/lib/rails/generators/mailer/templates/mailer.rb
浏览文件 @
35362fc2
<
% module_namespacing
do
-
%>
class <%= class_name %>
<
ActionMailer
::
Base
default
from:
"from@example.com"
class <%= class_name %>
<
ApplicationMailer
<
% actions.each
do
|
action
|
-
%>
# Subject can be set in your I18n file at config/locales/en.yml
...
...
railties/lib/rails/generators/erb/mailer/mailer_generator.rb
浏览文件 @
35362fc2
...
...
@@ -3,6 +3,26 @@
module
Erb
# :nodoc:
module
Generators
# :nodoc:
class
MailerGenerator
<
ControllerGenerator
# :nodoc:
def
copy_view_files
view_base_path
=
File
.
join
(
"app/views"
,
class_path
,
file_name
)
empty_directory
view_base_path
layout_base_path
=
"app/views/layouts"
actions
.
each
do
|
action
|
@action
=
action
formats
.
each
do
|
format
|
@view_path
=
File
.
join
(
view_base_path
,
filename_with_extensions
(
action
,
format
))
template
filename_with_extensions
(
:view
,
format
),
@view_path
@layout_path
=
File
.
join
(
layout_base_path
,
filename_with_extensions
(
"mailer"
,
format
))
template
filename_with_extensions
(
:layout
,
format
),
@layout_path
end
end
end
protected
def
formats
...
...
railties/lib/rails/generators/erb/mailer/templates/layout.html.erb
0 → 100644
浏览文件 @
35362fc2
<html>
<body>
<%%
=
yield
%>
</body>
</html>
railties/lib/rails/generators/erb/mailer/templates/layout.text.erb
0 → 100644
浏览文件 @
35362fc2
<%%
=
yield
%>
railties/test/generators/mailer_generator_test.rb
浏览文件 @
35362fc2
...
...
@@ -8,8 +8,18 @@ class MailerGeneratorTest < Rails::Generators::TestCase
def
test_mailer_skeleton_is_created
run_generator
assert_file
"app/mailers/notifier.rb"
do
|
mailer
|
assert_match
(
/class Notifier < ActionMailer::Base/
,
mailer
)
assert_match
(
/class Notifier < ApplicationMailer/
,
mailer
)
assert_no_match
(
/default from: "from@example.com"/
,
mailer
)
assert_no_match
(
/layout :mailer_notifier/
,
mailer
)
end
end
def
test_application_mailer_skeleton_is_created
run_generator
assert_file
"app/mailers/application_mailer.rb"
do
|
mailer
|
assert_match
(
/class ApplicationMailer < ActionMailer::Base/
,
mailer
)
assert_match
(
/default from: "from@example.com"/
,
mailer
)
assert_match
(
/layout 'mailer'/
,
mailer
)
end
end
...
...
@@ -69,27 +79,31 @@ def test_check_preview_class_collision
def
test_invokes_default_text_template_engine
run_generator
assert_file
"app/views/notifier/foo.text.erb"
do
|
view
|
assert_match
(
%r(
\s
app/views/notifier/foo
\.
text
\.
erb)
,
view
)
assert_match
(
/<%= @greeting %>/
,
view
)
end
assert_file
"app/views/notifier/bar.text.erb"
do
|
view
|
assert_match
(
%r(
\s
app/views/notifier/bar
\.
text
\.
erb)
,
view
)
assert_match
(
/<%= @greeting %>/
,
view
)
end
assert_file
"app/views/layouts/mailer.text.erb"
do
|
view
|
assert_match
(
/<%= yield %>/
,
view
)
end
end
def
test_invokes_default_html_template_engine
run_generator
assert_file
"app/views/notifier/foo.html.erb"
do
|
view
|
assert_match
(
%r(
\s
app/views/notifier/foo
\.
html
\.
erb)
,
view
)
assert_match
(
/<%= @greeting %>/
,
view
)
end
assert_file
"app/views/notifier/bar.html.erb"
do
|
view
|
assert_match
(
%r(
\s
app/views/notifier/bar
\.
html
\.
erb)
,
view
)
assert_match
(
/<%= @greeting %>/
,
view
)
end
assert_file
"app/views/layouts/mailer.html.erb"
do
|
view
|
assert_match
(
%r{<html>
\n
<body>
\n
<%= yield %>
\n
</body>
\n
</html>}
,
view
)
end
end
def
test_invokes_default_template_engine_even_with_no_action
...
...
@@ -105,7 +119,7 @@ def test_logs_if_the_template_engine_cannot_be_found
def
test_mailer_with_namedspaced_mailer
run_generator
[
"Farm::Animal"
,
"moos"
]
assert_file
"app/mailers/farm/animal.rb"
do
|
mailer
|
assert_match
(
/class Farm::Animal < A
ctionMailer::Base
/
,
mailer
)
assert_match
(
/class Farm::Animal < A
pplicationMailer
/
,
mailer
)
assert_match
(
/en\.farm\.animal\.moos\.subject/
,
mailer
)
end
assert_file
"test/mailers/previews/farm/animal_preview.rb"
do
|
preview
|
...
...
railties/test/generators/namespaced_generators_test.rb
浏览文件 @
35362fc2
...
...
@@ -148,8 +148,8 @@ def test_mailer_skeleton_is_created
run_generator
assert_file
"app/mailers/test_app/notifier.rb"
do
|
mailer
|
assert_match
(
/module TestApp/
,
mailer
)
assert_match
(
/class Notifier < A
ctionMailer::Base
/
,
mailer
)
assert_match
(
/default from: "from@example.com"/
,
mailer
)
assert_match
(
/class Notifier < A
pplicationMailer
/
,
mailer
)
assert_
no_
match
(
/default from: "from@example.com"/
,
mailer
)
end
end
...
...
@@ -174,12 +174,10 @@ def test_invokes_default_test_framework
def
test_invokes_default_template_engine
run_generator
assert_file
"app/views/test_app/notifier/foo.text.erb"
do
|
view
|
assert_match
(
%r(app/views/test_app/notifier/foo
\.
text
\.
erb)
,
view
)
assert_match
(
/<%= @greeting %>/
,
view
)
end
assert_file
"app/views/test_app/notifier/bar.text.erb"
do
|
view
|
assert_match
(
%r(app/views/test_app/notifier/bar
\.
text
\.
erb)
,
view
)
assert_match
(
/<%= @greeting %>/
,
view
)
end
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录