Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
dc57d545
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,体验更适合开发者的 AI 搜索 >>
提交
dc57d545
编写于
1月 26, 2010
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Fix t('.helper').
上级
9f63c4b2
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
37 addition
and
26 deletion
+37
-26
actionpack/lib/action_view/base.rb
actionpack/lib/action_view/base.rb
+4
-2
actionpack/lib/action_view/helpers/translation_helper.rb
actionpack/lib/action_view/helpers/translation_helper.rb
+6
-2
actionpack/lib/action_view/template.rb
actionpack/lib/action_view/template.rb
+2
-2
actionpack/lib/action_view/template/resolver.rb
actionpack/lib/action_view/template/resolver.rb
+8
-5
actionpack/test/controller/helper_test.rb
actionpack/test/controller/helper_test.rb
+11
-10
actionpack/test/fixtures/test/translation.erb
actionpack/test/fixtures/test/translation.erb
+1
-0
actionpack/test/template/translation_helper_test.rb
actionpack/test/template/translation_helper_test.rb
+5
-5
未找到文件。
actionpack/lib/action_view/base.rb
浏览文件 @
dc57d545
...
...
@@ -276,9 +276,11 @@ def initialize(view_paths = [], assigns_for_first_render = {}, controller = nil,
@config
=
nil
@formats
=
formats
@assigns
=
assigns_for_first_render
.
each
{
|
key
,
value
|
instance_variable_set
(
"@
#{
key
}
"
,
value
)
}
@_controller
=
controller
@helpers
=
self
.
class
.
helpers
||
Module
.
new
@_content_for
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
ActionView
::
SafeBuffer
.
new
}
@_controller
=
controller
@_content_for
=
Hash
.
new
{
|
h
,
k
|
h
[
k
]
=
ActionView
::
SafeBuffer
.
new
}
@_virtual_path
=
nil
self
.
view_paths
=
view_paths
end
...
...
actionpack/lib/action_view/helpers/translation_helper.rb
浏览文件 @
dc57d545
...
...
@@ -25,11 +25,15 @@ def localize(*args)
end
alias
:l
:localize
private
def
scope_key_by_partial
(
key
)
if
key
.
to_s
.
first
==
"."
template
.
path_without_format_and_extension
.
gsub
(
%r{/_?}
,
"."
)
+
key
.
to_s
if
@_virtual_path
@_virtual_path
.
gsub
(
%r{/_?}
,
"."
)
+
key
.
to_s
else
raise
"Cannot use t(
#{
key
.
inspect
}
) shortcut because path is not available"
end
else
key
end
...
...
actionpack/lib/action_view/template.rb
浏览文件 @
dc57d545
...
...
@@ -87,9 +87,9 @@ def compile(locals, view)
source
=
<<-
end_src
def
#{
method_name
}
(local_assigns)
old_output_buffer = output_buffer;
#{
locals_code
}
;
#{
code
}
_old_virtual_path, @_virtual_path = @_virtual_path,
#{
@details
[
:virtual_path
].
inspect
}
;_
old_output_buffer = output_buffer;
#{
locals_code
}
;
#{
code
}
ensure
self.output_buffer =
old_output_buffer
@_virtual_path, self.output_buffer = _old_virtual_path, _
old_output_buffer
end
end_src
...
...
actionpack/lib/action_view/template/resolver.rb
浏览文件 @
dc57d545
...
...
@@ -117,15 +117,18 @@ def query(path, exts)
# # :api: plugin
def
path_to_details
(
path
)
# [:erb, :format => :html, :locale => :en, :partial => true/false]
if
m
=
path
.
match
(
%r'(
?:^|/)(_)?[
\w
-]+
((?:
\.
[
\w
-]+)*)
\.
(
\w
+)$'
)
partial
=
m
[
1
]
==
'_'
details
=
(
m
[
2
]
||
""
).
split
(
'.'
).
reject
{
|
e
|
e
.
empty?
}
handler
=
Template
.
handler_class_for_extension
(
m
[
3
])
if
m
=
path
.
match
(
%r'(
(^|.*/)(_)?[
\w
-]+)
((?:
\.
[
\w
-]+)*)
\.
(
\w
+)$'
)
partial
=
m
[
3
]
==
'_'
details
=
(
m
[
4
]
||
""
).
split
(
'.'
).
reject
{
|
e
|
e
.
empty?
}
handler
=
Template
.
handler_class_for_extension
(
m
[
5
])
format
=
Mime
[
details
.
last
]
&&
details
.
pop
.
to_sym
locale
=
details
.
last
&&
details
.
pop
.
to_sym
return
handler
,
:format
=>
format
,
:locale
=>
locale
,
:partial
=>
partial
virtual_path
=
(
m
[
1
].
gsub
(
"
#{
@path
}
/"
,
""
)
<<
details
.
join
(
"."
))
return
handler
,
:format
=>
format
,
:locale
=>
locale
,
:partial
=>
partial
,
:virtual_path
=>
virtual_path
end
end
end
...
...
actionpack/test/controller/helper_test.rb
浏览文件 @
dc57d545
...
...
@@ -135,16 +135,17 @@ def test_helper_proxy
assert
methods
.
include?
(
'foobar'
)
end
def
test_deprecation
assert_deprecated
do
ActionController
::
Base
.
helpers_dir
=
"some/foo/bar"
end
assert_deprecated
do
assert_equal
[
"some/foo/bar"
],
ActionController
::
Base
.
helpers_dir
end
ensure
ActionController
::
Base
.
helpers_path
=
[
File
.
dirname
(
__FILE__
)
+
'/../fixtures/helpers'
]
end
# TODO Add this deprecation back before Rails 3.0 final release
# def test_deprecation
# assert_deprecated do
# ActionController::Base.helpers_dir = "some/foo/bar"
# end
# assert_deprecated do
# assert_equal ["some/foo/bar"], ActionController::Base.helpers_dir
# end
# ensure
# ActionController::Base.helpers_path = [File.dirname(__FILE__) + '/../fixtures/helpers']
# end
private
def
expected_helper_methods
...
...
actionpack/test/fixtures/test/translation.erb
0 → 100644
浏览文件 @
dc57d545
<%=
t
(
'.helper'
)
%>
\ No newline at end of file
actionpack/test/template/translation_helper_test.rb
浏览文件 @
dc57d545
require
'abstract_unit'
class
TranslationHelperTest
<
Test
::
Uni
t
::
TestCase
class
TranslationHelperTest
<
ActiveSuppor
t
::
TestCase
include
ActionView
::
Helpers
::
TagHelper
include
ActionView
::
Helpers
::
TranslationHelper
attr_reader
:request
def
setup
end
...
...
@@ -25,8 +25,8 @@ def test_delegates_localize_to_i18n
end
def
test_scoping_by_partial
expects
(
:template
).
returns
(
stub
(
:path_without_format_and_extension
=>
"people/index"
)
)
I18n
.
expects
(
:translate
).
with
(
"people.index.foo"
,
:locale
=>
'en'
,
:raise
=>
true
).
returns
(
""
)
translate
".foo"
,
:locale
=>
'en'
I18n
.
expects
(
:translate
).
with
(
"test.translation.helper"
,
:raise
=>
true
).
returns
(
"helper"
)
@view
=
ActionView
::
Base
.
new
(
ActionController
::
Base
.
view_paths
,
{}
)
assert_equal
"helper"
,
@view
.
render
(
:file
=>
"test/translation"
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录