Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
P
paperclip
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
ikcrm_common
paperclip
Commits
87783829
Commit
87783829
authored
Feb 08, 2009
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added :relative_root interpolation
parent
09657d1c
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
18 deletions
+56
-18
lib/paperclip/attachment.rb
+25
-18
test/attachment_test.rb
+30
-0
test/helper.rb
+1
-0
No files found.
lib/paperclip/attachment.rb
View file @
87783829
...
@@ -188,24 +188,31 @@ module Paperclip
...
@@ -188,24 +188,31 @@ module Paperclip
# necessary.
# necessary.
def
self
.
interpolations
def
self
.
interpolations
@interpolations
||=
{
@interpolations
||=
{
:rails_root
=>
lambda
{
|
attachment
,
style
|
RAILS_ROOT
},
:rails_root
=>
lambda
{
|
attachment
,
style
|
RAILS_ROOT
},
:rails_env
=>
lambda
{
|
attachment
,
style
|
RAILS_ENV
},
:rails_env
=>
lambda
{
|
attachment
,
style
|
RAILS_ENV
},
:class
=>
lambda
do
|
attachment
,
style
|
:class
=>
lambda
do
|
attachment
,
style
|
attachment
.
instance
.
class
.
name
.
underscore
.
pluralize
attachment
.
instance
.
class
.
name
.
underscore
.
pluralize
end
,
end
,
:basename
=>
lambda
do
|
attachment
,
style
|
:basename
=>
lambda
do
|
attachment
,
style
|
attachment
.
original_filename
.
gsub
(
/
#{
File
.
extname
(
attachment
.
original_filename
)
}
$/
,
""
)
attachment
.
original_filename
.
gsub
(
/
#{
File
.
extname
(
attachment
.
original_filename
)
}
$/
,
""
)
end
,
end
,
:extension
=>
lambda
do
|
attachment
,
style
|
:extension
=>
lambda
do
|
attachment
,
style
|
((
style
=
attachment
.
styles
[
style
])
&&
style
[
:format
])
||
((
style
=
attachment
.
styles
[
style
])
&&
style
[
:format
])
||
File
.
extname
(
attachment
.
original_filename
).
gsub
(
/^\.+/
,
""
)
File
.
extname
(
attachment
.
original_filename
).
gsub
(
/^\.+/
,
""
)
end
,
end
,
:id
=>
lambda
{
|
attachment
,
style
|
attachment
.
instance
.
id
},
:id
=>
lambda
{
|
attachment
,
style
|
attachment
.
instance
.
id
},
:id_partition
=>
lambda
do
|
attachment
,
style
|
:id_partition
=>
lambda
do
|
attachment
,
style
|
(
"%09d"
%
attachment
.
instance
.
id
).
scan
(
/\d{3}/
).
join
(
"/"
)
(
"%09d"
%
attachment
.
instance
.
id
).
scan
(
/\d{3}/
).
join
(
"/"
)
end
,
end
,
:attachment
=>
lambda
{
|
attachment
,
style
|
attachment
.
name
.
to_s
.
downcase
.
pluralize
},
:attachment
=>
lambda
{
|
attachment
,
style
|
attachment
.
name
.
to_s
.
downcase
.
pluralize
},
:style
=>
lambda
{
|
attachment
,
style
|
style
||
attachment
.
default_style
},
:style
=>
lambda
{
|
attachment
,
style
|
style
||
attachment
.
default_style
},
:relative_root
=>
lambda
do
|
attachment
,
style
|
if
ActionController
::
AbstractRequest
.
respond_to?
(
:relative_url_root
)
ActionController
::
AbstractRequest
.
relative_url_root
elsif
ActionController
::
Base
.
respond_to?
(
:relative_url_root
)
ActionController
::
Base
.
relative_url_root
end
end
}
}
end
end
...
...
test/attachment_test.rb
View file @
87783829
...
@@ -106,6 +106,36 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -106,6 +106,36 @@ class AttachmentTest < Test::Unit::TestCase
end
end
end
end
context
"An attachment with a :relative_root interpolation"
do
setup
do
rebuild_model
:url
=>
":relative_root/:id.png"
@dummy
=
Dummy
.
new
@dummy
.
stubs
(
:id
).
returns
(
1024
)
@dummy
.
avatar
=
StringIO
.
new
(
"."
)
ActionController
::
Base
.
stubs
(
:respond_to?
).
with
(
:relative_url_root
).
returns
(
false
)
ActionController
::
Base
.
stubs
(
:relative_url_root
).
returns
(
"/base"
)
ActionController
::
AbstractRequest
.
stubs
(
:respond_to?
).
with
(
:relative_url_root
).
returns
(
false
)
ActionController
::
AbstractRequest
.
stubs
(
:relative_url_root
).
returns
(
"/request"
)
end
should
"return the proper path when the path is nil"
do
assert_equal
"/1024.png"
,
@dummy
.
avatar
.
url
(
:original
,
false
)
end
should
"return the proper path when using Rails < 2.1"
do
ActionController
::
AbstractRequest
.
expects
(
:respond_to?
).
with
(
:relative_url_root
).
returns
(
true
)
ActionController
::
AbstractRequest
.
expects
(
:relative_url_root
).
returns
(
"/request"
)
assert_equal
"/request/1024.png"
,
@dummy
.
avatar
.
url
(
:original
,
false
)
end
should
"return the proper path when using Rails >= 2.1"
do
ActionController
::
Base
.
expects
(
:respond_to?
).
with
(
:relative_url_root
).
returns
(
true
)
ActionController
::
Base
.
expects
(
:relative_url_root
).
returns
(
"/base"
)
assert_equal
"/base/1024.png"
,
@dummy
.
avatar
.
url
(
:original
,
false
)
end
end
context
"An attachment with :convert_options"
do
context
"An attachment with :convert_options"
do
setup
do
setup
do
rebuild_model
:styles
=>
{
rebuild_model
:styles
=>
{
...
...
test/helper.rb
View file @
87783829
...
@@ -9,6 +9,7 @@ gem 'sqlite3-ruby'
...
@@ -9,6 +9,7 @@ gem 'sqlite3-ruby'
require
'active_record'
require
'active_record'
require
'active_support'
require
'active_support'
require
'action_controller'
begin
begin
require
'ruby-debug'
require
'ruby-debug'
rescue
LoadError
rescue
LoadError
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment