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
f79a822f
Commit
f79a822f
authored
Dec 23, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Modified post_process to handle Thumbnail's new interface. Munged styles into preferred format.
parent
ee70992b
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
36 additions
and
30 deletions
+36
-30
lib/paperclip.rb
+5
-0
lib/paperclip/attachment.rb
+19
-13
test/attachment_test.rb
+4
-17
test/paperclip_test.rb
+8
-0
No files found.
lib/paperclip.rb
View file @
f79a822f
...
...
@@ -73,6 +73,11 @@ module Paperclip
def
included
base
#:nodoc:
base
.
extend
ClassMethods
end
def
processor
name
name
=
name
.
to_s
.
camelize
Paperclip
.
const_get
(
name
)
if
Paperclip
.
const_defined?
(
name
)
end
end
class
PaperclipError
<
StandardError
#:nodoc:
...
...
lib/paperclip/attachment.rb
View file @
f79a822f
...
...
@@ -33,8 +33,9 @@ module Paperclip
@validations
=
options
[
:validations
]
@default_style
=
options
[
:default_style
]
@storage
=
options
[
:storage
]
@whiny
_thumbnails
=
options
[
:whiny_thumbnails
]
@whiny
=
options
[
:whiny_thumbnails
]
@convert_options
=
options
[
:convert_options
]
||
{}
@processors
=
[
:thumbnail
]
@options
=
options
@queued_for_delete
=
[]
@queued_for_write
=
{}
...
...
@@ -181,7 +182,7 @@ module Paperclip
attachment
.
original_filename
.
gsub
(
/
#{
File
.
extname
(
attachment
.
original_filename
)
}
$/
,
""
)
end
,
:extension
=>
lambda
do
|
attachment
,
style
|
((
style
=
attachment
.
styles
[
style
])
&&
style
.
last
)
||
((
style
=
attachment
.
styles
[
style
])
&&
style
[
:format
]
)
||
File
.
extname
(
attachment
.
original_filename
).
gsub
(
/^\.+/
,
""
)
end
,
:id
=>
lambda
{
|
attachment
,
style
|
attachment
.
instance
.
id
},
...
...
@@ -255,9 +256,17 @@ module Paperclip
def
normalize_style_definition
@styles
.
each
do
|
name
,
args
|
dimensions
,
format
=
[
args
,
nil
].
flatten
[
0
..
1
]
format
=
nil
if
format
==
""
@styles
[
name
]
=
[
dimensions
,
format
]
unless
args
.
is_a?
Hash
dimensions
,
format
=
[
args
,
nil
].
flatten
[
0
..
1
]
format
=
nil
if
format
.
blank?
@styles
[
name
]
=
{
:processors
=>
@processors
,
:geometry
=>
dimensions
,
:format
=>
format
,
:whiny
=>
@whiny
,
:convert_options
=>
extra_options_for
(
name
)
}
end
end
end
...
...
@@ -277,15 +286,12 @@ module Paperclip
logger
.
info
(
"[paperclip] Post-processing
#{
name
}
"
)
@styles
.
each
do
|
name
,
args
|
begin
dimensions
,
format
=
args
dimensions
=
dimensions
.
call
(
instance
)
if
dimensions
.
respond_to?
:call
@queued_for_write
[
name
]
=
Thumbnail
.
make
(
@queued_for_write
[
:original
],
dimensions
,
format
,
extra_options_for
(
name
),
@whiny_thumbnails
)
@queued_for_write
[
name
]
=
@queued_for_write
[
:original
]
args
[
:processors
].
each
do
|
processor
|
@queued_for_write
[
name
]
=
Paperclip
.
processor
(
processor
).
make
(
@queued_for_write
[
name
],
args
)
end
rescue
PaperclipError
=>
e
(
@errors
[
:processing
]
||=
[])
<<
e
.
message
if
@whiny
_thumbnails
(
@errors
[
:processing
]
||=
[])
<<
e
.
message
if
@whiny
end
end
callback
(
:"after_
#{
name
}
_post_process"
)
...
...
test/attachment_test.rb
View file @
f79a822f
...
...
@@ -117,6 +117,7 @@ class AttachmentTest < Test::Unit::TestCase
:thumb
=>
"-thumbnailize"
}
@dummy
=
Dummy
.
new
@dummy
.
avatar
end
should
"report the correct options when sent #extra_options_for(:thumb)"
do
...
...
@@ -127,23 +128,9 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal
"-do_stuff"
,
@dummy
.
avatar
.
send
(
:extra_options_for
,
:large
)
end
context
"when given a file"
do
setup
do
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
),
'rb'
)
Paperclip
::
Thumbnail
.
stubs
(
:make
)
[
:thumb
,
:large
].
each
do
|
style
|
@dummy
.
avatar
.
stubs
(
:extra_options_for
).
with
(
style
)
end
end
[
:thumb
,
:large
].
each
do
|
style
|
should
"call extra_options_for(
#{
style
}
)"
do
@dummy
.
avatar
.
expects
(
:extra_options_for
).
with
(
style
)
@dummy
.
avatar
=
@file
end
end
before_should
"call extra_options_for(:thumb/:large)"
do
Paperclip
::
Attachment
.
any_instance
.
expects
(
:extra_options_for
).
with
(
:thumb
)
Paperclip
::
Attachment
.
any_instance
.
expects
(
:extra_options_for
).
with
(
:large
)
end
end
...
...
test/paperclip_test.rb
View file @
f79a822f
...
...
@@ -10,6 +10,14 @@ class PaperclipTest < Test::Unit::TestCase
end
end
should
"return nil when sent #processor and the name of a class that doesn't exist"
do
assert_nil
Paperclip
.
processor
(
:boogey_man
)
end
should
"return a class when sent #processor and the name of a class under Paperclip"
do
assert_equal
::
Paperclip
::
Thumbnail
,
Paperclip
.
processor
(
:thumbnail
)
end
context
"Paperclip.bit_bucket"
do
context
"on systems without /dev/null"
do
setup
do
...
...
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