Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
f004c886
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,发现更多精彩内容 >>
提交
f004c886
编写于
4月 12, 2011
作者:
J
Joshua Peek
浏览文件
操作
浏览文件
下载
差异文件
Merge branch 'sprockets'
上级
1b5b53da
a4518517
变更
19
隐藏空白更改
内联
并排
Showing
19 changed file
with
278 addition
and
9 deletion
+278
-9
Gemfile
Gemfile
+2
-0
actionpack/lib/abstract_controller/asset_paths.rb
actionpack/lib/abstract_controller/asset_paths.rb
+2
-2
actionpack/lib/action_controller/railtie.rb
actionpack/lib/action_controller/railtie.rb
+1
-0
actionpack/lib/action_view/helpers.rb
actionpack/lib/action_view/helpers.rb
+2
-0
actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
..._view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
+11
-3
actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
..._view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
+11
-3
actionpack/lib/action_view/helpers/sprockets_helper.rb
actionpack/lib/action_view/helpers/sprockets_helper.rb
+85
-0
actionpack/test/fixtures/sprockets/app/javascripts/application.js
...ck/test/fixtures/sprockets/app/javascripts/application.js
+0
-0
actionpack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js
...pack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js
+0
-0
actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js
actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js
+0
-0
actionpack/test/fixtures/sprockets/app/stylesheets/application.css
...k/test/fixtures/sprockets/app/stylesheets/application.css
+0
-0
actionpack/test/fixtures/sprockets/app/stylesheets/dir/style.css
...ack/test/fixtures/sprockets/app/stylesheets/dir/style.css
+0
-0
actionpack/test/fixtures/sprockets/app/stylesheets/style.css
actionpack/test/fixtures/sprockets/app/stylesheets/style.css
+0
-0
actionpack/test/template/sprockets_helper_test.rb
actionpack/test/template/sprockets_helper_test.rb
+96
-0
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+32
-0
railties/lib/rails/application/configuration.rb
railties/lib/rails/application/configuration.rb
+8
-1
railties/lib/rails/application/finisher.rb
railties/lib/rails/application/finisher.rb
+21
-0
railties/lib/rails/tasks.rb
railties/lib/rails/tasks.rb
+1
-0
railties/lib/rails/tasks/assets.rake
railties/lib/rails/tasks/assets.rake
+6
-0
未找到文件。
Gemfile
浏览文件 @
f004c886
...
...
@@ -11,6 +11,8 @@ end
gem
"
rack
"
,
:git
=>
"git://github.com/rack/rack.git"
gem
"
rack-test
"
,
:git
=>
"git://github.com/brynary/rack-test.git"
gem
"
sprockets
"
,
:git
=>
"git://github.com/sstephenson/sprockets.git"
gem
"
rake
"
,
">= 0.8.7"
gem
"
mocha
"
,
">= 0.9.8"
...
...
actionpack/lib/abstract_controller/asset_paths.rb
浏览文件 @
f004c886
...
...
@@ -3,7 +3,7 @@ module AssetPaths
extend
ActiveSupport
::
Concern
included
do
config_accessor
:asset_host
,
:asset_path
,
:assets_dir
,
:javascripts_dir
,
:stylesheets_dir
config_accessor
:asset_host
,
:asset_path
,
:assets_dir
,
:javascripts_dir
,
:stylesheets_dir
,
:use_sprockets
end
end
end
\ No newline at end of file
end
actionpack/lib/action_controller/railtie.rb
浏览文件 @
f004c886
...
...
@@ -21,6 +21,7 @@ class Railtie < Rails::Railtie
paths
=
app
.
config
.
paths
options
=
app
.
config
.
action_controller
options
.
use_sprockets
||=
app
.
config
.
assets
.
enabled
options
.
assets_dir
||=
paths
[
"public"
].
first
options
.
javascripts_dir
||=
paths
[
"public/javascripts"
].
first
options
.
stylesheets_dir
||=
paths
[
"public/stylesheets"
].
first
...
...
actionpack/lib/action_view/helpers.rb
浏览文件 @
f004c886
...
...
@@ -22,6 +22,7 @@ module Helpers #:nodoc:
autoload
:RecordTagHelper
autoload
:SanitizeHelper
autoload
:ScriptaculousHelper
autoload
:SprocketsHelper
autoload
:TagHelper
autoload
:TextHelper
autoload
:TranslationHelper
...
...
@@ -52,6 +53,7 @@ module Helpers #:nodoc:
include
RecordTagHelper
include
SanitizeHelper
include
ScriptaculousHelper
include
SprocketsHelper
include
TagHelper
include
TextHelper
include
TranslationHelper
...
...
actionpack/lib/action_view/helpers/asset_tag_helpers/javascript_tag_helpers.rb
浏览文件 @
f004c886
...
...
@@ -86,7 +86,11 @@ def register_javascript_expansion(expansions)
# javascript_path "http://www.railsapplication.com/js/xmlhr" # => http://www.railsapplication.com/js/xmlhr
# javascript_path "http://www.railsapplication.com/js/xmlhr.js" # => http://www.railsapplication.com/js/xmlhr.js
def
javascript_path
(
source
)
asset_paths
.
compute_public_path
(
source
,
'javascripts'
,
'js'
)
if
config
.
use_sprockets
sprockets_javascript_path
(
source
)
else
asset_paths
.
compute_public_path
(
source
,
'javascripts'
,
'js'
)
end
end
alias_method
:path_to_javascript
,
:javascript_path
# aliased to avoid conflicts with a javascript_path named route
...
...
@@ -173,8 +177,12 @@ def javascript_path(source)
#
# javascript_include_tag :all, :cache => true, :recursive => true
def
javascript_include_tag
(
*
sources
)
@javascript_include
||=
JavascriptIncludeTag
.
new
(
config
,
asset_paths
)
@javascript_include
.
include_tag
(
*
sources
)
if
config
.
use_sprockets
sprockets_javascript_include_tag
(
*
sources
)
else
@javascript_include
||=
JavascriptIncludeTag
.
new
(
config
,
asset_paths
)
@javascript_include
.
include_tag
(
*
sources
)
end
end
end
...
...
actionpack/lib/action_view/helpers/asset_tag_helpers/stylesheet_tag_helpers.rb
浏览文件 @
f004c886
...
...
@@ -63,7 +63,11 @@ def register_stylesheet_expansion(expansions)
# stylesheet_path "http://www.railsapplication.com/css/style" # => http://www.railsapplication.com/css/style
# stylesheet_path "http://www.railsapplication.com/css/style.css" # => http://www.railsapplication.com/css/style.css
def
stylesheet_path
(
source
)
asset_paths
.
compute_public_path
(
source
,
'stylesheets'
,
'css'
)
if
config
.
use_sprockets
sprockets_stylesheet_path
(
source
)
else
asset_paths
.
compute_public_path
(
source
,
'stylesheets'
,
'css'
)
end
end
alias_method
:path_to_stylesheet
,
:stylesheet_path
# aliased to avoid conflicts with a stylesheet_path named route
...
...
@@ -136,8 +140,12 @@ def stylesheet_path(source)
# stylesheet_link_tag :all, :concat => true
#
def
stylesheet_link_tag
(
*
sources
)
@stylesheet_include
||=
StylesheetIncludeTag
.
new
(
config
,
asset_paths
)
@stylesheet_include
.
include_tag
(
*
sources
)
if
config
.
use_sprockets
sprockets_stylesheet_link_tag
(
*
sources
)
else
@stylesheet_include
||=
StylesheetIncludeTag
.
new
(
config
,
asset_paths
)
@stylesheet_include
.
include_tag
(
*
sources
)
end
end
end
...
...
actionpack/lib/action_view/helpers/sprockets_helper.rb
0 → 100644
浏览文件 @
f004c886
require
'uri'
module
ActionView
module
Helpers
module
SprocketsHelper
def
sprockets_javascript_path
(
source
)
compute_sprockets_path
source
,
'assets'
,
'js'
end
def
sprockets_javascript_include_tag
(
source
,
options
=
{})
options
=
{
'type'
=>
"text/javascript"
,
'src'
=>
sprockets_javascript_path
(
source
)
}.
merge
(
options
.
stringify_keys
)
content_tag
'script'
,
""
,
options
end
def
sprockets_stylesheet_path
(
source
)
compute_sprockets_path
source
,
'assets'
,
'css'
end
def
sprockets_stylesheet_link_tag
(
source
,
options
=
{})
options
=
{
'rel'
=>
"stylesheet"
,
'type'
=>
"text/css"
,
'media'
=>
"screen"
,
'href'
=>
sprockets_stylesheet_path
(
source
)
}.
merge
(
options
.
stringify_keys
)
tag
'link'
,
options
end
private
def
compute_sprockets_path
(
source
,
dir
,
default_ext
)
source
=
source
.
to_s
return
source
if
URI
.
parse
(
source
).
host
# Add /javscripts to relative paths
if
source
[
0
]
!=
?/
source
=
"/
#{
dir
}
/
#{
source
}
"
end
# Add default extension if there isn't one
if
default_ext
&&
File
.
extname
(
source
).
empty?
source
=
"
#{
source
}
.
#{
default_ext
}
"
end
# Fingerprint url
if
source
=~
/^\/
#{
dir
}
\/(.+)/
source
=
assets
.
path
(
$1
,
config
.
perform_caching
,
dir
)
end
host
=
compute_asset_host
(
source
)
if
controller
.
respond_to?
(
:request
)
&&
host
&&
URI
.
parse
(
host
).
host
source
=
"
#{
controller
.
request
.
protocol
}#{
host
}#{
source
}
"
end
source
end
def
compute_asset_host
(
source
)
if
host
=
config
.
asset_host
if
host
.
is_a?
(
Proc
)
||
host
.
respond_to?
(
:call
)
case
host
.
is_a?
(
Proc
)
?
host
.
arity
:
host
.
method
(
:call
).
arity
when
2
request
=
controller
.
respond_to?
(
:request
)
&&
controller
.
request
host
.
call
(
source
,
request
)
else
host
.
call
(
source
)
end
else
(
host
=~
/%d/
)
?
host
%
(
source
.
hash
%
4
)
:
host
end
end
end
def
assets
Rails
.
application
.
assets
end
end
end
end
actionpack/test/fixtures/sprockets/app/javascripts/application.js
0 → 100644
浏览文件 @
f004c886
actionpack/test/fixtures/sprockets/app/javascripts/dir/xmlhr.js
0 → 100644
浏览文件 @
f004c886
actionpack/test/fixtures/sprockets/app/javascripts/xmlhr.js
0 → 100644
浏览文件 @
f004c886
actionpack/test/fixtures/sprockets/app/stylesheets/application.css
0 → 100644
浏览文件 @
f004c886
actionpack/test/fixtures/sprockets/app/stylesheets/dir/style.css
0 → 100644
浏览文件 @
f004c886
actionpack/test/fixtures/sprockets/app/stylesheets/style.css
0 → 100644
浏览文件 @
f004c886
actionpack/test/template/sprockets_helper_test.rb
0 → 100644
浏览文件 @
f004c886
require
'abstract_unit'
require
'sprockets'
class
SprocketsHelperTest
<
ActionView
::
TestCase
tests
ActionView
::
Helpers
::
SprocketsHelper
attr_accessor
:assets
def
setup
super
@controller
=
BasicController
.
new
@request
=
Class
.
new
do
def
protocol
()
'http://'
end
def
ssl?
()
false
end
def
host_with_port
()
'localhost'
end
end
.
new
@controller
.
request
=
@request
@assets
=
Sprockets
::
Environment
.
new
@assets
.
paths
<<
FIXTURES
.
join
(
"sprockets/app/javascripts"
)
@assets
.
paths
<<
FIXTURES
.
join
(
"sprockets/app/stylesheets"
)
config
.
perform_caching
=
true
end
def
url_for
(
*
args
)
"http://www.example.com"
end
test
"javascript path"
do
assert_equal
"/assets/application-d41d8cd98f00b204e9800998ecf8427e.js"
,
sprockets_javascript_path
(
:application
)
assert_equal
"/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js"
,
sprockets_javascript_path
(
"xmlhr"
)
assert_equal
"/assets/dir/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js"
,
sprockets_javascript_path
(
"dir/xmlhr.js"
)
assert_equal
"/dir/xmlhr.js"
,
sprockets_javascript_path
(
"/dir/xmlhr"
)
assert_equal
"http://www.railsapplication.com/js/xmlhr"
,
sprockets_javascript_path
(
"http://www.railsapplication.com/js/xmlhr"
)
assert_equal
"http://www.railsapplication.com/js/xmlhr.js"
,
sprockets_javascript_path
(
"http://www.railsapplication.com/js/xmlhr.js"
)
end
test
"javascript include tag"
do
assert_equal
'<script src="/assets/application-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>'
,
sprockets_javascript_include_tag
(
:application
)
assert_equal
'<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>'
,
sprockets_javascript_include_tag
(
"xmlhr"
)
assert_equal
'<script src="/assets/xmlhr-d41d8cd98f00b204e9800998ecf8427e.js" type="text/javascript"></script>'
,
sprockets_javascript_include_tag
(
"xmlhr.js"
)
assert_equal
'<script src="http://www.railsapplication.com/xmlhr" type="text/javascript"></script>'
,
sprockets_javascript_include_tag
(
"http://www.railsapplication.com/xmlhr"
)
end
test
"stylesheet path"
do
assert_equal
"/assets/application-d41d8cd98f00b204e9800998ecf8427e.css"
,
sprockets_stylesheet_path
(
:application
)
assert_equal
"/assets/style-d41d8cd98f00b204e9800998ecf8427e.css"
,
sprockets_stylesheet_path
(
"style"
)
assert_equal
"/assets/dir/style-d41d8cd98f00b204e9800998ecf8427e.css"
,
sprockets_stylesheet_path
(
"dir/style.css"
)
assert_equal
"/dir/style.css"
,
sprockets_stylesheet_path
(
"/dir/style.css"
)
assert_equal
"http://www.railsapplication.com/css/style"
,
sprockets_stylesheet_path
(
"http://www.railsapplication.com/css/style"
)
assert_equal
"http://www.railsapplication.com/css/style.css"
,
sprockets_stylesheet_path
(
"http://www.railsapplication.com/css/style.css"
)
end
test
"stylesheet link tag"
do
assert_equal
'<link href="/assets/application-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />'
,
sprockets_stylesheet_link_tag
(
:application
)
assert_equal
'<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />'
,
sprockets_stylesheet_link_tag
(
"style"
)
assert_equal
'<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="screen" rel="stylesheet" type="text/css" />'
,
sprockets_stylesheet_link_tag
(
"style.css"
)
assert_equal
'<link href="http://www.railsapplication.com/style.css" media="screen" rel="stylesheet" type="text/css" />'
,
sprockets_stylesheet_link_tag
(
"http://www.railsapplication.com/style.css"
)
assert_equal
'<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="all" rel="stylesheet" type="text/css" />'
,
sprockets_stylesheet_link_tag
(
"style"
,
:media
=>
"all"
)
assert_equal
'<link href="/assets/style-d41d8cd98f00b204e9800998ecf8427e.css" media="print" rel="stylesheet" type="text/css" />'
,
sprockets_stylesheet_link_tag
(
"style"
,
:media
=>
"print"
)
end
end
railties/lib/rails/application.rb
浏览文件 @
f004c886
...
...
@@ -137,6 +137,38 @@ def config
@config
||=
Application
::
Configuration
.
new
(
find_root_with_flag
(
"config.ru"
,
Dir
.
pwd
))
end
def
assets
@assets
||=
build_asset_environment
end
attr_writer
:assets
def
build_asset_environment
return
unless
config
.
assets
.
enabled
require
'sprockets'
env
=
Sprockets
::
Environment
.
new
(
root
.
to_s
)
env
.
static_root
=
File
.
join
(
root
.
join
(
"public"
),
config
.
assets
.
prefix
)
env
end
initializer
:add_sprockets_paths
do
|
app
|
if
config
.
assets
.
enabled
paths
=
[
"app/javascripts"
,
"app/stylesheets"
,
"vendor/plugins/*/app/javascripts"
,
"vendor/plugins/*/app/stylesheets"
,
"vendor/plugins/*/javascripts"
,
"vendor/plugins/*/stylesheets"
]
+
config
.
assets
.
paths
paths
.
each
do
|
pattern
|
Dir
[
app
.
root
.
join
(
pattern
)].
each
do
|
dir
|
app
.
assets
.
paths
<<
dir
end
end
end
end
protected
def
default_asset_path
...
...
railties/lib/rails/application/configuration.rb
浏览文件 @
f004c886
...
...
@@ -9,7 +9,8 @@ class Configuration < ::Rails::Engine::Configuration
:filter_parameters
,
:helpers_paths
,
:logger
,
:preload_frameworks
,
:reload_plugins
,
:secret_token
,
:serve_static_assets
,
:session_options
,
:time_zone
,
:whiny_nils
,
:force_ssl
:time_zone
,
:whiny_nils
,
:force_ssl
,
:assets
attr_writer
:log_level
...
...
@@ -29,6 +30,12 @@ def initialize(*)
@log_level
=
nil
@middleware
=
app_middleware
@generators
=
app_generators
@assets
=
ActiveSupport
::
OrderedOptions
.
new
@assets
.
enabled
=
false
@assets
.
paths
=
[]
@assets
.
precompile
=
[]
@assets
.
prefix
=
"/assets"
end
def
compiled_asset_path
...
...
railties/lib/rails/application/finisher.rb
浏览文件 @
f004c886
...
...
@@ -33,6 +33,27 @@ module Finisher
end
end
initializer
:add_sprockets_route
do
|
app
|
assets
=
config
.
assets
if
assets
.
enabled
app
.
routes
.
append
do
mount
app
.
assets
=>
assets
.
prefix
end
end
end
initializer
:set_sprockets_logger
do
|
app
|
if
config
.
assets
.
enabled
app
.
assets
.
logger
=
Rails
.
logger
end
end
initializer
:index_sprockets_environment
do
|
app
|
if
config
.
assets
.
enabled
&&
config
.
action_controller
.
perform_caching
app
.
assets
=
app
.
assets
.
index
end
end
initializer
:build_middleware_stack
do
build_middleware_stack
end
...
...
railties/lib/rails/tasks.rb
浏览文件 @
f004c886
...
...
@@ -3,6 +3,7 @@
# Load Rails rakefile extensions
%w(
annotations
assets
documentation
framework
log
...
...
railties/lib/rails/tasks/assets.rake
0 → 100644
浏览文件 @
f004c886
namespace
:assets
do
task
:compile
=>
:environment
do
assets
=
Rails
.
application
.
config
.
assets
.
precompile
Rails
.
application
.
assets
.
precompile
(
*
assets
)
end
end
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录