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
8c3f685f
Commit
8c3f685f
authored
Nov 16, 2011
by
Mike Burns
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'fix_convert_options' of
https://github.com/kasatani/paperclip
parents
ff48f688
b66833e6
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
36 additions
and
3 deletions
+36
-3
lib/paperclip/style.rb
+6
-2
test/style_test.rb
+30
-1
No files found.
lib/paperclip/style.rb
View file @
8c3f685f
...
@@ -18,6 +18,8 @@ module Paperclip
...
@@ -18,6 +18,8 @@ module Paperclip
@geometry
=
definition
.
delete
(
:geometry
)
@geometry
=
definition
.
delete
(
:geometry
)
@format
=
definition
.
delete
(
:format
)
@format
=
definition
.
delete
(
:format
)
@processors
=
definition
.
delete
(
:processors
)
@processors
=
definition
.
delete
(
:processors
)
@convert_options
=
definition
.
delete
(
:convert_options
)
@source_file_options
=
definition
.
delete
(
:source_file_options
)
@other_args
=
definition
@other_args
=
definition
elsif
definition
.
is_a?
String
elsif
definition
.
is_a?
String
@geometry
=
definition
@geometry
=
definition
...
@@ -50,11 +52,13 @@ module Paperclip
...
@@ -50,11 +52,13 @@ module Paperclip
end
end
def
convert_options
def
convert_options
attachment
.
send
(
:extra_options_for
,
name
)
@convert_options
.
respond_to?
(
:call
)
?
@convert_options
.
call
(
attachment
.
instance
)
:
(
@convert_options
||
attachment
.
send
(
:extra_options_for
,
name
))
end
end
def
source_file_options
def
source_file_options
attachment
.
send
(
:extra_source_file_options_for
,
name
)
@source_file_options
.
respond_to?
(
:call
)
?
@source_file_options
.
call
(
attachment
.
instance
)
:
(
@source_file_options
||
attachment
.
send
(
:extra_source_file_options_for
,
name
))
end
end
# returns the geometry string for this style
# returns the geometry string for this style
...
...
test/style_test.rb
View file @
8c3f685f
...
@@ -41,7 +41,9 @@ class StyleTest < Test::Unit::TestCase
...
@@ -41,7 +41,9 @@ class StyleTest < Test::Unit::TestCase
:styles
=>
{
:styles
=>
{
:foo
=>
lambda
{
|
a
|
"300x300#"
},
:foo
=>
lambda
{
|
a
|
"300x300#"
},
:bar
=>
{
:bar
=>
{
:geometry
=>
lambda
{
|
a
|
"300x300#"
}
:geometry
=>
lambda
{
|
a
|
"300x300#"
},
:convert_options
=>
lambda
{
|
a
|
"-do_stuff"
},
:source_file_options
=>
lambda
{
|
a
|
"-do_extra_stuff"
}
}
}
}
}
end
end
...
@@ -51,6 +53,8 @@ class StyleTest < Test::Unit::TestCase
...
@@ -51,6 +53,8 @@ class StyleTest < Test::Unit::TestCase
assert_equal
"300x300#"
,
@attachment
.
options
.
styles
[
:bar
].
geometry
assert_equal
"300x300#"
,
@attachment
.
options
.
styles
[
:bar
].
geometry
assert_equal
[
:test
],
@attachment
.
options
.
styles
[
:foo
].
processors
assert_equal
[
:test
],
@attachment
.
options
.
styles
[
:foo
].
processors
assert_equal
[
:test
],
@attachment
.
options
.
styles
[
:bar
].
processors
assert_equal
[
:test
],
@attachment
.
options
.
styles
[
:bar
].
processors
assert_equal
"-do_stuff"
,
@attachment
.
options
.
styles
[
:bar
].
convert_options
assert_equal
"-do_extra_stuff"
,
@attachment
.
options
.
styles
[
:bar
].
source_file_options
end
end
end
end
...
@@ -177,4 +181,29 @@ class StyleTest < Test::Unit::TestCase
...
@@ -177,4 +181,29 @@ class StyleTest < Test::Unit::TestCase
assert_equal
[
:test
],
@attachment
.
options
.
styles
[
:foo
].
processors
assert_equal
[
:test
],
@attachment
.
options
.
styles
[
:foo
].
processors
end
end
end
end
context
"An attachment with :convert_options and :source_file_options in :styles"
do
setup
do
@attachment
=
attachment
:path
=>
":basename.:extension"
,
:styles
=>
{
:thumb
=>
"100x100"
,
:large
=>
{
:geometry
=>
"400x400"
,
:convert_options
=>
"-do_stuff"
,
:source_file_options
=>
"-do_extra_stuff"
}
}
@file
=
StringIO
.
new
(
"..."
)
@file
.
stubs
(
:original_filename
).
returns
(
"file.jpg"
)
end
should
"have empty options for :thumb style"
do
assert_equal
""
,
@attachment
.
options
.
styles
[
:thumb
].
processor_options
[
:convert_options
]
assert_equal
""
,
@attachment
.
options
.
styles
[
:thumb
].
processor_options
[
:source_file_options
]
end
should
"have the right options for :large style"
do
assert_equal
"-do_stuff"
,
@attachment
.
options
.
styles
[
:large
].
processor_options
[
:convert_options
]
assert_equal
"-do_extra_stuff"
,
@attachment
.
options
.
styles
[
:large
].
processor_options
[
:source_file_options
]
end
end
end
end
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