Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
c6123c37
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,体验更适合开发者的 AI 搜索 >>
提交
c6123c37
编写于
3月 20, 2009
作者:
C
Carl Lerche
提交者:
Yehuda Katz
3月 23, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Finished implementing layout for render :text
上级
81e814ad
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
67 addition
and
16 deletion
+67
-16
actionpack/lib/action_controller/abstract/renderer.rb
actionpack/lib/action_controller/abstract/renderer.rb
+5
-3
actionpack/lib/action_controller/new_base/layouts.rb
actionpack/lib/action_controller/new_base/layouts.rb
+20
-3
actionpack/lib/action_controller/new_base/renderer.rb
actionpack/lib/action_controller/new_base/renderer.rb
+5
-5
actionpack/test/abstract_controller/abstract_controller_test.rb
...pack/test/abstract_controller/abstract_controller_test.rb
+6
-2
actionpack/test/abstract_controller/helper_test.rb
actionpack/test/abstract_controller/helper_test.rb
+4
-0
actionpack/test/new_base/render_text_test.rb
actionpack/test/new_base/render_text_test.rb
+26
-2
actionpack/test/new_base/test_helper.rb
actionpack/test/new_base/test_helper.rb
+1
-1
未找到文件。
actionpack/lib/action_controller/abstract/renderer.rb
浏览文件 @
c6123c37
...
...
@@ -20,8 +20,8 @@ def _action_view
@_action_view
||=
ActionView
::
Base
.
new
(
self
.
class
.
view_paths
,
{},
self
)
end
def
render
(
name
=
action_name
,
options
=
{})
self
.
response_body
=
render_to_string
(
name
,
options
)
def
render
(
options
=
{})
self
.
response_body
=
render_to_string
(
options
)
end
# Raw rendering of a template.
...
...
@@ -30,7 +30,9 @@ def render(name = action_name, options = {})
# @option _layout<String> The relative path to the layout template to use
#
# :api: plugin
def
render_to_string
(
name
=
action_name
,
options
=
{})
def
render_to_string
(
options
=
{})
name
=
options
[
:_template_name
]
||
action_name
template
=
options
[
:_template
]
||
view_paths
.
find_by_parts
(
name
.
to_s
,
formats
,
options
[
:_prefix
])
_render_template
(
template
,
options
)
end
...
...
actionpack/lib/action_controller/new_base/layouts.rb
浏览文件 @
c6123c37
module
ActionController
module
Layouts
def
render_to_string
(
options
)
options
[
:_layout
]
=
options
[
:layout
]
||
_layout
if
!
options
.
key?
(
:text
)
||
options
.
key?
(
:layout
)
options
[
:_layout
]
=
options
.
key?
(
:layout
)
?
_layout_for_option
(
options
[
:layout
])
:
_layout
end
super
end
private
def
_layout_for_option
(
name
)
case
name
when
String
then
_layout_for_name
(
name
)
when
true
then
_layout
when
false
then
nil
end
end
def
_layout_for_name
(
name
)
view_paths
.
find_by_parts
(
name
,
formats
,
"layouts"
)
end
def
_layout
begin
view_paths
.
find_by_parts
(
controller_path
,
formats
,
"layouts"
)
_layout_for_name
(
controller_path
)
rescue
ActionView
::
MissingTemplate
begin
view_paths
.
find_by_parts
(
"application"
,
formats
,
"layouts
"
)
_layout_for_name
(
"application
"
)
rescue
ActionView
::
MissingTemplate
end
end
...
...
actionpack/lib/action_controller/new_base/renderer.rb
浏览文件 @
c6123c37
...
...
@@ -38,13 +38,13 @@ def render_to_string(options)
options
[
:_template
]
=
ActionView
::
TextTemplate
.
new
(
_text
(
options
))
template
=
nil
elsif
options
.
key?
(
:template
)
template
=
options
.
delete
(
:template
)
options
[
:_template_name
]
=
options
[
:template
]
elsif
options
.
key?
(
:action
)
template
=
options
.
delete
(
:action
)
.
to_s
options
[
:_template_name
]
=
options
[
:action
]
.
to_s
options
[
:_prefix
]
=
_prefix
end
super
(
template
,
options
)
super
(
options
)
end
private
...
...
@@ -54,7 +54,7 @@ def _prefix
end
def
_text
(
options
)
text
=
options
.
delete
(
:text
)
text
=
options
[
:text
]
case
text
when
nil
then
" "
...
...
@@ -63,7 +63,7 @@ def _text(options)
end
def
_process_options
(
options
)
if
status
=
options
.
delete
(
:status
)
if
status
=
options
[
:status
]
response
.
status
=
status
.
to_i
end
end
...
...
actionpack/test/abstract_controller/abstract_controller_test.rb
浏览文件 @
c6123c37
...
...
@@ -31,7 +31,11 @@ class RenderingController < AbstractController::Base
def
_prefix
()
end
def
render
(
name
=
action_name
,
options
=
{})
def
render
(
options
=
{})
if
options
.
is_a?
(
String
)
options
=
{
:_template_name
=>
options
}
end
options
[
:_prefix
]
=
_prefix
super
end
...
...
@@ -130,7 +134,7 @@ def _layout
self
.
class
.
layout
(
formats
)
end
def
render_to_string
(
name
=
action_name
,
options
=
{})
def
render_to_string
(
options
=
{})
options
[
:_layout
]
=
options
[
:layout
]
||
_layout
super
end
...
...
actionpack/test/abstract_controller/helper_test.rb
浏览文件 @
c6123c37
...
...
@@ -7,6 +7,10 @@ class ControllerWithHelpers < AbstractController::Base
include
Renderer
include
Helpers
def
render
(
string
)
super
(
:_template_name
=>
string
)
end
append_view_path
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"views"
))
end
...
...
actionpack/test/new_base/render_text_test.rb
浏览文件 @
c6123c37
...
...
@@ -8,7 +8,7 @@ class RenderTextController < ActionController::Base2
"layouts/greetings.html.erb"
=>
"<%= yield %>, I wish thee well."
)]
def
render_hello_world
_from_variable
def
render_hello_world
render
:text
=>
"hello david"
end
...
...
@@ -36,6 +36,14 @@ def render_text_with_layout
render
:text
=>
"hello world"
,
:layout
=>
true
end
def
render_text_with_layout_false
render
:text
=>
"hello world"
,
:layout
=>
false
end
def
render_text_with_layout_nil
render
:text
=>
"hello world"
,
:layout
=>
nil
end
def
render_text_with_custom_layout
render
:text
=>
"hello world"
,
:layout
=>
"greetings"
end
...
...
@@ -44,7 +52,7 @@ def render_text_with_custom_layout
class
TestSimpleTextRender
<
SimpleRouteCase
describe
"Rendering text from a action with default options renders the text without the layout"
get
"/happy_path/render_text/render_hello_world
_from_variable
"
get
"/happy_path/render_text/render_hello_world"
assert_body
"hello david"
assert_status
200
end
...
...
@@ -96,4 +104,20 @@ class TestTextRenderWithCustomLayout < SimpleRouteCase
assert_body
"hello world, I wish thee well."
assert_status
200
end
class
TestTextRenderWithLayoutFalse
<
SimpleRouteCase
describe
"Rendering text with :layout => false"
get
"/happy_path/render_text/render_text_with_layout_false"
assert_body
"hello world"
assert_status
200
end
class
TestTextRenderWithLayoutNil
<
SimpleRouteCase
describe
"Rendering text with :layout => nil"
get
"/happy_path/render_text/render_text_with_layout_nil"
assert_body
"hello world"
assert_status
200
end
end
\ No newline at end of file
actionpack/test/new_base/test_helper.rb
浏览文件 @
c6123c37
...
...
@@ -32,8 +32,8 @@ class Base2 < AbstractBase
include
ActionController
::
HideActions
include
ActionController
::
UrlFor
include
ActionController
::
Renderer
include
ActionController
::
Layouts
include
ActionController
::
Renderer
def
self
.
inherited
(
klass
)
@subclasses
||=
[]
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录