Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
5ed162d7
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,发现更多精彩内容 >>
提交
5ed162d7
编写于
6月 11, 2008
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Moved template handler registration into a mix-in module.
上级
2275b8da
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
27 addition
and
72 deletion
+27
-72
actionpack/lib/action_view.rb
actionpack/lib/action_view.rb
+1
-6
actionpack/lib/action_view/template.rb
actionpack/lib/action_view/template.rb
+26
-65
actionpack/lib/action_view/template_handler.rb
actionpack/lib/action_view/template_handler.rb
+0
-1
未找到文件。
actionpack/lib/action_view.rb
浏览文件 @
5ed162d7
...
...
@@ -21,12 +21,7 @@
# WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
#++
require
'action_view/template_handler'
require
'action_view/template_handlers/compilable'
require
'action_view/template_handlers/builder'
require
'action_view/template_handlers/erb'
require
'action_view/template_handlers/rjs'
require
'action_view/template_handlers'
require
'action_view/template_finder'
require
'action_view/template'
require
'action_view/partial_template'
...
...
actionpack/lib/action_view/template.rb
浏览文件 @
5ed162d7
module
ActionView
#:nodoc:
class
Template
#:nodoc:
extend
TemplateHandlers
attr_accessor
:locals
attr_reader
:handler
,
:path
,
:extension
,
:filename
,
:path_without_extension
,
:method
...
...
@@ -13,7 +14,7 @@ def initialize(view, path, use_full_path, locals = {})
@view
.
first_render
||=
@path
@source
=
nil
# Don't read the source until we know that it is required
set_extension_and_file_name
(
use_full_path
)
@locals
=
locals
||
{}
@handler
=
self
.
class
.
handler_class_for_extension
(
@extension
).
new
(
@view
)
end
...
...
@@ -29,7 +30,7 @@ def render_template
raise
TemplateError
.
new
(
self
,
@view
.
assigns
,
e
)
end
end
def
render
prepare!
@handler
.
render
(
self
)
...
...
@@ -46,11 +47,11 @@ def method_key
def
base_path_for_exception
@finder
.
find_base_path_for
(
"
#{
@path_without_extension
}
.
#{
@extension
}
"
)
||
@finder
.
view_paths
.
first
end
def
prepare!
@view
.
send
:evaluate_assigns
@view
.
current_render_extension
=
@extension
if
@handler
.
compilable?
@handler
.
compile_template
(
self
)
# compile the given template, if necessary
@method
=
@view
.
method_names
[
method_key
]
# Set the method name for this template and run it
...
...
@@ -58,70 +59,30 @@ def prepare!
end
private
def
set_extension_and_file_name
(
use_full_path
)
@path_without_extension
,
@extension
=
@finder
.
path_and_extension
(
@path
)
if
use_full_path
if
@extension
@filename
=
@finder
.
pick_template
(
@path_without_extension
,
@extension
)
def
set_extension_and_file_name
(
use_full_path
)
@path_without_extension
,
@extension
=
@finder
.
path_and_extension
(
@path
)
if
use_full_path
if
@extension
@filename
=
@finder
.
pick_template
(
@path_without_extension
,
@extension
)
else
@extension
=
@finder
.
pick_template_extension
(
@path
).
to_s
raise_missing_template_exception
unless
@extension
@filename
=
@finder
.
pick_template
(
@path
,
@extension
)
@extension
=
@extension
.
gsub
(
/^.+\./
,
''
)
# strip off any formats
end
else
@extension
=
@finder
.
pick_template_extension
(
@path
).
to_s
raise_missing_template_exception
unless
@extension
@filename
=
@finder
.
pick_template
(
@path
,
@extension
)
@extension
=
@extension
.
gsub
(
/^.+\./
,
''
)
# strip off any formats
@filename
=
@path
end
else
@filename
=
@path
end
raise_missing_template_exception
if
@filename
.
blank?
end
def
raise_missing_template_exception
full_template_path
=
@path
.
include?
(
'.'
)
?
@path
:
"
#{
@path
}
.
#{
@view
.
template_format
}
.erb"
display_paths
=
@finder
.
view_paths
.
join
(
':'
)
template_type
=
(
@path
=~
/layouts/i
)
?
'layout'
:
'template'
raise
(
MissingTemplate
,
"Missing
#{
template_type
}
#{
full_template_path
}
in view path
#{
display_paths
}
"
)
end
# Template Handlers
@@template_handlers
=
HashWithIndifferentAccess
.
new
@@default_template_handlers
=
nil
# Register a class that knows how to handle template files with the given
# extension. This can be used to implement new template types.
# The constructor for the class must take the ActiveView::Base instance
# as a parameter, and the class must implement a +render+ method that
# takes the contents of the template to render as well as the Hash of
# local assigns available to the template. The +render+ method ought to
# return the rendered template as a string.
def
self
.
register_template_handler
(
extension
,
klass
)
@@template_handlers
[
extension
.
to_sym
]
=
klass
ActionView
::
TemplateFinder
.
reload!
end
def
self
.
template_handler_extensions
@@template_handlers
.
keys
.
map
(
&
:to_s
).
sort
end
def
self
.
register_default_template_handler
(
extension
,
klass
)
register_template_handler
(
extension
,
klass
)
@@default_template_handlers
=
klass
end
def
self
.
handler_class_for_extension
(
extension
)
(
extension
&&
@@template_handlers
[
extension
.
to_sym
])
||
@@default_template_handlers
end
register_default_template_handler
:erb
,
TemplateHandlers
::
ERB
register_template_handler
:rjs
,
TemplateHandlers
::
RJS
register_template_handler
:builder
,
TemplateHandlers
::
Builder
raise_missing_template_exception
if
@filename
.
blank?
end
# TODO: Depreciate old template extensions
register_template_handler
:rhtml
,
TemplateHandlers
::
ERB
register_template_handler
:rxml
,
TemplateHandlers
::
Builder
def
raise_missing_template_exception
full_template_path
=
@path
.
include?
(
'.'
)
?
@path
:
"
#{
@path
}
.
#{
@view
.
template_format
}
.erb"
display_paths
=
@finder
.
view_paths
.
join
(
':'
)
template_type
=
(
@path
=~
/layouts/i
)
?
'layout'
:
'template'
raise
(
MissingTemplate
,
"Missing
#{
template_type
}
#{
full_template_path
}
in view path
#{
display_paths
}
"
)
end
end
end
actionpack/lib/action_view/template_handler.rb
浏览文件 @
5ed162d7
module
ActionView
class
TemplateHandler
def
self
.
line_offset
0
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录