Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
7b63f56c
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,发现更多精彩内容 >>
提交
7b63f56c
编写于
10月 02, 2016
作者:
M
Matthew Draper
提交者:
GitHub
10月 02, 2016
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #26672 from schpet/support_ruby_keywords_as_template_locals
Avoid compiling ruby keywords into template locals
上级
832b0262
f9960f2d
变更
6
隐藏空白更改
内联
并排
Showing
6 changed file
with
47 addition
and
1 deletion
+47
-1
actionview/CHANGELOG.md
actionview/CHANGELOG.md
+18
-0
actionview/lib/action_view/template.rb
actionview/lib/action_view/template.rb
+7
-1
actionview/test/fixtures/test/render_file_inspect_local_assigns.erb
.../test/fixtures/test/render_file_inspect_local_assigns.erb
+1
-0
actionview/test/fixtures/test/render_file_unicode_local.erb
actionview/test/fixtures/test/render_file_unicode_local.erb
+1
-0
actionview/test/fixtures/test/render_file_with_ruby_keyword_locals.erb
...st/fixtures/test/render_file_with_ruby_keyword_locals.erb
+1
-0
actionview/test/template/compiled_templates_test.rb
actionview/test/template/compiled_templates_test.rb
+19
-0
未找到文件。
actionview/CHANGELOG.md
浏览文件 @
7b63f56c
*
Render now accepts any keys for locals, including reserved words
Only locals with valid variable names get set directly. Others
will still be available in local_assigns.
Example of render with reserved words:
```erb
<%= render "example", class: "text-center", message: "Hello world!" %>
<!-- _example.html.erb: -->
<%= tag.div class: local_assigns[:class] do %>
<p><%= message %></p>
<% end %>
```
*Peter Schilling*, *Matthew Draper*
*
Show cache hits and misses when rendering partials.
Partials using the `cache` helper will show whether a render hit or missed
...
...
actionview/lib/action_view/template.rb
浏览文件 @
7b63f56c
require
"active_support/core_ext/object/try"
require
"active_support/core_ext/kernel/singleton_class"
require
"active_support/core_ext/module/delegation"
require
"thread"
module
ActionView
...
...
@@ -324,8 +325,13 @@ def handle_render_error(view, e) #:nodoc:
end
def
locals_code
#:nodoc:
# Only locals with valid variable names get set directly. Others will
# still be available in local_assigns.
locals
=
@locals
.
to_set
-
Module
::
DELEGATION_RESERVED_METHOD_NAMES
locals
=
locals
.
grep
(
/\A(?![A-Z0-9])(?:[[:alnum:]_]|[^\0-\177])+\z/
)
# Double assign to suppress the dreaded 'assigned but unused variable' warning
@
locals
.
each_with_object
(
""
)
{
|
key
,
code
|
code
<<
"
#{
key
}
=
#{
key
}
= local_assigns[:
#{
key
}
];"
}
locals
.
each_with_object
(
""
)
{
|
key
,
code
|
code
<<
"
#{
key
}
=
#{
key
}
= local_assigns[:
#{
key
}
];"
}
end
def
method_name
#:nodoc:
...
...
actionview/test/fixtures/test/render_file_inspect_local_assigns.erb
0 → 100644
浏览文件 @
7b63f56c
<%=
local_assigns
.
inspect
.
html_safe
%>
\ No newline at end of file
actionview/test/fixtures/test/render_file_unicode_local.erb
0 → 100644
浏览文件 @
7b63f56c
<%=
🎃
%>
\ No newline at end of file
actionview/test/fixtures/test/render_file_with_ruby_keyword_locals.erb
0 → 100644
浏览文件 @
7b63f56c
The class is
<%=
local_assigns
[
:class
]
%>
\ No newline at end of file
actionview/test/template/compiled_templates_test.rb
浏览文件 @
7b63f56c
...
...
@@ -9,6 +9,25 @@ def test_template_with_nil_erb_return
assert_equal
"This is nil:
\n
"
,
render
(
template:
"test/nil_return"
)
end
def
test_template_with_ruby_keyword_locals
assert_equal
"The class is foo"
,
render
(
file:
"test/render_file_with_ruby_keyword_locals"
,
locals:
{
class:
"foo"
})
end
def
test_template_with_invalid_identifier_locals
locals
=
{
foo:
"bar"
,
Foo
:
"bar"
,
"d-a-s-h-e-s"
:
""
,
"white space"
:
""
,
}
assert_equal
locals
.
inspect
,
render
(
file:
"test/render_file_inspect_local_assigns"
,
locals:
locals
)
end
def
test_template_with_unicode_identifier
assert_equal
"🎂"
,
render
(
file:
"test/render_file_unicode_local"
,
locals:
{
🎃
:
"🎂"
})
end
def
test_template_gets_recompiled_when_using_different_keys_in_local_assigns
assert_equal
"one"
,
render
(
file:
"test/render_file_with_locals_and_default"
)
assert_equal
"two"
,
render
(
file:
"test/render_file_with_locals_and_default"
,
locals:
{
secret:
"two"
})
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录