Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
e693f45e
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,发现更多精彩内容 >>
提交
e693f45e
编写于
5月 21, 2009
作者:
Y
Yehuda Katz + Carl Lerche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Remove some response content type concepts from ActionView
上级
386ff66e
变更
13
隐藏空白更改
内联
并排
Showing
13 changed file
with
63 addition
and
29 deletion
+63
-29
actionpack/lib/action_controller/base/mime_responds.rb
actionpack/lib/action_controller/base/mime_responds.rb
+3
-4
actionpack/lib/action_controller/new_base/base.rb
actionpack/lib/action_controller/new_base/base.rb
+16
-4
actionpack/lib/action_controller/new_base/renderer.rb
actionpack/lib/action_controller/new_base/renderer.rb
+11
-9
actionpack/lib/action_controller/testing/process2.rb
actionpack/lib/action_controller/testing/process2.rb
+1
-0
actionpack/lib/action_dispatch/http/mime_type.rb
actionpack/lib/action_dispatch/http/mime_type.rb
+1
-1
actionpack/lib/action_dispatch/http/request.rb
actionpack/lib/action_dispatch/http/request.rb
+1
-1
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/base.rb
+5
-2
actionpack/lib/action_view/template/handler.rb
actionpack/lib/action_view/template/handler.rb
+5
-0
actionpack/lib/action_view/template/handlers/builder.rb
actionpack/lib/action_view/template/handlers/builder.rb
+2
-0
actionpack/lib/action_view/template/handlers/erb.rb
actionpack/lib/action_view/template/handlers/erb.rb
+2
-0
actionpack/lib/action_view/template/handlers/rjs.rb
actionpack/lib/action_view/template/handlers/rjs.rb
+6
-0
actionpack/lib/action_view/template/template.rb
actionpack/lib/action_view/template/template.rb
+8
-7
actionpack/test/controller/content_type_test.rb
actionpack/test/controller/content_type_test.rb
+2
-1
未找到文件。
actionpack/lib/action_controller/base/mime_responds.rb
浏览文件 @
e693f45e
...
...
@@ -122,12 +122,11 @@ def custom(mime_type, &block)
# TODO: Remove this when new base is merged in
if
defined?
(
Http
)
@controller
.
formats
=
[
mime_type
.
to_sym
]
@controller
.
template
.
formats
=
[
mime_type
.
to_sym
]
else
@controller
.
template
.
formats
=
[
mime_type
.
to_sym
]
@response
.
content_type
=
mime_type
.
to_s
end
@controller
.
template
.
formats
=
[
mime_type
.
to_sym
]
@response
.
content_type
=
mime_type
.
to_s
block_given?
?
block
.
call
:
@controller
.
send
(
:render
,
:action
=>
@controller
.
action_name
)
end
end
...
...
actionpack/lib/action_controller/new_base/base.rb
浏览文件 @
e693f45e
...
...
@@ -70,7 +70,7 @@ def self.app_loaded!
end
end
def
render_to_body
(
action
=
nil
,
options
=
{})
def
_normalize_options
(
action
=
nil
,
options
=
{})
if
action
.
is_a?
(
Hash
)
options
,
action
=
action
,
nil
elsif
action
.
is_a?
(
String
)
||
action
.
is_a?
(
Symbol
)
...
...
@@ -87,9 +87,21 @@ def render_to_body(action = nil, options = {})
if
options
.
key?
(
:action
)
&&
options
[
:action
].
to_s
.
index
(
"/"
)
options
[
:template
]
=
options
.
delete
(
:action
)
end
# options = {:template => options.to_s} if options.is_a?(String) || options.is_a?(Symbol)
super
(
options
)
||
" "
options
end
def
render
(
action
=
nil
,
options
=
{})
options
=
_normalize_options
(
action
,
options
)
super
(
options
)
end
def
render_to_string
(
action
=
nil
,
options
=
{})
options
=
_normalize_options
(
action
,
options
)
super
(
options
)
end
def
render_to_body
(
options
)
super
||
[
" "
]
end
# Redirects the browser to the target specified in +options+. This parameter can take one of three forms:
...
...
actionpack/lib/action_controller/new_base/renderer.rb
浏览文件 @
e693f45e
...
...
@@ -14,6 +14,16 @@ def response_body=(body)
super
end
def
render
(
options
)
super
options
[
:_template
]
||=
_action_view
.
_partial
response
.
content_type
||=
begin
mime
=
options
[
:_template
].
mime_type
formats
.
include?
(
mime
&&
mime
.
to_sym
)
||
formats
.
include?
(
:all
)
?
mime
:
Mime
::
Type
.
lookup_by_extension
(
formats
.
first
)
end
response_body
end
def
render_to_body
(
options
)
_process_options
(
options
)
...
...
@@ -35,15 +45,7 @@ def render_to_body(options)
options
[
:_prefix
]
=
_prefix
end
ret
=
super
(
options
)
options
[
:_template
]
||=
_action_view
.
_partial
response
.
content_type
||=
begin
mime
=
options
[
:_template
].
mime_type
mime
&&=
mime
.
to_sym
formats
.
include?
(
mime
)
?
mime
:
formats
.
first
end
ret
super
end
private
...
...
actionpack/lib/action_controller/testing/process2.rb
浏览文件 @
e693f45e
...
...
@@ -40,6 +40,7 @@ def process(action, parameters = nil, session = nil, flash = nil, http_method =
@request
.
recycle!
@response
.
recycle!
@controller
.
response_body
=
nil
@controller
.
formats
=
nil
@html_document
=
nil
@request
.
env
[
'REQUEST_METHOD'
]
=
http_method
...
...
actionpack/lib/action_dispatch/http/mime_type.rb
浏览文件 @
e693f45e
...
...
@@ -3,7 +3,7 @@
module
Mime
SET
=
[]
EXTENSION_LOOKUP
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
Type
.
new
(
k
)
unless
k
.
blank?
}
EXTENSION_LOOKUP
=
{
}
LOOKUP
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
Type
.
new
(
k
)
unless
k
.
blank?
}
def
self
.
[]
(
type
)
...
...
actionpack/lib/action_dispatch/http/request.rb
浏览文件 @
e693f45e
...
...
@@ -175,7 +175,7 @@ def formats
if
ActionController
::
Base
.
use_accept_header
Array
(
Mime
[
parameters
[
:format
]]
||
accepts
)
else
[
format
]
[
format
,
Mime
[
:all
]
]
end
end
...
...
actionpack/lib/action_view/base.rb
浏览文件 @
e693f45e
...
...
@@ -288,8 +288,11 @@ def _copy_ivars_from_controller #:nodoc:
end
def
_set_controller_content_type
(
content_type
)
#:nodoc:
if
controller
.
respond_to?
(
:response
)
controller
.
response
.
content_type
||=
content_type
# TODO: Remove this method when new base is switched
unless
defined?
(
ActionController
::
Http
)
if
controller
.
respond_to?
(
:response
)
controller
.
response
.
content_type
||=
content_type
end
end
end
end
...
...
actionpack/lib/action_view/template/handler.rb
浏览文件 @
e693f45e
require
"active_support/core_ext/class/inheritable_attributes"
# Legacy TemplateHandler stub
module
ActionView
module
TemplateHandlers
#:nodoc:
...
...
@@ -19,6 +21,9 @@ def compile(template)
end
class
TemplateHandler
extlib_inheritable_accessor
:default_format
self
.
default_format
=
Mime
::
HTML
def
self
.
call
(
template
)
"
#{
name
}
.new(self).render(template, local_assigns)"
end
...
...
actionpack/lib/action_view/template/handlers/builder.rb
浏览文件 @
e693f45e
...
...
@@ -5,6 +5,8 @@ module TemplateHandlers
class
Builder
<
TemplateHandler
include
Compilable
self
.
default_format
=
Mime
::
XML
def
compile
(
template
)
"_set_controller_content_type(Mime::XML);"
+
"xml = ::Builder::XmlMarkup.new(:indent => 2);"
+
...
...
actionpack/lib/action_view/template/handlers/erb.rb
浏览文件 @
e693f45e
...
...
@@ -13,6 +13,8 @@ class ERB < TemplateHandler
cattr_accessor
:erb_trim_mode
self
.
erb_trim_mode
=
'-'
self
.
default_format
=
Mime
::
HTML
def
compile
(
template
)
src
=
::
ERB
.
new
(
"<% __in_erb_template=true %>
#{
template
.
source
}
"
,
nil
,
erb_trim_mode
,
'@output_buffer'
).
src
...
...
actionpack/lib/action_view/template/handlers/rjs.rb
浏览文件 @
e693f45e
...
...
@@ -3,11 +3,17 @@ module TemplateHandlers
class
RJS
<
TemplateHandler
include
Compilable
self
.
default_format
=
Mime
::
JS
def
compile
(
template
)
"@formats = [:html];"
+
"controller.response.content_type ||= Mime::JS;"
+
"update_page do |page|;
#{
template
.
source
}
\n
end"
end
def
default_format
Mime
::
JS
end
end
end
end
actionpack/lib/action_view/template/template.rb
浏览文件 @
e693f45e
...
...
@@ -7,13 +7,19 @@
module
ActionView
class
Template
extend
TemplateHandlers
attr_reader
:source
,
:identifier
,
:handler
attr_reader
:source
,
:identifier
,
:handler
,
:mime_type
def
initialize
(
source
,
identifier
,
handler
,
details
)
@source
=
source
@identifier
=
identifier
@handler
=
handler
@details
=
details
format
=
details
[
:format
]
||
begin
# TODO: Clean this up
handler
.
respond_to?
(
:default_format
)
?
handler
.
default_format
.
to_sym
.
to_s
:
"html"
end
@mime_type
=
Mime
::
Type
.
lookup_by_extension
(
format
.
to_s
)
end
def
render
(
view
,
locals
,
&
blk
)
...
...
@@ -35,12 +41,7 @@ def counter_name
def
partial?
@details
[
:partial
]
end
# TODO: Move out of Template
def
mime_type
Mime
::
Type
.
lookup_by_extension
(
@details
[
:format
].
to_s
)
if
@details
[
:format
]
end
private
def
compile
(
locals
,
view
)
...
...
actionpack/test/controller/content_type_test.rb
浏览文件 @
e693f45e
...
...
@@ -148,12 +148,13 @@ class AcceptBasedContentTypeTest < ActionController::TestCase
def
setup
super
@_old_accept_header
=
ActionController
::
Base
.
use_accept_header
ActionController
::
Base
.
use_accept_header
=
true
end
def
teardown
super
ActionController
::
Base
.
use_accept_header
=
false
ActionController
::
Base
.
use_accept_header
=
@_old_accept_header
end
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录