Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
3875e449
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,发现更多精彩内容 >>
提交
3875e449
编写于
7月 02, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
差异文件
Merge pull request #1925 from spohlenz/refactor-asset-paths
Refactor sprockets asset paths to allow for alternate asset environments
上级
9d6e5e64
21344bc3
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
40 addition
and
9 deletion
+40
-9
actionpack/lib/sprockets/helpers/rails_helper.rb
actionpack/lib/sprockets/helpers/rails_helper.rb
+27
-9
actionpack/test/fixtures/sprockets/alternate/stylesheets/style.css
...k/test/fixtures/sprockets/alternate/stylesheets/style.css
+1
-0
actionpack/test/template/sprockets_helper_test.rb
actionpack/test/template/sprockets_helper_test.rb
+12
-0
未找到文件。
actionpack/lib/sprockets/helpers/rails_helper.rb
浏览文件 @
3875e449
...
...
@@ -16,7 +16,10 @@ def asset_paths
else
config
.
default_asset_host_protocol
||=
:relative
end
RailsHelper
::
AssetPaths
.
new
(
config
,
controller
)
paths
=
RailsHelper
::
AssetPaths
.
new
(
config
,
controller
)
paths
.
asset_environment
=
asset_environment
paths
.
asset_prefix
=
asset_prefix
paths
end
end
...
...
@@ -76,9 +79,28 @@ def debug_assets?
params
[
:debug_assets
]
==
'true'
end
# Override to specify an alternative prefix for asset path generation.
# When combined with a custom +asset_environment+, this can be used to
# implement themes that can take advantage of the asset pipeline.
#
# If you only want to change where the assets are mounted, refer to
# +config.assets.prefix+ instead.
def
asset_prefix
Rails
.
application
.
config
.
assets
.
prefix
end
# Override to specify an alternative asset environment for asset
# path generation. The environment should already have been mounted
# at the prefix returned by +asset_prefix+.
def
asset_environment
Rails
.
application
.
assets
end
class
AssetPaths
<
::
ActionView
::
AssetPaths
#:nodoc:
def
compute_public_path
(
source
,
dir
,
ext
=
nil
,
include_host
=
true
,
protocol
=
nil
)
super
(
source
,
Rails
.
application
.
config
.
assets
.
prefix
,
ext
,
include_host
,
protocol
)
attr_accessor
:asset_environment
,
:asset_prefix
def
compute_public_path
(
source
,
dir
,
ext
=
nil
,
include_host
=
true
,
protocol
=
nil
)
super
(
source
,
asset_prefix
,
ext
,
include_host
,
protocol
)
end
# Return the filesystem path for the source
...
...
@@ -90,14 +112,14 @@ def asset_for(source, ext)
source
=
source
.
to_s
return
nil
if
is_uri?
(
source
)
source
=
rewrite_extension
(
source
,
nil
,
ext
)
asset
s
[
source
]
asset
_environment
[
source
]
end
def
rewrite_asset_path
(
source
,
dir
)
if
source
[
0
]
==
?/
source
else
asset
s
.
path
(
source
,
performing_caching?
,
dir
)
asset
_environment
.
path
(
source
,
performing_caching?
,
dir
)
end
end
...
...
@@ -109,10 +131,6 @@ def rewrite_extension(source, dir, ext)
end
end
def
assets
Rails
.
application
.
assets
end
# When included in Sprockets::Context, we need to ask the top-level config as the controller is not available
def
performing_caching?
config
.
action_controller
.
present?
?
config
.
action_controller
.
perform_caching
:
config
.
perform_caching
...
...
actionpack/test/fixtures/sprockets/alternate/stylesheets/style.css
0 → 100644
浏览文件 @
3875e449
/* Different from other style.css */
\ No newline at end of file
actionpack/test/template/sprockets_helper_test.rb
浏览文件 @
3875e449
...
...
@@ -197,4 +197,16 @@ def url_for(*args)
assert_equal
"<link href=
\"
/assets/style-d41d8cd98f00b204e9800998ecf8427e.css
\"
media=
\"
screen
\"
rel=
\"
stylesheet
\"
type=
\"
text/css
\"
/>
\n
<link href=
\"
/assets/extra-d41d8cd98f00b204e9800998ecf8427e.css
\"
media=
\"
screen
\"
rel=
\"
stylesheet
\"
type=
\"
text/css
\"
/>"
,
stylesheet_link_tag
(
"style"
,
"extra"
)
end
test
"alternate asset prefix"
do
stubs
(
:asset_prefix
).
returns
(
"/themes/test"
)
assert_equal
"/themes/test/style-d41d8cd98f00b204e9800998ecf8427e.css"
,
asset_path
(
"style"
,
"css"
)
end
test
"alternate asset environment"
do
assets
=
Sprockets
::
Environment
.
new
assets
.
paths
<<
FIXTURES
.
join
(
"sprockets/alternate/stylesheets"
)
stubs
(
:asset_environment
).
returns
(
assets
)
assert_equal
"/assets/style-df0b97ad35a8e1f7f61097461f77c19a.css"
,
asset_path
(
"style"
,
"css"
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录