Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
a3a5c7eb
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,发现更多精彩内容 >>
提交
a3a5c7eb
编写于
4月 19, 2011
作者:
D
David Heinemeier Hansson
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
All assets, including images, audio, and video, now uses the asset pipeline when its on
上级
dca31b92
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
44 addition
and
8 deletion
+44
-8
actionpack/lib/action_view/helpers/asset_tag_helper.rb
actionpack/lib/action_view/helpers/asset_tag_helper.rb
+15
-3
actionpack/lib/action_view/helpers/sprockets_helper.rb
actionpack/lib/action_view/helpers/sprockets_helper.rb
+10
-5
actionpack/test/fixtures/sprockets/app/images/logo.png
actionpack/test/fixtures/sprockets/app/images/logo.png
+0
-0
actionpack/test/template/sprockets_helper_test.rb
actionpack/test/template/sprockets_helper_test.rb
+19
-0
未找到文件。
actionpack/lib/action_view/helpers/asset_tag_helper.rb
浏览文件 @
a3a5c7eb
...
...
@@ -274,7 +274,11 @@ def favicon_link_tag(source='/favicon.ico', options={})
# The alias +path_to_image+ is provided to avoid that. Rails uses the alias internally, and
# plugin authors are encouraged to do so.
def
image_path
(
source
)
asset_paths
.
compute_public_path
(
source
,
'images'
)
if
config
.
use_sprockets
sprockets_asset_path
(
source
)
else
asset_paths
.
compute_public_path
(
source
,
'images'
)
end
end
alias_method
:path_to_image
,
:image_path
# aliased to avoid conflicts with an image_path named route
...
...
@@ -289,7 +293,11 @@ def image_path(source)
# video_path("/trailers/hd.avi") # => /trailers/hd.avi
# video_path("http://www.railsapplication.com/vid/hd.avi") # => http://www.railsapplication.com/vid/hd.avi
def
video_path
(
source
)
asset_paths
.
compute_public_path
(
source
,
'videos'
)
if
config
.
use_sprockets
sprockets_asset_path
(
source
)
else
asset_paths
.
compute_public_path
(
source
,
'videos'
)
end
end
alias_method
:path_to_video
,
:video_path
# aliased to avoid conflicts with a video_path named route
...
...
@@ -304,7 +312,11 @@ def video_path(source)
# audio_path("/sounds/horse.wav") # => /sounds/horse.wav
# audio_path("http://www.railsapplication.com/sounds/horse.wav") # => http://www.railsapplication.com/sounds/horse.wav
def
audio_path
(
source
)
asset_paths
.
compute_public_path
(
source
,
'audios'
)
if
config
.
use_sprockets
sprockets_asset_path
(
source
)
else
asset_paths
.
compute_public_path
(
source
,
'audios'
)
end
end
alias_method
:path_to_audio
,
:audio_path
# aliased to avoid conflicts with an audio_path named route
...
...
actionpack/lib/action_view/helpers/sprockets_helper.rb
浏览文件 @
a3a5c7eb
...
...
@@ -3,8 +3,12 @@
module
ActionView
module
Helpers
module
SprocketsHelper
def
sprockets_asset_path
(
source
,
default_ext
=
nil
)
compute_sprockets_path
(
source
,
'assets'
,
default_ext
)
end
def
sprockets_javascript_path
(
source
)
compute_sprockets_path
source
,
'assets'
,
'js'
sprockets_asset_path
(
source
,
'js'
)
end
def
sprockets_javascript_include_tag
(
source
,
options
=
{})
...
...
@@ -17,9 +21,9 @@ def sprockets_javascript_include_tag(source, options = {})
end
def
sprockets_stylesheet_path
(
source
)
compute_sprockets_path
source
,
'assets'
,
'css'
sprockets_asset_path
(
source
,
'css'
)
end
def
sprockets_stylesheet_link_tag
(
source
,
options
=
{})
options
=
{
'rel'
=>
"stylesheet"
,
...
...
@@ -31,13 +35,14 @@ def sprockets_stylesheet_link_tag(source, options = {})
tag
'link'
,
options
end
private
def
compute_sprockets_path
(
source
,
dir
,
default_ext
)
def
compute_sprockets_path
(
source
,
dir
,
default_ext
=
nil
)
source
=
source
.
to_s
return
source
if
URI
.
parse
(
source
).
host
# Add /
javscrip
ts to relative paths
# Add /
asse
ts to relative paths
if
source
[
0
]
!=
?/
source
=
"/
#{
dir
}
/
#{
source
}
"
end
...
...
actionpack/test/fixtures/sprockets/app/images/logo.png
0 → 100644
浏览文件 @
a3a5c7eb
6.5 KB
actionpack/test/template/sprockets_helper_test.rb
浏览文件 @
a3a5c7eb
...
...
@@ -22,6 +22,7 @@ def host_with_port() 'localhost' end
@assets
=
Sprockets
::
Environment
.
new
@assets
.
paths
<<
FIXTURES
.
join
(
"sprockets/app/javascripts"
)
@assets
.
paths
<<
FIXTURES
.
join
(
"sprockets/app/stylesheets"
)
@assets
.
paths
<<
FIXTURES
.
join
(
"sprockets/app/images"
)
config
.
perform_caching
=
true
end
...
...
@@ -30,6 +31,24 @@ def url_for(*args)
"http://www.example.com"
end
test
"asset path"
do
assert_equal
"/assets/logo-9c0a079bdd7701d7e729bd956823d153.png"
,
sprockets_asset_path
(
"logo.png"
)
assert_equal
"/images/logo"
,
sprockets_asset_path
(
"/images/logo"
)
assert_equal
"/images/logo.gif"
,
sprockets_asset_path
(
"/images/logo.gif"
)
assert_equal
"/dir/audio"
,
sprockets_asset_path
(
"/dir/audio"
)
assert_equal
"http://www.example.com/video/play"
,
sprockets_asset_path
(
"http://www.example.com/video/play"
)
assert_equal
"http://www.example.com/video/play.mp4"
,
sprockets_asset_path
(
"http://www.example.com/video/play.mp4"
)
end
test
"javascript path"
do
assert_equal
"/assets/application-d41d8cd98f00b204e9800998ecf8427e.js"
,
sprockets_javascript_path
(
:application
)
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录