Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
张重言
rails
提交
d5ad92ce
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,发现更多精彩内容 >>
提交
d5ad92ce
编写于
4月 15, 2011
作者:
J
José Valim
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Make static faster as we don't have to serve multiple paths anymore.
上级
afc82882
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
17 addition
and
84 deletion
+17
-84
actionpack/lib/action_dispatch/middleware/static.rb
actionpack/lib/action_dispatch/middleware/static.rb
+15
-28
actionpack/test/dispatch/static_test.rb
actionpack/test/dispatch/static_test.rb
+1
-32
actionpack/test/template/asset_tag_helper_test.rb
actionpack/test/template/asset_tag_helper_test.rb
+0
-23
railties/lib/rails/application.rb
railties/lib/rails/application.rb
+1
-1
未找到文件。
actionpack/lib/action_dispatch/middleware/static.rb
浏览文件 @
d5ad92ce
...
...
@@ -2,25 +2,23 @@
module
ActionDispatch
class
FileHandler
def
initialize
(
at
,
root
)
@at
,
@root
=
at
.
chomp
(
'/'
),
root
.
chomp
(
'/'
)
@compiled_at
=
@at
.
blank?
?
nil
:
/^
#{
Regexp
.
escape
(
at
)
}
/
def
initialize
(
root
)
@root
=
root
.
chomp
(
'/'
)
@compiled_root
=
/^
#{
Regexp
.
escape
(
root
)
}
/
@file_server
=
::
Rack
::
File
.
new
(
@root
)
end
def
match?
(
path
)
path
=
path
.
dup
if
!
@compiled_at
||
path
.
sub!
(
@compiled_at
,
''
)
full_path
=
path
.
empty?
?
@root
:
File
.
join
(
@root
,
::
Rack
::
Utils
.
unescape
(
path
))
paths
=
"
#{
full_path
}#{
ext
}
"
matches
=
Dir
[
paths
]
match
=
matches
.
detect
{
|
m
|
File
.
file?
(
m
)
}
if
match
match
.
sub!
(
@compiled_root
,
''
)
match
end
full_path
=
path
.
empty?
?
@root
:
File
.
join
(
@root
,
::
Rack
::
Utils
.
unescape
(
path
))
paths
=
"
#{
full_path
}#{
ext
}
"
matches
=
Dir
[
paths
]
match
=
matches
.
detect
{
|
m
|
File
.
file?
(
m
)
}
if
match
match
.
sub!
(
@compiled_root
,
''
)
match
end
end
...
...
@@ -39,9 +37,9 @@ def ext
class
Static
FILE_METHODS
=
%w(GET HEAD)
.
freeze
def
initialize
(
app
,
roots
)
def
initialize
(
app
,
path
)
@app
=
app
@file_handler
s
=
create_file_handlers
(
roots
)
@file_handler
=
FileHandler
.
new
(
path
)
end
def
call
(
env
)
...
...
@@ -49,24 +47,13 @@ def call(env)
method
=
env
[
'REQUEST_METHOD'
]
if
FILE_METHODS
.
include?
(
method
)
@file_handlers
.
each
do
|
file_handler
|
if
match
=
file_handler
.
match?
(
path
)
env
[
"PATH_INFO"
]
=
match
return
file_handler
.
call
(
env
)
end
if
match
=
@file_handler
.
match?
(
path
)
env
[
"PATH_INFO"
]
=
match
return
@file_handler
.
call
(
env
)
end
end
@app
.
call
(
env
)
end
private
def
create_file_handlers
(
roots
)
roots
=
{
''
=>
roots
}
unless
roots
.
is_a?
(
Hash
)
roots
.
map
do
|
at
,
root
|
FileHandler
.
new
(
at
,
root
)
if
File
.
exist?
(
root
)
end
.
compact
end
end
end
actionpack/test/dispatch/static_test.rb
浏览文件 @
d5ad92ce
...
...
@@ -47,35 +47,4 @@ def setup
end
include
StaticTests
end
class
MultipleDirectorisStaticTest
<
ActiveSupport
::
TestCase
DummyApp
=
lambda
{
|
env
|
[
200
,
{
"Content-Type"
=>
"text/plain"
},
[
"Hello, World!"
]]
}
App
=
ActionDispatch
::
Static
.
new
(
DummyApp
,
{
"/"
=>
"
#{
FIXTURE_LOAD_PATH
}
/public"
,
"/blog"
=>
"
#{
FIXTURE_LOAD_PATH
}
/blog_public"
,
"/foo"
=>
"
#{
FIXTURE_LOAD_PATH
}
/non_existing_dir"
})
def
setup
@app
=
App
end
include
StaticTests
test
"serves files from other mounted directories"
do
assert_html
"/blog/index.html"
,
get
(
"/blog/index.html"
)
assert_html
"/blog/index.html"
,
get
(
"/blog/index"
)
assert_html
"/blog/index.html"
,
get
(
"/blog/"
)
assert_html
"/blog/blog.html"
,
get
(
"/blog/blog/"
)
assert_html
"/blog/blog.html"
,
get
(
"/blog/blog.html"
)
assert_html
"/blog/blog.html"
,
get
(
"/blog/blog"
)
assert_html
"/blog/subdir/index.html"
,
get
(
"/blog/subdir/index.html"
)
assert_html
"/blog/subdir/index.html"
,
get
(
"/blog/subdir/"
)
assert_html
"/blog/subdir/index.html"
,
get
(
"/blog/subdir"
)
end
end
end
\ No newline at end of file
actionpack/test/template/asset_tag_helper_test.rb
浏览文件 @
d5ad92ce
...
...
@@ -477,15 +477,6 @@ def test_string_asset_id
assert_equal
%(<img alt="Rails" src="#{expected_path}" />)
,
image_tag
(
"rails.png"
)
end
def
test_env_asset_path
@controller
.
config
.
asset_path
=
"/assets%s"
def
@controller
.
env
;
@_env
||=
{}
end
@controller
.
env
[
"action_dispatch.asset_path"
]
=
"/omg%s"
expected_path
=
"/assets/omg/images/rails.png"
assert_equal
%(<img alt="Rails" src="#{expected_path}" />)
,
image_tag
(
"rails.png"
)
end
def
test_proc_asset_id
@controller
.
config
.
asset_path
=
Proc
.
new
do
|
asset_path
|
"/assets.v12345
#{
asset_path
}
"
...
...
@@ -495,20 +486,6 @@ def test_proc_asset_id
assert_equal
%(<img alt="Rails" src="#{expected_path}" />)
,
image_tag
(
"rails.png"
)
end
def
test_env_proc_asset_path
@controller
.
config
.
asset_path
=
Proc
.
new
do
|
asset_path
|
"/assets.v12345
#{
asset_path
}
"
end
def
@controller
.
env
;
@_env
||=
{}
end
@controller
.
env
[
"action_dispatch.asset_path"
]
=
Proc
.
new
do
|
asset_path
|
"/omg
#{
asset_path
}
"
end
expected_path
=
"/assets.v12345/omg/images/rails.png"
assert_equal
%(<img alt="Rails" src="#{expected_path}" />)
,
image_tag
(
"rails.png"
)
end
def
test_image_tag_interpreting_email_cid_correctly
# An inline image has no need for an alt tag to be automatically generated from the cid:
assert_equal
'<img src="cid:thi%25%25sis@acontentid" />'
,
image_tag
(
"cid:thi%25%25sis@acontentid"
)
...
...
railties/lib/rails/application.rb
浏览文件 @
d5ad92ce
...
...
@@ -161,7 +161,7 @@ def default_middleware_stack
end
if
config
.
serve_static_assets
middleware
.
use
::
ActionDispatch
::
Static
,
"/"
=>
paths
[
"public"
].
first
middleware
.
use
::
ActionDispatch
::
Static
,
paths
[
"public"
].
first
end
middleware
.
use
::
Rack
::
Lock
unless
config
.
allow_concurrency
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录