Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dd41f66a
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,发现更多精彩内容 >>
提交
dd41f66a
编写于
7月 14, 2008
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Include Memoizable in ActionView::Template
上级
8a9934a9
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
43 deletion
+27
-43
actionpack/lib/action_view/renderable.rb
actionpack/lib/action_view/renderable.rb
+6
-9
actionpack/lib/action_view/renderable_partial.rb
actionpack/lib/action_view/renderable_partial.rb
+6
-9
actionpack/lib/action_view/template.rb
actionpack/lib/action_view/template.rb
+15
-25
未找到文件。
actionpack/lib/action_view/renderable.rb
浏览文件 @
dd41f66a
...
...
@@ -7,20 +7,17 @@ def self.included(base)
@@mutex
=
Mutex
.
new
end
include
ActiveSupport
::
Memoizable
def
handler
@handler
||=
Template
.
handler_class_for_extension
(
extension
)
Template
.
handler_class_for_extension
(
extension
)
end
memorize
:handler
def
compiled_source
@compiled_source
||=
handler
.
new
(
nil
).
compile
(
self
)
if
handler
.
compilable?
end
def
freeze
# Eager load and freeze memoized methods
handler
.
freeze
compiled_source
.
freeze
super
handler
.
new
(
nil
).
compile
(
self
)
if
handler
.
compilable?
end
memorize
:compiled_source
def
render
(
view
,
local_assigns
=
{})
view
.
_first_render
||=
self
...
...
actionpack/lib/action_view/renderable_partial.rb
浏览文件 @
dd41f66a
...
...
@@ -3,20 +3,17 @@ module RenderablePartial
# NOTE: The template that this mixin is beening include into is frozen
# So you can not set or modify any instance variables
include
ActiveSupport
::
Memoizable
def
variable_name
@variable_name
||=
name
.
sub
(
/\A_/
,
''
).
to_sym
name
.
sub
(
/\A_/
,
''
).
to_sym
end
memorize
:variable_name
def
counter_name
@counter_name
||=
"
#{
variable_name
}
_counter"
.
to_sym
end
def
freeze
# Eager load and freeze memoized methods
variable_name
.
freeze
counter_name
.
freeze
super
"
#{
variable_name
}
_counter"
.
to_sym
end
memorize
:counter_name
def
render
(
view
,
local_assigns
=
{})
ActionController
::
Base
.
benchmark
(
"Rendered
#{
path_without_format_and_extension
}
"
,
Logger
::
DEBUG
,
false
)
do
...
...
actionpack/lib/action_view/template.rb
浏览文件 @
dd41f66a
module
ActionView
#:nodoc:
class
Template
extend
TemplateHandlers
include
ActiveSupport
::
Memoizable
include
Renderable
attr_accessor
:filename
,
:load_path
,
:base_path
,
:name
,
:format
,
:extension
...
...
@@ -16,48 +17,37 @@ def initialize(template_path, load_paths = [])
extend
RenderablePartial
if
@name
=~
/^_/
end
def
freeze
# Eager load and freeze memoized methods
format_and_extension
.
freeze
path
.
freeze
path_without_extension
.
freeze
path_without_format_and_extension
.
freeze
source
.
freeze
method_segment
.
freeze
super
end
def
format_and_extension
@format_and_extension
||=
(
extensions
=
[
format
,
extension
].
compact
.
join
(
"."
)).
blank?
?
nil
:
extensions
(
extensions
=
[
format
,
extension
].
compact
.
join
(
"."
)).
blank?
?
nil
:
extensions
end
memorize
:format_and_extension
def
path
@path
||=
[
base_path
,
[
name
,
format
,
extension
].
compact
.
join
(
'.'
)].
compact
.
join
(
'/'
)
[
base_path
,
[
name
,
format
,
extension
].
compact
.
join
(
'.'
)].
compact
.
join
(
'/'
)
end
memorize
:path
def
path_without_extension
@path_without_extension
||=
[
base_path
,
[
name
,
format
].
compact
.
join
(
'.'
)].
compact
.
join
(
'/'
)
[
base_path
,
[
name
,
format
].
compact
.
join
(
'.'
)].
compact
.
join
(
'/'
)
end
memorize
:path_without_extension
def
path_without_format_and_extension
@path_without_format_and_extension
||=
[
base_path
,
name
].
compact
.
join
(
'/'
)
[
base_path
,
name
].
compact
.
join
(
'/'
)
end
memorize
:path_without_format_and_extension
def
source
@source
||=
File
.
read
(
filename
)
File
.
read
(
filename
)
end
memorize
:source
def
method_segment
unless
@method_segment
segment
=
File
.
expand_path
(
filename
)
segment
.
sub!
(
/^
#{
Regexp
.
escape
(
File
.
expand_path
(
RAILS_ROOT
))
}
/
,
''
)
if
defined?
(
RAILS_ROOT
)
segment
.
gsub!
(
/([^a-zA-Z0-9_])/
)
{
$1
.
ord
}
@method_segment
=
segment
end
@method_segment
segment
=
File
.
expand_path
(
filename
)
segment
.
sub!
(
/^
#{
Regexp
.
escape
(
File
.
expand_path
(
RAILS_ROOT
))
}
/
,
''
)
if
defined?
(
RAILS_ROOT
)
segment
.
gsub!
(
/([^a-zA-Z0-9_])/
)
{
$1
.
ord
}
end
memorize
:method_segment
def
render_template
(
view
,
local_assigns
=
{})
render
(
view
,
local_assigns
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录