Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
97b77330
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,发现更多精彩内容 >>
提交
97b77330
编写于
6月 23, 2010
作者:
J
Josh Kalderimis
提交者:
José Valim
6月 23, 2010
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
refactored the javascript asset tag helpers and moved the default scripts setup within the railtie
Signed-off-by:
N
José Valim
<
jose.valim@gmail.com
>
上级
a6eeb086
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
21 addition
and
29 deletion
+21
-29
actionpack/lib/action_view/helpers/asset_tag_helper.rb
actionpack/lib/action_view/helpers/asset_tag_helper.rb
+5
-14
actionpack/lib/action_view/railtie.rb
actionpack/lib/action_view/railtie.rb
+9
-0
actionpack/test/template/asset_tag_helper_test.rb
actionpack/test/template/asset_tag_helper_test.rb
+7
-15
未找到文件。
actionpack/lib/action_view/helpers/asset_tag_helper.rb
浏览文件 @
97b77330
...
...
@@ -194,7 +194,6 @@ module Helpers #:nodoc:
# RewriteEngine On
# RewriteRule ^/release-\d+/(images|javascripts|stylesheets)/(.*)$ /$1/$2 [L]
module
AssetTagHelper
JAVASCRIPT_DEFAULT_SOURCES
=
[
'prototype'
,
'effects'
,
'dragdrop'
,
'controls'
,
'rails'
].
freeze
# Returns a link tag that browsers and news readers can use to auto-detect
# an RSS or ATOM feed. The +type+ can either be <tt>:rss</tt> (default) or
...
...
@@ -351,7 +350,7 @@ def javascript_include_tag(*sources)
end
end
@@javascript_expansions
=
{
:defaults
=>
JAVASCRIPT_DEFAULT_SOURCES
.
dup
}
@@javascript_expansions
=
{
}
# Register one or more javascript files to be included when <tt>symbol</tt>
# is passed to <tt>javascript_include_tag</tt>. This method is typically intended
...
...
@@ -368,6 +367,10 @@ def self.register_javascript_expansion(expansions)
@@javascript_expansions
.
merge!
(
expansions
)
end
def
self
.
reset_javascript_expansions
#:nodoc:
@@javascript_expansions
=
{}
end
@@stylesheet_expansions
=
{}
# Register one or more stylesheet files to be included when <tt>symbol</tt>
...
...
@@ -385,18 +388,6 @@ def self.register_stylesheet_expansion(expansions)
@@stylesheet_expansions
.
merge!
(
expansions
)
end
# Register one or more additional JavaScript files to be included when
# <tt>javascript_include_tag :defaults</tt> is called. This method is
# typically intended to be called from plugin initialization to register additional
# .js files that the plugin installed in <tt>public/javascripts</tt>.
def
self
.
register_javascript_include_default
(
*
sources
)
@@javascript_expansions
[
:defaults
].
concat
(
sources
)
end
def
self
.
reset_javascript_include_default
#:nodoc:
@@javascript_expansions
[
:defaults
]
=
JAVASCRIPT_DEFAULT_SOURCES
.
dup
end
# Computes the path to a stylesheet asset in the public stylesheets directory.
# If the +source+ filename has no extension, <tt>.css</tt> will be appended (except for explicit URIs).
# Full paths from the document root will be passed through.
...
...
actionpack/lib/action_view/railtie.rb
浏览文件 @
97b77330
...
...
@@ -6,6 +6,9 @@ module ActionView
class
Railtie
<
Rails
::
Railtie
config
.
action_view
=
ActiveSupport
::
OrderedOptions
.
new
# setup default js includes
config
.
action_view
.
javascript_expansions
=
{
:defaults
=>
[
'prototype'
,
'effects'
,
'dragdrop'
,
'controls'
,
'rails'
]
}
require
"action_view/railties/log_subscriber"
log_subscriber
:action_view
,
ActionView
::
Railties
::
LogSubscriber
.
new
...
...
@@ -17,6 +20,12 @@ class Railtie < Rails::Railtie
end
end
initializer
"action_view.javascript_expansions"
do
|
app
|
ActiveSupport
.
on_load
(
:action_view
)
do
ActionView
::
Helpers
::
AssetTagHelper
.
register_javascript_expansion
(
app
.
config
.
action_view
.
javascript_expansions
)
end
end
initializer
"action_view.set_configs"
do
|
app
|
ActiveSupport
.
on_load
(
:action_view
)
do
app
.
config
.
action_view
.
each
do
|
k
,
v
|
...
...
actionpack/test/template/asset_tag_helper_test.rb
浏览文件 @
97b77330
...
...
@@ -44,7 +44,7 @@ def host_with_port() 'localhost' end
@controller
.
request
=
@request
ActionView
::
Helpers
::
AssetTagHelper
::
re
set_javascript_include_default
ActionView
::
Helpers
::
AssetTagHelper
::
re
gister_javascript_expansion
:defaults
=>
[
'prototype'
,
'effects'
,
'dragdrop'
,
'controls'
,
'rails'
]
end
def
url_for
(
*
args
)
...
...
@@ -256,19 +256,6 @@ def test_javascript_include_tag_is_html_safe
assert
javascript_include_tag
(
"prototype"
).
html_safe?
end
def
test_register_javascript_include_default
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'bank'
assert_dom_equal
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/rails.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
javascript_include_tag
(
:defaults
)
end
def
test_register_javascript_include_default_mixed_defaults
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'bank'
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_include_default
'robber'
,
'/elsewhere/cools.js'
assert_dom_equal
%(<script src="/javascripts/prototype.js" type="text/javascript"></script>\n<script src="/javascripts/effects.js" type="text/javascript"></script>\n<script src="/javascripts/dragdrop.js" type="text/javascript"></script>\n<script src="/javascripts/controls.js" type="text/javascript"></script>\n<script src="/javascripts/rails.js" type="text/javascript"></script>\n<script src="/javascripts/bank.js" type="text/javascript"></script>\n<script src="/javascripts/robber.js" type="text/javascript"></script>\n<script src="/elsewhere/cools.js" type="text/javascript"></script>\n<script src="/javascripts/application.js" type="text/javascript"></script>)
,
javascript_include_tag
(
:defaults
)
end
def
test_custom_javascript_expansions
ENV
[
"RAILS_ASSET_ID"
]
=
""
ActionView
::
Helpers
::
AssetTagHelper
::
register_javascript_expansion
:robbery
=>
[
"bank"
,
"robber"
]
...
...
@@ -286,6 +273,11 @@ def test_custom_javascript_expansions_with_undefined_symbol
assert_raise
(
ArgumentError
)
{
javascript_include_tag
(
'first'
,
:monkey
,
'last'
)
}
end
def
test_reset_javascript_expansions
ActionView
::
Helpers
::
AssetTagHelper
::
reset_javascript_expansions
assert_raise
(
ArgumentError
)
{
javascript_include_tag
(
:defaults
)
}
end
def
test_stylesheet_path
ENV
[
"RAILS_ASSET_ID"
]
=
""
StylePathToTag
.
each
{
|
method
,
tag
|
assert_dom_equal
(
tag
,
eval
(
method
))
}
...
...
@@ -923,7 +915,7 @@ def setup
@request
=
Struct
.
new
(
:protocol
).
new
(
"gopher://"
)
@controller
.
request
=
@request
ActionView
::
Helpers
::
AssetTagHelper
::
reset_javascript_
include_default
ActionView
::
Helpers
::
AssetTagHelper
::
reset_javascript_
expansions
end
def
url_for
(
options
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录