Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
ab7c25d5
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,发现更多精彩内容 >>
提交
ab7c25d5
编写于
12月 29, 2008
作者:
J
Joshua Peek
提交者:
Yehuda Katz
1月 01, 2009
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up view path cruft and split path implementations into Template::Path and Template::EagerPath
上级
860dd770
变更
12
隐藏空白更改
内联
并排
Showing
12 changed file
with
108 addition
and
138 deletion
+108
-138
actionmailer/test/abstract_unit.rb
actionmailer/test/abstract_unit.rb
+0
-1
actionpack/lib/action_controller/base.rb
actionpack/lib/action_controller/base.rb
+6
-6
actionpack/lib/action_controller/rescue.rb
actionpack/lib/action_controller/rescue.rb
+2
-2
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/base.rb
+1
-1
actionpack/lib/action_view/inline_template.rb
actionpack/lib/action_view/inline_template.rb
+1
-1
actionpack/lib/action_view/paths.rb
actionpack/lib/action_view/paths.rb
+1
-106
actionpack/lib/action_view/renderable.rb
actionpack/lib/action_view/renderable.rb
+3
-6
actionpack/lib/action_view/template.rb
actionpack/lib/action_view/template.rb
+81
-4
actionpack/test/abstract_unit.rb
actionpack/test/abstract_unit.rb
+0
-1
actionpack/test/template/compiled_templates_test.rb
actionpack/test/template/compiled_templates_test.rb
+5
-4
actionpack/test/template/render_test.rb
actionpack/test/template/render_test.rb
+4
-3
railties/lib/initializer.rb
railties/lib/initializer.rb
+4
-3
未找到文件。
actionmailer/test/abstract_unit.rb
浏览文件 @
ab7c25d5
...
...
@@ -17,7 +17,6 @@
FIXTURE_LOAD_PATH
=
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
)
ActionMailer
::
Base
.
template_root
=
FIXTURE_LOAD_PATH
ActionMailer
::
Base
.
template_root
.
load
class
MockSMTP
def
self
.
deliveries
...
...
actionpack/lib/action_controller/base.rb
浏览文件 @
ab7c25d5
...
...
@@ -869,7 +869,7 @@ def render(options = nil, extra_options = {}, &block) #:doc:
validate_render_arguments
(
options
,
extra_options
,
block_given?
)
if
options
.
nil?
options
=
{
:template
=>
default_template
.
filename
,
:layout
=>
true
}
options
=
{
:template
=>
default_template
,
:layout
=>
true
}
elsif
options
==
:update
options
=
extra_options
.
merge
({
:update
=>
true
})
elsif
options
.
is_a?
(
String
)
||
options
.
is_a?
(
Symbol
)
...
...
@@ -1125,7 +1125,7 @@ def stale?(options)
end
# Sets the etag, last_modified, or both on the response and renders a
# "304 Not Modified" response if the request is already fresh.
# "304 Not Modified" response if the request is already fresh.
#
# Example:
#
...
...
@@ -1133,8 +1133,8 @@ def stale?(options)
# @article = Article.find(params[:id])
# fresh_when(:etag => @article, :last_modified => @article.created_at.utc)
# end
#
# This will render the show template if the request isn't sending a matching etag or
#
# This will render the show template if the request isn't sending a matching etag or
# If-Modified-Since header and just a "304 Not Modified" response if there's a match.
def
fresh_when
(
options
)
options
.
assert_valid_keys
(
:etag
,
:last_modified
)
...
...
@@ -1239,7 +1239,7 @@ def log_processing
log_processing_for_parameters
end
end
def
log_processing_for_request_id
request_id
=
"
\n\n
Processing
#{
self
.
class
.
name
}
\#
#{
action_name
}
"
request_id
<<
"to
#{
params
[
:format
]
}
"
if
params
[
:format
]
...
...
@@ -1251,7 +1251,7 @@ def log_processing_for_request_id
def
log_processing_for_parameters
parameters
=
respond_to?
(
:filter_parameters
)
?
filter_parameters
(
params
)
:
params
.
dup
parameters
=
parameters
.
except!
(
:controller
,
:action
,
:format
,
:_method
)
logger
.
info
" Parameters:
#{
parameters
.
inspect
}
"
unless
parameters
.
empty?
end
...
...
actionpack/lib/action_controller/rescue.rb
浏览文件 @
ab7c25d5
...
...
@@ -38,8 +38,8 @@ module Rescue
'ActionView::TemplateError'
=>
'template_error'
}
RESCUES_TEMPLATE_PATH
=
ActionView
::
PathSet
::
Path
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"templates"
)
,
true
)
RESCUES_TEMPLATE_PATH
=
ActionView
::
Template
::
Eager
Path
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"templates"
))
def
self
.
included
(
base
)
#:nodoc:
base
.
cattr_accessor
:rescue_responses
...
...
actionpack/lib/action_view/base.rb
浏览文件 @
ab7c25d5
...
...
@@ -225,7 +225,7 @@ def view_paths=(paths)
end
# Returns the result of a render that's dictated by the options hash. The primary options are:
#
#
# * <tt>:partial</tt> - See ActionView::Partials.
# * <tt>:update</tt> - Calls update_page with the block given.
# * <tt>:file</tt> - Renders an explicit template file (this used to be the old default), add :locals to pass in those.
...
...
actionpack/lib/action_view/inline_template.rb
浏览文件 @
ab7c25d5
...
...
@@ -12,7 +12,7 @@ def initialize(source, type = nil)
private
# Always recompile inline templates
def
recompile?
(
local_assigns
)
def
recompile?
true
end
end
...
...
actionpack/lib/action_view/paths.rb
浏览文件 @
ab7c25d5
...
...
@@ -2,7 +2,7 @@ module ActionView #:nodoc:
class
PathSet
<
Array
#:nodoc:
def
self
.
type_cast
(
obj
)
if
obj
.
is_a?
(
String
)
Path
.
new
(
obj
)
Template
::
Eager
Path
.
new
(
obj
)
else
obj
end
...
...
@@ -32,111 +32,6 @@ def unshift(*objs)
super
(
*
objs
.
map
{
|
obj
|
self
.
class
.
type_cast
(
obj
)
})
end
class
Path
#:nodoc:
attr_reader
:path
,
:paths
delegate
:hash
,
:inspect
,
:to
=>
:path
def
initialize
(
path
,
load
=
false
)
raise
ArgumentError
,
"path already is a Path class"
if
path
.
is_a?
(
Path
)
@path
=
path
.
freeze
reload!
if
load
end
def
to_s
if
defined?
(
RAILS_ROOT
)
path
.
to_s
.
sub
(
/^
#{
Regexp
.
escape
(
File
.
expand_path
(
RAILS_ROOT
))
}
\//
,
''
)
else
path
.
to_s
end
end
def
to_str
path
.
to_str
end
def
==
(
path
)
to_str
==
path
.
to_str
end
def
eql?
(
path
)
to_str
==
path
.
to_str
end
# Returns a ActionView::Template object for the given path string. The
# input path should be relative to the view path directory,
# +hello/index.html.erb+. This method also has a special exception to
# match partial file names without a handler extension. So
# +hello/index.html+ will match the first template it finds with a
# known template extension, +hello/index.html.erb+. Template extensions
# should not be confused with format extensions +html+, +js+, +xml+,
# etc. A format must be supplied to match a formated file. +hello/index+
# will never match +hello/index.html.erb+.
#
# This method also has two different implementations, one that is "lazy"
# and makes file system calls every time and the other is cached,
# "eager" which looks up the template in an in memory index. The "lazy"
# version is designed for development where you want to automatically
# find new templates between requests. The "eager" version is designed
# for production mode and it is much faster but requires more time
# upfront to build the file index.
def
[]
(
path
)
if
loaded?
@paths
[
path
]
else
Dir
.
glob
(
"
#{
@path
}
/
#{
path
}
*"
).
each
do
|
file
|
template
=
create_template
(
file
)
if
template
.
accessible_paths
.
include?
(
path
)
return
template
end
end
nil
end
end
def
loaded?
@loaded
?
true
:
false
end
def
load
reload!
unless
loaded?
self
end
# Rebuild load path directory cache
def
reload!
@paths
=
{}
templates_in_path
do
|
template
|
template
.
load!
template
.
accessible_paths
.
each
do
|
path
|
@paths
[
path
]
=
template
end
end
@paths
.
freeze
@loaded
=
true
end
private
def
templates_in_path
(
Dir
.
glob
(
"
#{
@path
}
/**/*/**"
)
|
Dir
.
glob
(
"
#{
@path
}
/**"
)).
each
do
|
file
|
yield
create_template
(
file
)
unless
File
.
directory?
(
file
)
end
end
def
create_template
(
file
)
Template
.
new
(
file
.
split
(
"
#{
self
}
/"
).
last
,
self
)
end
end
def
load
each
{
|
path
|
path
.
load
}
end
def
reload!
each
{
|
path
|
path
.
reload!
}
end
def
find_template
(
original_template_path
,
format
=
nil
)
return
original_template_path
if
original_template_path
.
respond_to?
(
:render
)
template_path
=
original_template_path
.
sub
(
/^\//
,
''
)
...
...
actionpack/lib/action_view/renderable.rb
浏览文件 @
ab7c25d5
...
...
@@ -60,7 +60,7 @@ def method_name(local_assigns)
def
compile
(
local_assigns
)
render_symbol
=
method_name
(
local_assigns
)
if
recompile?
(
render_symbol
)
if
!
Base
::
CompiledTemplates
.
method_defined?
(
render_symbol
)
||
recompile?
compile!
(
render_symbol
,
local_assigns
)
end
end
...
...
@@ -89,11 +89,8 @@ def #{render_symbol}(local_assigns)
end
end
# Method to check whether template compilation is necessary.
# The template will be compiled if the file has not been compiled yet, or
# if local_assigns has a new key, which isn't supported by the compiled code yet.
def
recompile?
(
symbol
)
!
Base
::
CompiledTemplates
.
method_defined?
(
symbol
)
||
!
loaded?
def
recompile?
false
end
end
end
actionpack/lib/action_view/template.rb
浏览文件 @
ab7c25d5
module
ActionView
#:nodoc:
class
Template
class
Path
attr_reader
:path
,
:paths
delegate
:hash
,
:inspect
,
:to
=>
:path
def
initialize
(
path
)
raise
ArgumentError
,
"path already is a Path class"
if
path
.
is_a?
(
Path
)
@path
=
path
.
freeze
end
def
to_s
if
defined?
(
RAILS_ROOT
)
path
.
to_s
.
sub
(
/^
#{
Regexp
.
escape
(
File
.
expand_path
(
RAILS_ROOT
))
}
\//
,
''
)
else
path
.
to_s
end
end
def
to_str
path
.
to_str
end
def
==
(
path
)
to_str
==
path
.
to_str
end
def
eql?
(
path
)
to_str
==
path
.
to_str
end
# Returns a ActionView::Template object for the given path string. The
# input path should be relative to the view path directory,
# +hello/index.html.erb+. This method also has a special exception to
# match partial file names without a handler extension. So
# +hello/index.html+ will match the first template it finds with a
# known template extension, +hello/index.html.erb+. Template extensions
# should not be confused with format extensions +html+, +js+, +xml+,
# etc. A format must be supplied to match a formated file. +hello/index+
# will never match +hello/index.html.erb+.
def
[]
(
path
)
templates_in_path
do
|
template
|
if
template
.
accessible_paths
.
include?
(
path
)
return
template
end
end
nil
end
private
def
templates_in_path
(
Dir
.
glob
(
"
#{
@path
}
/**/*/**"
)
|
Dir
.
glob
(
"
#{
@path
}
/**"
)).
each
do
|
file
|
yield
create_template
(
file
)
unless
File
.
directory?
(
file
)
end
end
def
create_template
(
file
)
Template
.
new
(
file
.
split
(
"
#{
self
}
/"
).
last
,
self
)
end
end
class
EagerPath
<
Path
def
initialize
(
path
)
super
@paths
=
{}
templates_in_path
do
|
template
|
template
.
load!
template
.
accessible_paths
.
each
do
|
path
|
@paths
[
path
]
=
template
end
end
@paths
.
freeze
end
def
[]
(
path
)
@paths
[
path
]
end
end
extend
TemplateHandlers
extend
ActiveSupport
::
Memoizable
include
Renderable
...
...
@@ -115,13 +193,12 @@ def stale?
File
.
mtime
(
filename
)
>
mtime
end
def
loaded
?
@load
ed
def
recompile
?
!
@cach
ed
end
def
load!
@loaded
=
true
compile
({})
@cached
=
true
freeze
end
...
...
actionpack/test/abstract_unit.rb
浏览文件 @
ab7c25d5
...
...
@@ -34,7 +34,6 @@
FIXTURE_LOAD_PATH
=
File
.
join
(
File
.
dirname
(
__FILE__
),
'fixtures'
)
ActionController
::
Base
.
view_paths
=
FIXTURE_LOAD_PATH
ActionController
::
Base
.
view_paths
.
load
def
uses_mocha
(
test_name
)
yield
...
...
actionpack/test/template/compiled_templates_test.rb
浏览文件 @
ab7c25d5
...
...
@@ -31,7 +31,7 @@ def test_compiled_template_will_not_be_recompiled_when_rendered_with_identical_l
end
def
test_compiled_template_will_always_be_recompiled_when_template_is_not_cached
ActionView
::
Template
.
any_instance
.
expects
(
:
loaded?
).
times
(
3
).
returns
(
fals
e
)
ActionView
::
Template
.
any_instance
.
expects
(
:
recompile?
).
times
(
3
).
returns
(
tru
e
)
assert_equal
0
,
@compiled_templates
.
instance_methods
.
size
assert_equal
"Hello world!"
,
render
(
:file
=>
"
#{
FIXTURE_LOAD_PATH
}
/test/hello_world.erb"
)
ActionView
::
Template
.
any_instance
.
expects
(
:compile!
).
times
(
3
)
...
...
@@ -62,13 +62,14 @@ def render(*args)
def
render_with_cache
(
*
args
)
view_paths
=
ActionController
::
Base
.
view_paths
assert
view_paths
.
first
.
loaded?
assert
_equal
ActionView
::
Template
::
EagerPath
,
view_paths
.
first
.
class
ActionView
::
Base
.
new
(
view_paths
,
{}).
render
(
*
args
)
end
def
render_without_cache
(
*
args
)
view_paths
=
ActionView
::
Base
.
process_view_paths
(
FIXTURE_LOAD_PATH
)
assert
!
view_paths
.
first
.
loaded?
path
=
ActionView
::
Template
::
Path
.
new
(
FIXTURE_LOAD_PATH
)
view_paths
=
ActionView
::
Base
.
process_view_paths
(
path
)
assert_equal
ActionView
::
Template
::
Path
,
view_paths
.
first
.
class
ActionView
::
Base
.
new
(
view_paths
,
{}).
render
(
*
args
)
end
...
...
actionpack/test/template/render_test.rb
浏览文件 @
ab7c25d5
...
...
@@ -197,7 +197,7 @@ class CachedViewRenderTest < Test::Unit::TestCase
# Ensure view path cache is primed
def
setup
view_paths
=
ActionController
::
Base
.
view_paths
assert
view_paths
.
first
.
loaded?
assert
_equal
ActionView
::
Template
::
EagerPath
,
view_paths
.
first
.
class
setup_view
(
view_paths
)
end
end
...
...
@@ -208,8 +208,9 @@ class LazyViewRenderTest < Test::Unit::TestCase
# Test the same thing as above, but make sure the view path
# is not eager loaded
def
setup
view_paths
=
ActionView
::
Base
.
process_view_paths
(
FIXTURE_LOAD_PATH
)
assert
!
view_paths
.
first
.
loaded?
path
=
ActionView
::
Template
::
Path
.
new
(
FIXTURE_LOAD_PATH
)
view_paths
=
ActionView
::
Base
.
process_view_paths
(
path
)
assert_equal
ActionView
::
Template
::
Path
,
view_paths
.
first
.
class
setup_view
(
view_paths
)
end
end
railties/lib/initializer.rb
浏览文件 @
ab7c25d5
...
...
@@ -370,8 +370,9 @@ def load_observers
def
load_view_paths
if
configuration
.
frameworks
.
include?
(
:action_view
)
if
configuration
.
cache_classes
ActionController
::
Base
.
view_paths
.
load
if
configuration
.
frameworks
.
include?
(
:action_controller
)
ActionMailer
::
Base
.
template_root
.
load
if
configuration
.
frameworks
.
include?
(
:action_mailer
)
view_path
=
ActionView
::
Template
::
EagerPath
.
new
(
configuration
.
view_path
)
ActionController
::
Base
.
view_paths
=
view_path
if
configuration
.
frameworks
.
include?
(
:action_controller
)
ActionMailer
::
Base
.
template_root
=
view_path
if
configuration
.
frameworks
.
include?
(
:action_mailer
)
end
end
end
...
...
@@ -473,7 +474,7 @@ def initialize_framework_logging
# set to use Configuration#view_path.
def
initialize_framework_views
if
configuration
.
frameworks
.
include?
(
:action_view
)
view_path
=
ActionView
::
PathSet
::
Path
.
new
(
configuration
.
view_path
,
false
)
view_path
=
ActionView
::
Template
::
Path
.
new
(
configuration
.
view_path
)
ActionMailer
::
Base
.
template_root
||=
view_path
if
configuration
.
frameworks
.
include?
(
:action_mailer
)
ActionController
::
Base
.
view_paths
=
view_path
if
configuration
.
frameworks
.
include?
(
:action_controller
)
&&
ActionController
::
Base
.
view_paths
.
empty?
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录