Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
6601917a
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,发现更多精彩内容 >>
提交
6601917a
编写于
10月 15, 2012
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Extract compute_asset_extname and allow extname to be disabled
上级
9d412388
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
30 addition
and
13 deletion
+30
-13
actionpack/lib/action_view/helpers/asset_url_helper.rb
actionpack/lib/action_view/helpers/asset_url_helper.rb
+15
-7
actionpack/test/template/asset_tag_helper_test.rb
actionpack/test/template/asset_tag_helper_test.rb
+15
-6
未找到文件。
actionpack/lib/action_view/helpers/asset_url_helper.rb
浏览文件 @
6601917a
...
@@ -107,11 +107,6 @@ module Helpers #:nodoc:
...
@@ -107,11 +107,6 @@ module Helpers #:nodoc:
module
AssetUrlHelper
module
AssetUrlHelper
URI_REGEXP
=
%r{^[-a-z]+://|^(?:cid|data):|^//}
URI_REGEXP
=
%r{^[-a-z]+://|^(?:cid|data):|^//}
ASSET_EXTENSIONS
=
{
javascript:
'.js'
,
stylesheet:
'.css'
}
# Computes the path to asset in public directory. If :type
# Computes the path to asset in public directory. If :type
# options is set, a file extension will be appended and scoped
# options is set, a file extension will be appended and scoped
# to the corresponding public directory.
# to the corresponding public directory.
...
@@ -127,8 +122,8 @@ def asset_path(source, options = {})
...
@@ -127,8 +122,8 @@ def asset_path(source, options = {})
return
""
unless
source
.
present?
return
""
unless
source
.
present?
return
source
if
source
=~
URI_REGEXP
return
source
if
source
=~
URI_REGEXP
if
File
.
extname
(
source
).
empty?
&&
(
ext
=
ASSET_EXTENSIONS
[
options
[
:type
]]
)
if
extname
=
compute_asset_extname
(
source
,
options
)
source
=
"
#{
source
}#{
ext
}
"
source
=
"
#{
source
}#{
ext
name
}
"
end
end
if
source
[
0
]
!=
?/
if
source
[
0
]
!=
?/
...
@@ -157,6 +152,19 @@ def asset_url(source, options = {})
...
@@ -157,6 +152,19 @@ def asset_url(source, options = {})
end
end
alias_method
:url_to_asset
,
:asset_url
# aliased to avoid conflicts with an asset_url named route
alias_method
:url_to_asset
,
:asset_url
# aliased to avoid conflicts with an asset_url named route
ASSET_EXTENSIONS
=
{
javascript:
'.js'
,
stylesheet:
'.css'
}
# Compute extname to append to asset path. Returns nil if
# nothing should be added.
def
compute_asset_extname
(
source
,
options
=
{})
return
if
options
[
:extname
]
==
false
extname
=
options
[
:extname
]
||
ASSET_EXTENSIONS
[
options
[
:type
]]
extname
if
extname
&&
File
.
extname
(
source
)
!=
extname
end
# Maps asset types to public directory.
# Maps asset types to public directory.
ASSET_PUBLIC_DIRECTORIES
=
{
ASSET_PUBLIC_DIRECTORIES
=
{
audio:
'/audios'
,
audio:
'/audios'
,
...
...
actionpack/test/template/asset_tag_helper_test.rb
浏览文件 @
6601917a
...
@@ -43,6 +43,11 @@ def url_for(*args)
...
@@ -43,6 +43,11 @@ def url_for(*args)
%(asset_path("dir/xml.png"))
=>
%(/dir/xml.png)
,
%(asset_path("dir/xml.png"))
=>
%(/dir/xml.png)
,
%(asset_path("/dir/xml.png"))
=>
%(/dir/xml.png)
,
%(asset_path("/dir/xml.png"))
=>
%(/dir/xml.png)
,
%(asset_path("script.min"))
=>
%(/script.min)
,
%(asset_path("script.min.js"))
=>
%(/script.min.js)
,
%(asset_path("style.min"))
=>
%(/style.min)
,
%(asset_path("style.min.css"))
=>
%(/style.min.css)
,
%(asset_path("style", type: :stylesheet))
=>
%(/stylesheets/style.css)
,
%(asset_path("style", type: :stylesheet))
=>
%(/stylesheets/style.css)
,
%(asset_path("xmlhr", type: :javascript))
=>
%(/javascripts/xmlhr.js)
,
%(asset_path("xmlhr", type: :javascript))
=>
%(/javascripts/xmlhr.js)
,
%(asset_path("xml.png", type: :image))
=>
%(/images/xml.png)
%(asset_path("xml.png", type: :image))
=>
%(/images/xml.png)
...
@@ -66,7 +71,9 @@ def url_for(*args)
...
@@ -66,7 +71,9 @@ def url_for(*args)
JavascriptPathToTag
=
{
JavascriptPathToTag
=
{
%(javascript_path("xmlhr"))
=>
%(/javascripts/xmlhr.js)
,
%(javascript_path("xmlhr"))
=>
%(/javascripts/xmlhr.js)
,
%(javascript_path("super/xmlhr"))
=>
%(/javascripts/super/xmlhr.js)
,
%(javascript_path("super/xmlhr"))
=>
%(/javascripts/super/xmlhr.js)
,
%(javascript_path("/super/xmlhr.js"))
=>
%(/super/xmlhr.js)
%(javascript_path("/super/xmlhr.js"))
=>
%(/super/xmlhr.js)
,
%(javascript_path("xmlhr.min"))
=>
%(/javascripts/xmlhr.min.js)
,
%(javascript_path("xmlhr.min.js"))
=>
%(/javascripts/xmlhr.min.js)
}
}
PathToJavascriptToTag
=
{
PathToJavascriptToTag
=
{
...
@@ -91,7 +98,6 @@ def url_for(*args)
...
@@ -91,7 +98,6 @@ def url_for(*args)
%(javascript_include_tag("bank"))
=>
%(<script src="/javascripts/bank.js" ></script>)
,
%(javascript_include_tag("bank"))
=>
%(<script src="/javascripts/bank.js" ></script>)
,
%(javascript_include_tag("bank.js"))
=>
%(<script src="/javascripts/bank.js" ></script>)
,
%(javascript_include_tag("bank.js"))
=>
%(<script src="/javascripts/bank.js" ></script>)
,
%(javascript_include_tag("bank", :lang => "vbscript"))
=>
%(<script lang="vbscript" src="/javascripts/bank.js" ></script>)
,
%(javascript_include_tag("bank", :lang => "vbscript"))
=>
%(<script lang="vbscript" src="/javascripts/bank.js" ></script>)
,
%(javascript_include_tag("common.javascript", "/elsewhere/cools"))
=>
%(<script src="/javascripts/common.javascript" ></script>\n<script src="/elsewhere/cools.js" ></script>)
,
%(javascript_include_tag("http://example.com/all"))
=>
%(<script src="http://example.com/all"></script>)
,
%(javascript_include_tag("http://example.com/all"))
=>
%(<script src="http://example.com/all"></script>)
,
%(javascript_include_tag("http://example.com/all.js"))
=>
%(<script src="http://example.com/all.js"></script>)
,
%(javascript_include_tag("http://example.com/all.js"))
=>
%(<script src="http://example.com/all.js"></script>)
,
...
@@ -102,14 +108,17 @@ def url_for(*args)
...
@@ -102,14 +108,17 @@ def url_for(*args)
%(stylesheet_path("bank"))
=>
%(/stylesheets/bank.css)
,
%(stylesheet_path("bank"))
=>
%(/stylesheets/bank.css)
,
%(stylesheet_path("bank.css"))
=>
%(/stylesheets/bank.css)
,
%(stylesheet_path("bank.css"))
=>
%(/stylesheets/bank.css)
,
%(stylesheet_path('subdir/subdir'))
=>
%(/stylesheets/subdir/subdir.css)
,
%(stylesheet_path('subdir/subdir'))
=>
%(/stylesheets/subdir/subdir.css)
,
%(stylesheet_path('/subdir/subdir.css'))
=>
%(/subdir/subdir.css)
%(stylesheet_path('/subdir/subdir.css'))
=>
%(/subdir/subdir.css)
,
%(stylesheet_path("style.min"))
=>
%(/stylesheets/style.min.css)
,
%(stylesheet_path("style.min.css"))
=>
%(/stylesheets/style.min.css)
}
}
PathToStyleToTag
=
{
PathToStyleToTag
=
{
%(path_to_stylesheet("style"))
=>
%(/stylesheets/style.css)
,
%(path_to_stylesheet("style"))
=>
%(/stylesheets/style.css)
,
%(path_to_stylesheet("style.css"))
=>
%(/stylesheets/style.css)
,
%(path_to_stylesheet("style.css"))
=>
%(/stylesheets/style.css)
,
%(path_to_stylesheet('dir/file'))
=>
%(/stylesheets/dir/file.css)
,
%(path_to_stylesheet('dir/file'))
=>
%(/stylesheets/dir/file.css)
,
%(path_to_stylesheet('/dir/file.rcss'))
=>
%(/dir/file.rcss)
%(path_to_stylesheet('/dir/file.rcss', :extname => false))
=>
%(/dir/file.rcss)
,
%(path_to_stylesheet('/dir/file', :extname => '.rcss'))
=>
%(/dir/file.rcss)
}
}
StyleUrlToTag
=
{
StyleUrlToTag
=
{
...
@@ -123,7 +132,8 @@ def url_for(*args)
...
@@ -123,7 +132,8 @@ def url_for(*args)
%(url_to_stylesheet("style"))
=>
%(http://www.example.com/stylesheets/style.css)
,
%(url_to_stylesheet("style"))
=>
%(http://www.example.com/stylesheets/style.css)
,
%(url_to_stylesheet("style.css"))
=>
%(http://www.example.com/stylesheets/style.css)
,
%(url_to_stylesheet("style.css"))
=>
%(http://www.example.com/stylesheets/style.css)
,
%(url_to_stylesheet('dir/file'))
=>
%(http://www.example.com/stylesheets/dir/file.css)
,
%(url_to_stylesheet('dir/file'))
=>
%(http://www.example.com/stylesheets/dir/file.css)
,
%(url_to_stylesheet('/dir/file.rcss'))
=>
%(http://www.example.com/dir/file.rcss)
%(url_to_stylesheet('/dir/file.rcss', :extname => false))
=>
%(http://www.example.com/dir/file.rcss)
,
%(url_to_stylesheet('/dir/file', :extname => '.rcss'))
=>
%(http://www.example.com/dir/file.rcss)
}
}
StyleLinkToTag
=
{
StyleLinkToTag
=
{
...
@@ -132,7 +142,6 @@ def url_for(*args)
...
@@ -132,7 +142,6 @@ def url_for(*args)
%(stylesheet_link_tag("/elsewhere/file"))
=>
%(<link href="/elsewhere/file.css" media="screen" rel="stylesheet" />)
,
%(stylesheet_link_tag("/elsewhere/file"))
=>
%(<link href="/elsewhere/file.css" media="screen" rel="stylesheet" />)
,
%(stylesheet_link_tag("subdir/subdir"))
=>
%(<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" />)
,
%(stylesheet_link_tag("subdir/subdir"))
=>
%(<link href="/stylesheets/subdir/subdir.css" media="screen" rel="stylesheet" />)
,
%(stylesheet_link_tag("bank", :media => "all"))
=>
%(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" />)
,
%(stylesheet_link_tag("bank", :media => "all"))
=>
%(<link href="/stylesheets/bank.css" media="all" rel="stylesheet" />)
,
%(stylesheet_link_tag("random.styles", "/elsewhere/file"))
=>
%(<link href="/stylesheets/random.styles" media="screen" rel="stylesheet" />\n<link href="/elsewhere/file.css" media="screen" rel="stylesheet" />)
,
%(stylesheet_link_tag("http://www.example.com/styles/style"))
=>
%(<link href="http://www.example.com/styles/style" media="screen" rel="stylesheet" />)
,
%(stylesheet_link_tag("http://www.example.com/styles/style"))
=>
%(<link href="http://www.example.com/styles/style" media="screen" rel="stylesheet" />)
,
%(stylesheet_link_tag("http://www.example.com/styles/style.css"))
=>
%(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" />)
,
%(stylesheet_link_tag("http://www.example.com/styles/style.css"))
=>
%(<link href="http://www.example.com/styles/style.css" media="screen" rel="stylesheet" />)
,
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录