Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
b98e496c
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,发现更多精彩内容 >>
提交
b98e496c
编写于
4月 29, 2009
作者:
Y
Yehuda Katz + Carl Lerche
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Support implicit and explicit content types
上级
49834e08
变更
6
显示空白变更内容
内联
并排
Showing
6 changed file
with
139 addition
and
2 deletion
+139
-2
actionpack/lib/action_controller/new_base.rb
actionpack/lib/action_controller/new_base.rb
+1
-0
actionpack/lib/action_controller/new_base/content_type.rb
actionpack/lib/action_controller/new_base/content_type.rb
+15
-0
actionpack/lib/action_view/template/text.rb
actionpack/lib/action_view/template/text.rb
+1
-2
actionpack/test/controller/content_type_test.rb
actionpack/test/controller/content_type_test.rb
+10
-0
actionpack/test/new_base/content_type_test.rb
actionpack/test/new_base/content_type_test.rb
+111
-0
actionpack/test/new_base/test_helper.rb
actionpack/test/new_base/test_helper.rb
+1
-0
未找到文件。
actionpack/lib/action_controller/new_base.rb
浏览文件 @
b98e496c
module
ActionController
autoload
:ContentType
,
"action_controller/new_base/content_type"
autoload
:HideActions
,
"action_controller/new_base/hide_actions"
autoload
:Http
,
"action_controller/new_base/base"
autoload
:Layouts
,
"action_controller/new_base/layouts"
...
...
actionpack/lib/action_controller/new_base/content_type.rb
0 → 100644
浏览文件 @
b98e496c
module
ActionController
module
ContentType
def
render_to_body
(
options
=
{})
if
content_type
=
options
[
:content_type
]
response
.
content_type
=
content_type
end
ret
=
super
response
.
content_type
||=
options
[
:_template
].
mime_type
ret
end
end
end
\ No newline at end of file
actionpack/lib/action_view/template/text.rb
浏览文件 @
b98e496c
...
...
@@ -3,7 +3,6 @@ class TextTemplate < String #:nodoc:
def
render
(
*
)
self
end
def
exempt_from_layout?
()
false
end
def
mime_type
()
Mime
::
HTML
end
end
end
actionpack/test/controller/content_type_test.rb
浏览文件 @
b98e496c
require
'abstract_unit'
class
ContentTypeController
<
ActionController
::
Base
# :ported:
def
render_content_type_from_body
response
.
content_type
=
Mime
::
RSS
render
:text
=>
"hello world!"
end
# :ported:
def
render_defaults
render
:text
=>
"hello world!"
end
# :ported:
def
render_content_type_from_render
render
:text
=>
"hello world!"
,
:content_type
=>
Mime
::
RSS
end
# :ported:
def
render_charset_from_body
response
.
charset
=
"utf-16"
render
:text
=>
"hello world!"
end
# :ported:
def
render_nil_charset_from_body
response
.
charset
=
nil
render
:text
=>
"hello world!"
...
...
@@ -60,6 +65,7 @@ def setup
@controller
.
logger
=
Logger
.
new
(
nil
)
end
# :ported:
def
test_render_defaults
get
:render_defaults
assert_equal
"utf-8"
,
@response
.
charset
...
...
@@ -74,24 +80,28 @@ def test_render_changed_charset_default
ContentTypeController
.
default_charset
=
"utf-8"
end
# :ported:
def
test_content_type_from_body
get
:render_content_type_from_body
assert_equal
"application/rss+xml"
,
@response
.
content_type
assert_equal
"utf-8"
,
@response
.
charset
end
# :ported:
def
test_content_type_from_render
get
:render_content_type_from_render
assert_equal
"application/rss+xml"
,
@response
.
content_type
assert_equal
"utf-8"
,
@response
.
charset
end
# :ported:
def
test_charset_from_body
get
:render_charset_from_body
assert_equal
Mime
::
HTML
,
@response
.
content_type
assert_equal
"utf-16"
,
@response
.
charset
end
# :ported:
def
test_nil_charset_from_body
get
:render_nil_charset_from_body
assert_equal
Mime
::
HTML
,
@response
.
content_type
...
...
actionpack/test/new_base/content_type_test.rb
0 → 100644
浏览文件 @
b98e496c
require
File
.
join
(
File
.
expand_path
(
File
.
dirname
(
__FILE__
)),
"test_helper"
)
module
ContentType
class
BaseController
<
ActionController
::
Base2
def
index
render
:text
=>
"Hello world!"
end
def
set_on_response_obj
response
.
content_type
=
Mime
::
RSS
render
:text
=>
"Hello world!"
end
def
set_on_render
render
:text
=>
"Hello world!"
,
:content_type
=>
Mime
::
RSS
end
end
class
TestDefault
<
SimpleRouteCase
describe
"a default response is HTML and UTF8"
get
"/content_type/base"
assert_body
"Hello world!"
assert_header
"Content-Type"
,
"text/html; charset=utf-8"
end
class
TestSetOnResponseObj
<
SimpleRouteCase
describe
"setting the content type of the response directly on the response object"
get
"/content_type/base/set_on_response_obj"
assert_body
"Hello world!"
assert_header
"Content-Type"
,
"application/rss+xml; charset=utf-8"
end
class
TestSetOnRender
<
SimpleRouteCase
describe
"setting the content type of the response as an option to render"
get
"/content_type/base/set_on_render"
assert_body
"Hello world!"
assert_header
"Content-Type"
,
"application/rss+xml; charset=utf-8"
end
class
ImpliedController
<
ActionController
::
Base2
self
.
view_paths
=
[
ActionView
::
Template
::
FixturePath
.
new
(
"content_type/implied/i_am_html_erb.html.erb"
=>
"Hello world!"
,
"content_type/implied/i_am_xml_erb.xml.erb"
=>
"<xml>Hello world!</xml>"
,
"content_type/implied/i_am_html_builder.html.builder"
=>
"xml.p 'Hello'"
,
"content_type/implied/i_am_xml_builder.xml.builder"
=>
"xml.awesome 'Hello'"
)]
def
i_am_html_erb
()
end
def
i_am_xml_erb
()
end
def
i_am_html_builder
()
end
def
i_am_xml_builder
()
end
end
class
TestImpliedController
<
SimpleRouteCase
describe
"the template's mime type is used if no content_type is specified"
test
"sets Content-Type as text/html when rendering *.html.erb"
do
get
"/content_type/implied/i_am_html_erb"
assert_header
"Content-Type"
,
"text/html; charset=utf-8"
end
test
"sets Content-Type as application/xml when rendering *.xml.erb"
do
get
"/content_type/implied/i_am_xml_erb"
assert_header
"Content-Type"
,
"application/xml; charset=utf-8"
end
test
"sets Content-Type as text/html when rendering *.html.builder"
do
get
"/content_type/implied/i_am_html_builder"
assert_header
"Content-Type"
,
"text/html; charset=utf-8"
end
test
"sets Content-Type as application/xml when rendering *.xml.builder"
do
get
"/content_type/implied/i_am_xml_builder"
assert_header
"Content-Type"
,
"application/xml; charset=utf-8"
end
end
end
module
Charset
class
BaseController
<
ActionController
::
Base2
def
set_on_response_obj
response
.
charset
=
"utf-16"
render
:text
=>
"Hello world!"
end
def
set_as_nil_on_response_obj
response
.
charset
=
nil
render
:text
=>
"Hello world!"
end
end
class
TestSetOnResponseObj
<
SimpleRouteCase
describe
"setting the charset of the response directly on the response object"
get
"/charset/base/set_on_response_obj"
assert_body
"Hello world!"
assert_header
"Content-Type"
,
"text/html; charset=utf-16"
end
class
TestSetAsNilOnResponseObj
<
SimpleRouteCase
describe
"setting the charset of the response as nil directly on the response object"
get
"/charset/base/set_as_nil_on_response_obj"
assert_body
"Hello world!"
assert_header
"Content-Type"
,
"text/html; charset=utf-8"
end
end
\ No newline at end of file
actionpack/test/new_base/test_helper.rb
浏览文件 @
b98e496c
...
...
@@ -42,6 +42,7 @@ class Base2 < Http
use
ActionController
::
UrlFor
use
ActionController
::
Renderer
use
ActionController
::
Layouts
use
ActionController
::
ContentType
def
self
.
inherited
(
klass
)
::
ActionController
::
Base2
.
subclasses
<<
klass
.
to_s
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录