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
338fc353
Commit
338fc353
authored
Mar 07, 2011
by
yar
Committed by
Jon Yurek
Mar 09, 2011
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
selectively reprocessing attachment styles
parent
cf41b01c
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
82 additions
and
8 deletions
+82
-8
lib/paperclip/attachment.rb
+10
-8
test/integration_test.rb
+72
-0
No files found.
lib/paperclip/attachment.rb
View file @
338fc353
...
...
@@ -241,7 +241,7 @@ module Paperclip
# in the paperclip:refresh rake task and that's it. It will regenerate all
# thumbnails forcefully, by reobtaining the original file and going through
# the post-process again.
def
reprocess!
def
reprocess!
(
*
style_args
)
new_original
=
Tempfile
.
new
(
"paperclip-reprocess"
)
new_original
.
binmode
if
old_original
=
to_file
(
:original
)
...
...
@@ -249,7 +249,7 @@ module Paperclip
new_original
.
rewind
@queued_for_write
=
{
:original
=>
new_original
}
post_process
post_process
(
*
style_args
)
old_original
.
close
if
old_original
.
respond_to?
(
:close
)
...
...
@@ -324,21 +324,23 @@ module Paperclip
[
style_options
,
all_options
].
compact
.
join
(
" "
)
end
def
post_process
#:nodoc:
def
post_process
(
*
style_args
)
#:nodoc:
return
if
@queued_for_write
[
:original
].
nil?
instance
.
run_paperclip_callbacks
(
:post_process
)
do
instance
.
run_paperclip_callbacks
(
:"
#{
name
}
_post_process"
)
do
post_process_styles
post_process_styles
(
*
style_args
)
end
end
end
def
post_process_styles
#:nodoc:
def
post_process_styles
(
*
style_args
)
#:nodoc:
styles
.
each
do
|
name
,
style
|
begin
raise
RuntimeError
.
new
(
"Style
#{
name
}
has no processors defined."
)
if
style
.
processors
.
blank?
@queued_for_write
[
name
]
=
style
.
processors
.
inject
(
@queued_for_write
[
:original
])
do
|
file
,
processor
|
Paperclip
.
processor
(
processor
).
make
(
file
,
style
.
processor_options
,
self
)
if
style_args
.
empty?
||
style_args
.
include?
(
name
)
raise
RuntimeError
.
new
(
"Style
#{
name
}
has no processors defined."
)
if
style
.
processors
.
blank?
@queued_for_write
[
name
]
=
style
.
processors
.
inject
(
@queued_for_write
[
:original
])
do
|
file
,
processor
|
Paperclip
.
processor
(
processor
).
make
(
file
,
style
.
processor_options
,
self
)
end
end
rescue
PaperclipError
=>
e
log
(
"An error was received while processing:
#{
e
.
inspect
}
"
)
...
...
test/integration_test.rb
View file @
338fc353
...
...
@@ -69,6 +69,78 @@ class IntegrationTest < Test::Unit::TestCase
end
end
context
"Attachment"
do
setup
do
@thumb_path
=
"./test/../public/system/avatars/1/thumb/5k.png"
File
.
delete
(
@thumb_path
)
if
File
.
exists?
(
@thumb_path
)
rebuild_model
:styles
=>
{
:thumb
=>
"50x50#"
}
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
),
'rb'
)
end
teardown
{
@file
.
close
}
should
"not create the thumbnails upon saving when post-processing is disabled"
do
@dummy
.
avatar
.
post_processing
=
false
@dummy
.
avatar
=
@file
assert
@dummy
.
save
assert
!
File
.
exists?
(
@thumb_path
)
end
should
"create the thumbnails upon saving when post_processing is enabled"
do
@dummy
.
avatar
.
post_processing
=
true
@dummy
.
avatar
=
@file
assert
@dummy
.
save
assert
File
.
exists?
(
@thumb_path
)
end
end
context
"Attachment with no generated thumbnails"
do
setup
do
@thumb_small_path
=
"./test/../public/system/avatars/1/thumb_small/5k.png"
@thumb_large_path
=
"./test/../public/system/avatars/1/thumb_large/5k.png"
File
.
delete
(
@thumb_small_path
)
if
File
.
exists?
(
@thumb_small_path
)
File
.
delete
(
@thumb_large_path
)
if
File
.
exists?
(
@thumb_large_path
)
rebuild_model
:styles
=>
{
:thumb_small
=>
"50x50#"
,
:thumb_large
=>
"60x60#"
}
@dummy
=
Dummy
.
new
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
"fixtures"
,
"5k.png"
),
'rb'
)
@dummy
.
avatar
.
post_processing
=
false
@dummy
.
avatar
=
@file
assert
@dummy
.
save
@dummy
.
avatar
.
post_processing
=
true
end
teardown
{
@file
.
close
}
should
"allow us to create all thumbnails in one go"
do
assert
!
File
.
exists?
(
@thumb_small_path
)
assert
!
File
.
exists?
(
@thumb_large_path
)
@dummy
.
avatar
.
reprocess!
assert
File
.
exists?
(
@thumb_small_path
)
assert
File
.
exists?
(
@thumb_large_path
)
end
should
"allow us to selectively create each thumbnail"
do
assert
!
File
.
exists?
(
@thumb_small_path
)
assert
!
File
.
exists?
(
@thumb_large_path
)
@dummy
.
avatar
.
reprocess!
:thumb_small
assert
File
.
exists?
(
@thumb_small_path
)
assert
!
File
.
exists?
(
@thumb_large_path
)
@dummy
.
avatar
.
reprocess!
:thumb_large
assert
File
.
exists?
(
@thumb_large_path
)
end
end
context
"A model that modifies its original"
do
setup
do
rebuild_model
:styles
=>
{
:original
=>
"2x2#"
}
...
...
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