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
8d28a1e8
Commit
8d28a1e8
authored
Oct 24, 2012
by
garethr
Committed by
Jon Yurek
Nov 02, 2012
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Allow setting of escape url as a default option
parent
a255f26d
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
25 additions
and
1 deletions
+25
-1
lib/paperclip/attachment.rb
+3
-1
test/attachment_test.rb
+22
-0
No files found.
lib/paperclip/attachment.rb
View file @
8d28a1e8
...
@@ -12,6 +12,7 @@ module Paperclip
...
@@ -12,6 +12,7 @@ module Paperclip
:convert_options
=>
{},
:convert_options
=>
{},
:default_style
=>
:original
,
:default_style
=>
:original
,
:default_url
=>
"/:attachment/:style/missing.png"
,
:default_url
=>
"/:attachment/:style/missing.png"
,
:escape_url
=>
true
,
:restricted_characters
=>
/[&$+,\/:;=?@<>\[\]\{\}\|\\\^~%# ]/
,
:restricted_characters
=>
/[&$+,\/:;=?@<>\[\]\{\}\|\\\^~%# ]/
,
:hash_data
=>
":class/:attachment/:id/:style/:updated_at"
,
:hash_data
=>
":class/:attachment/:id/:style/:updated_at"
,
:hash_digest
=>
"SHA1"
,
:hash_digest
=>
"SHA1"
,
...
@@ -60,6 +61,7 @@ module Paperclip
...
@@ -60,6 +61,7 @@ module Paperclip
# +preserve_files+ - whether to keep files on the filesystem when deleting or clearing the attachment. Defaults to false
# +preserve_files+ - whether to keep files on the filesystem when deleting or clearing the attachment. Defaults to false
# +interpolator+ - the object used to interpolate filenames and URLs. Defaults to Paperclip::Interpolations
# +interpolator+ - the object used to interpolate filenames and URLs. Defaults to Paperclip::Interpolations
# +url_generator+ - the object used to generate URLs, using the interpolator. Defaults to Paperclip::UrlGenerator
# +url_generator+ - the object used to generate URLs, using the interpolator. Defaults to Paperclip::UrlGenerator
# +escape_url+ - Perform URI escaping to URLs. Defaults to true
def
initialize
(
name
,
instance
,
options
=
{})
def
initialize
(
name
,
instance
,
options
=
{})
@name
=
name
@name
=
name
@instance
=
instance
@instance
=
instance
...
@@ -133,7 +135,7 @@ module Paperclip
...
@@ -133,7 +135,7 @@ module Paperclip
# +#new(Paperclip::Attachment, options_hash)+
# +#new(Paperclip::Attachment, options_hash)+
# +#for(style_name, options_hash)+
# +#for(style_name, options_hash)+
def
url
(
style_name
=
default_style
,
options
=
{})
def
url
(
style_name
=
default_style
,
options
=
{})
default_options
=
{
:timestamp
=>
@options
[
:use_timestamp
],
:escape
=>
true
}
default_options
=
{
:timestamp
=>
@options
[
:use_timestamp
],
:escape
=>
@options
[
:escape_url
]
}
if
options
==
true
||
options
==
false
# Backwards compatibility.
if
options
==
true
||
options
==
false
# Backwards compatibility.
@url_generator
.
for
(
style_name
,
default_options
.
merge
(
:timestamp
=>
options
))
@url_generator
.
for
(
style_name
,
default_options
.
merge
(
:timestamp
=>
options
))
...
...
test/attachment_test.rb
View file @
8d28a1e8
...
@@ -149,6 +149,28 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -149,6 +149,28 @@ class AttachmentTest < Test::Unit::TestCase
assert
mock_url_generator_builder
.
has_generated_url_with_style_name?
(
'default style'
)
assert
mock_url_generator_builder
.
has_generated_url_with_style_name?
(
'default style'
)
end
end
should
"pass the option :escape => true if :escape_url is true and :escape is not passed"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:url_generator
=>
mock_url_generator_builder
,
:escape_url
=>
true
)
attachment
.
url
(
:style_name
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
true
)
end
should
"pass the option :escape => false if :escape_url is false and :escape is not passed"
do
mock_url_generator_builder
=
MockUrlGeneratorBuilder
.
new
attachment
=
Paperclip
::
Attachment
.
new
(
:name
,
:instance
,
:url_generator
=>
mock_url_generator_builder
,
:escape_url
=>
false
)
attachment
.
url
(
:style_name
)
assert
mock_url_generator_builder
.
has_generated_url_with_options?
(
:escape
=>
false
)
end
should
"return the path based on the url by default"
do
should
"return the path based on the url by default"
do
@attachment
=
attachment
:url
=>
"/:class/:id/:basename"
@attachment
=
attachment
:url
=>
"/:class/:id/:basename"
@model
=
@attachment
.
instance
@model
=
@attachment
.
instance
...
...
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