Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
890321e5
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 搜索 >>
提交
890321e5
编写于
3月 19, 2009
作者:
Y
Yehuda Katz
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Get very basic layouts working.
* Required small architecture change
上级
8ab37c76
变更
10
隐藏空白更改
内联
并排
Showing
10 changed file
with
104 addition
and
28 deletion
+104
-28
actionpack/lib/action_controller/abstract/layouts.rb
actionpack/lib/action_controller/abstract/layouts.rb
+2
-5
actionpack/lib/action_controller/abstract/renderer.rb
actionpack/lib/action_controller/abstract/renderer.rb
+32
-15
actionpack/lib/action_controller/new_base.rb
actionpack/lib/action_controller/new_base.rb
+1
-0
actionpack/lib/action_controller/new_base/layouts.rb
actionpack/lib/action_controller/new_base/layouts.rb
+19
-0
actionpack/lib/action_controller/new_base/renderer.rb
actionpack/lib/action_controller/new_base/renderer.rb
+10
-6
actionpack/test/abstract_controller/abstract_controller_test.rb
...pack/test/abstract_controller/abstract_controller_test.rb
+14
-2
actionpack/test/new_base/render_action_test.rb
actionpack/test/new_base/render_action_test.rb
+23
-0
actionpack/test/new_base/test_helper.rb
actionpack/test/new_base/test_helper.rb
+1
-0
actionpack/test/new_base/views/with_layout/happy_path/render_action_with_layout/hello_world.html.erb
...happy_path/render_action_with_layout/hello_world.html.erb
+1
-0
actionpack/test/new_base/views/with_layout/layouts/application.html.erb
...t/new_base/views/with_layout/layouts/application.html.erb
+1
-0
未找到文件。
actionpack/lib/action_controller/abstract/layouts.rb
浏览文件 @
890321e5
module
AbstractController
module
Layouts
def
_render_template
(
tmp
)
_action_view
.
_render_template_with_layout
(
tmp
,
_layout
)
end
def
_layout
def
_render_template
(
template
,
options
)
_action_view
.
_render_template_with_layout
(
template
,
options
[
:_layout
])
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/abstract/renderer.rb
浏览文件 @
890321e5
...
...
@@ -4,12 +4,14 @@ module AbstractController
module
Renderer
def
self
.
included
(
klass
)
klass
.
class_eval
do
klass
.
class_eval
do
extend
ClassMethods
attr_internal
:formats
extlib_inheritable_accessor
:view_paths
self
.
view_paths
||=
ActionView
::
PathSet
.
new
extlib_inheritable_accessor
:_view_paths
self
.
_view_paths
||=
ActionView
::
PathSet
.
new
include
AbstractController
::
Logger
end
end
...
...
@@ -17,27 +19,42 @@ def self.included(klass)
def
_action_view
@_action_view
||=
ActionView
::
Base
.
new
(
self
.
class
.
view_paths
,
{},
self
)
end
def
_prefix
end
def
render
(
template
=
action_name
)
self
.
response_body
=
render_to_string
(
template
)
def
render
(
name
=
action_name
,
options
=
{})
self
.
response_body
=
render_to_string
(
name
,
options
)
end
def
render_to_string
(
template
=
action_name
,
prefix
=
true
)
tmp
=
view_paths
.
find_by_parts
(
template
.
to_s
,
formats
,
(
_prefix
if
prefix
))
_render_template
(
tmp
)
# Raw rendering of a template.
# ====
# @option _prefix<String> The template's path prefix
# @option _layout<String> The relative path to the layout template to use
#
# :api: plugin
def
render_to_string
(
name
=
action_name
,
options
=
{})
template
=
view_paths
.
find_by_parts
(
name
.
to_s
,
formats
,
options
[
:_prefix
])
_render_template
(
template
,
options
)
end
def
_render_template
(
t
mp
)
_action_view
.
_render_template_with_layout
(
t
mp
)
def
_render_template
(
t
emplate
,
options
)
_action_view
.
_render_template_with_layout
(
t
emplate
)
end
def
view_paths
()
_view_paths
end
module
ClassMethods
def
append_view_path
(
path
)
self
.
view_paths
<<
path
end
def
view_paths
self
.
_view_paths
end
def
view_paths
=
(
paths
)
self
.
_view_paths
=
paths
.
is_a?
(
ActionView
::
PathSet
)
?
paths
:
ActionView
::
Base
.
process_view_paths
(
paths
)
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/new_base.rb
浏览文件 @
890321e5
module
ActionController
autoload
:AbstractBase
,
"action_controller/new_base/base"
autoload
:HideActions
,
"action_controller/new_base/hide_actions"
autoload
:Layouts
,
"action_controller/new_base/layouts"
autoload
:Renderer
,
"action_controller/new_base/renderer"
autoload
:UrlFor
,
"action_controller/new_base/url_for"
end
\ No newline at end of file
actionpack/lib/action_controller/new_base/layouts.rb
0 → 100644
浏览文件 @
890321e5
module
ActionController
module
Layouts
def
render_to_string
(
options
)
options
[
:_layout
]
=
options
[
:layout
]
||
_layout
super
end
def
_layout
begin
view_paths
.
find_by_parts
(
controller_path
,
formats
,
"layouts"
)
rescue
ActionView
::
MissingTemplate
begin
view_paths
.
find_by_parts
(
"application"
,
formats
,
"layouts"
)
rescue
ActionView
::
MissingTemplate
end
end
end
end
end
\ No newline at end of file
actionpack/lib/action_controller/new_base/renderer.rb
浏览文件 @
890321e5
...
...
@@ -11,6 +11,11 @@ module Renderer
# end
# end
def
initialize
(
*
)
self
.
formats
=
[
:html
]
super
end
def
render
(
action
,
options
=
{})
# TODO: Move this into #render_to_string
if
action
.
is_a?
(
Hash
)
...
...
@@ -23,22 +28,21 @@ def render(action, options = {})
self
.
response_body
=
render_to_string
(
options
)
end
def
render_to_string
(
options
)
self
.
formats
=
[
:html
]
def
render_to_string
(
options
)
unless
options
.
is_a?
(
Hash
)
options
=
{
:action
=>
options
}
end
if
options
.
key?
(
:text
)
_render_text
(
options
)
elsif
options
.
key?
(
:template
)
template
=
options
.
delete
(
:template
)
super
(
template
,
false
)
super
(
template
)
elsif
options
.
key?
(
:action
)
template
=
options
.
delete
(
:action
).
to_s
super
(
template
)
options
[
:_prefix
]
=
_prefix
super
(
template
,
options
)
end
end
...
...
actionpack/test/abstract_controller/abstract_controller_test.rb
浏览文件 @
890321e5
...
...
@@ -28,7 +28,14 @@ class TestBasic < ActiveSupport::TestCase
# ====
class
RenderingController
<
AbstractController
::
Base
include
Renderer
def
_prefix
()
end
def
render
(
name
=
action_name
,
options
=
{})
options
[
:_prefix
]
=
_prefix
super
end
append_view_path
File
.
expand_path
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"views"
))
end
...
...
@@ -121,7 +128,12 @@ def self.layout(formats)
def
_layout
self
.
class
.
layout
(
formats
)
end
end
def
render_to_string
(
name
=
action_name
,
options
=
{})
options
[
:_layout
]
=
options
[
:layout
]
||
_layout
super
end
end
class
Me4
<
WithLayouts
...
...
actionpack/test/new_base/render_action_test.rb
浏览文件 @
890321e5
...
...
@@ -2,6 +2,7 @@
module
HappyPath
# This has no layout and it works
class
RenderActionController
<
ActionController
::
Base2
def
render_action_hello_world
...
...
@@ -71,5 +72,27 @@ class TestRenderActionWithSymbol < SimpleRouteCase
assert_body
"Hello world!"
assert_status
200
end
# # ==== Render actions with layouts ====
class
RenderActionWithLayoutController
<
ActionController
::
Base2
# Set the view path to an application view structure with layouts
self
.
view_paths
=
[
File
.
join
(
File
.
dirname
(
__FILE__
),
'views'
,
'with_layout'
)]
def
hello_world
render
:action
=>
"hello_world"
end
end
class
TestRenderActionWithLayout
<
SimpleRouteCase
describe
%(
Render hello_world and implicitly use application.html.erb as a layout if
no layout is specified and no controller layout is present
)
get
"/happy_path/render_action_with_layout/hello_world"
assert_body
"OHAI Hello World! KTHXBAI"
assert_status
200
end
end
\ No newline at end of file
actionpack/test/new_base/test_helper.rb
浏览文件 @
890321e5
...
...
@@ -33,6 +33,7 @@ class Base2 < AbstractBase
include
ActionController
::
HideActions
include
ActionController
::
UrlFor
include
ActionController
::
Renderer
include
ActionController
::
Layouts
def
self
.
inherited
(
klass
)
@subclasses
||=
[]
...
...
actionpack/test/new_base/views/with_layout/happy_path/render_action_with_layout/hello_world.html.erb
0 → 100644
浏览文件 @
890321e5
Hello World!
\ No newline at end of file
actionpack/test/new_base/views/with_layout/layouts/application.html.erb
0 → 100644
浏览文件 @
890321e5
OHAI
<%=
yield
%>
KTHXBAI
\ No newline at end of file
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录