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
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
29 deletions
+35
-29
lib/paperclip.rb
+5
-0
lib/paperclip/attachment.rb
+18
-12
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
...
@@ -73,6 +73,11 @@ module Paperclip
def
included
base
#:nodoc:
def
included
base
#:nodoc:
base
.
extend
ClassMethods
base
.
extend
ClassMethods
end
end
def
processor
name
name
=
name
.
to_s
.
camelize
Paperclip
.
const_get
(
name
)
if
Paperclip
.
const_defined?
(
name
)
end
end
end
class
PaperclipError
<
StandardError
#:nodoc:
class
PaperclipError
<
StandardError
#:nodoc:
...
...
lib/paperclip/attachment.rb
View file @
f79a822f
...
@@ -33,8 +33,9 @@ module Paperclip
...
@@ -33,8 +33,9 @@ module Paperclip
@validations
=
options
[
:validations
]
@validations
=
options
[
:validations
]
@default_style
=
options
[
:default_style
]
@default_style
=
options
[
:default_style
]
@storage
=
options
[
:storage
]
@storage
=
options
[
:storage
]
@whiny
_thumbnails
=
options
[
:whiny_thumbnails
]
@whiny
=
options
[
:whiny_thumbnails
]
@convert_options
=
options
[
:convert_options
]
||
{}
@convert_options
=
options
[
:convert_options
]
||
{}
@processors
=
[
:thumbnail
]
@options
=
options
@options
=
options
@queued_for_delete
=
[]
@queued_for_delete
=
[]
@queued_for_write
=
{}
@queued_for_write
=
{}
...
@@ -181,7 +182,7 @@ module Paperclip
...
@@ -181,7 +182,7 @@ module Paperclip
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
.
last
)
||
((
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
},
...
@@ -255,9 +256,17 @@ module Paperclip
...
@@ -255,9 +256,17 @@ module Paperclip
def
normalize_style_definition
def
normalize_style_definition
@styles
.
each
do
|
name
,
args
|
@styles
.
each
do
|
name
,
args
|
unless
args
.
is_a?
Hash
dimensions
,
format
=
[
args
,
nil
].
flatten
[
0
..
1
]
dimensions
,
format
=
[
args
,
nil
].
flatten
[
0
..
1
]
format
=
nil
if
format
==
""
format
=
nil
if
format
.
blank?
@styles
[
name
]
=
[
dimensions
,
format
]
@styles
[
name
]
=
{
:processors
=>
@processors
,
:geometry
=>
dimensions
,
:format
=>
format
,
:whiny
=>
@whiny
,
:convert_options
=>
extra_options_for
(
name
)
}
end
end
end
end
end
...
@@ -277,15 +286,12 @@ module Paperclip
...
@@ -277,15 +286,12 @@ module Paperclip
logger
.
info
(
"[paperclip] Post-processing
#{
name
}
"
)
logger
.
info
(
"[paperclip] Post-processing
#{
name
}
"
)
@styles
.
each
do
|
name
,
args
|
@styles
.
each
do
|
name
,
args
|
begin
begin
dimensions
,
format
=
args
@queued_for_write
[
name
]
=
@queued_for_write
[
:original
]
dimensions
=
dimensions
.
call
(
instance
)
if
dimensions
.
respond_to?
:call
args
[
:processors
].
each
do
|
processor
|
@queued_for_write
[
name
]
=
Thumbnail
.
make
(
@queued_for_write
[
:original
],
@queued_for_write
[
name
]
=
Paperclip
.
processor
(
processor
).
make
(
@queued_for_write
[
name
],
args
)
dimensions
,
end
format
,
extra_options_for
(
name
),
@whiny_thumbnails
)
rescue
PaperclipError
=>
e
rescue
PaperclipError
=>
e
(
@errors
[
:processing
]
||=
[])
<<
e
.
message
if
@whiny
_thumbnails
(
@errors
[
:processing
]
||=
[])
<<
e
.
message
if
@whiny
end
end
end
end
callback
(
:"after_
#{
name
}
_post_process"
)
callback
(
:"after_
#{
name
}
_post_process"
)
...
...
test/attachment_test.rb
View file @
f79a822f
...
@@ -117,6 +117,7 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -117,6 +117,7 @@ class AttachmentTest < Test::Unit::TestCase
:thumb
=>
"-thumbnailize"
:thumb
=>
"-thumbnailize"
}
}
@dummy
=
Dummy
.
new
@dummy
=
Dummy
.
new
@dummy
.
avatar
end
end
should
"report the correct options when sent #extra_options_for(:thumb)"
do
should
"report the correct options when sent #extra_options_for(:thumb)"
do
...
@@ -127,23 +128,9 @@ class AttachmentTest < Test::Unit::TestCase
...
@@ -127,23 +128,9 @@ class AttachmentTest < Test::Unit::TestCase
assert_equal
"-do_stuff"
,
@dummy
.
avatar
.
send
(
:extra_options_for
,
:large
)
assert_equal
"-do_stuff"
,
@dummy
.
avatar
.
send
(
:extra_options_for
,
:large
)
end
end
context
"when given a file"
do
before_should
"call extra_options_for(:thumb/:large)"
do
setup
do
Paperclip
::
Attachment
.
any_instance
.
expects
(
:extra_options_for
).
with
(
:thumb
)
@file
=
File
.
new
(
File
.
join
(
File
.
dirname
(
__FILE__
),
Paperclip
::
Attachment
.
any_instance
.
expects
(
:extra_options_for
).
with
(
:large
)
"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
end
end
end
end
...
...
test/paperclip_test.rb
View file @
f79a822f
...
@@ -10,6 +10,14 @@ class PaperclipTest < Test::Unit::TestCase
...
@@ -10,6 +10,14 @@ class PaperclipTest < Test::Unit::TestCase
end
end
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
"Paperclip.bit_bucket"
do
context
"on systems without /dev/null"
do
context
"on systems without /dev/null"
do
setup
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