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
f1118c6b
Commit
f1118c6b
authored
Dec 24, 2008
by
Jon Yurek
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added Paperclip::Processor as a necessary superclass of Thumbnail (and all processors)
parent
5a731302
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
45 additions
and
11 deletions
+45
-11
lib/paperclip.rb
+9
-1
lib/paperclip/processor.rb
+17
-0
lib/paperclip/thumbnail.rb
+3
-8
test/paperclip_test.rb
+6
-2
test/processor_test.rb
+10
-0
No files found.
lib/paperclip.rb
View file @
f1118c6b
...
@@ -29,9 +29,15 @@ require 'tempfile'
...
@@ -29,9 +29,15 @@ require 'tempfile'
require
'paperclip/upfile'
require
'paperclip/upfile'
require
'paperclip/iostream'
require
'paperclip/iostream'
require
'paperclip/geometry'
require
'paperclip/geometry'
require
'paperclip/processor'
require
'paperclip/thumbnail'
require
'paperclip/thumbnail'
require
'paperclip/storage'
require
'paperclip/storage'
require
'paperclip/attachment'
require
'paperclip/attachment'
if
defined?
RAILS_ROOT
Dir
.
glob
(
File
.
join
(
File
.
expand_path
(
RAILS_ROOT
),
"lib"
,
"paperclip_processors"
,
"*.rb"
)).
each
do
|
processor
|
require
processor
end
end
# The base module that gets included in ActiveRecord::Base. See the
# The base module that gets included in ActiveRecord::Base. See the
# documentation for Paperclip::ClassMethods for more useful information.
# documentation for Paperclip::ClassMethods for more useful information.
...
@@ -81,7 +87,9 @@ module Paperclip
...
@@ -81,7 +87,9 @@ module Paperclip
def
processor
name
def
processor
name
name
=
name
.
to_s
.
camelize
name
=
name
.
to_s
.
camelize
Paperclip
.
const_get
(
name
)
if
Paperclip
.
const_defined?
(
name
)
processor
=
Paperclip
.
const_get
(
name
)
raise
PaperclipError
.
new
(
"Processor
#{
name
}
was not found"
)
unless
processor
.
ancestors
.
include?
(
Paperclip
::
Processor
)
processor
end
end
end
end
...
...
lib/paperclip/processor.rb
0 → 100644
View file @
f1118c6b
module
Paperclip
class
Processor
attr_accessor
:file
,
:options
def
initialize
file
,
options
=
{}
@file
=
file
@options
=
options
end
def
make
end
def
self
.
make
file
,
options
=
{}
new
(
file
,
options
).
make
end
end
end
lib/paperclip/thumbnail.rb
View file @
f1118c6b
module
Paperclip
module
Paperclip
# Handles thumbnailing images that are uploaded.
# Handles thumbnailing images that are uploaded.
class
Thumbnail
class
Thumbnail
<
Processor
attr_accessor
:
file
,
:
current_geometry
,
:target_geometry
,
:format
,
:whiny
,
:convert_options
attr_accessor
:current_geometry
,
:target_geometry
,
:format
,
:whiny
,
:convert_options
# Creates a Thumbnail object set to work on the +file+ given. It
# Creates a Thumbnail object set to work on the +file+ given. It
# will attempt to transform the image into one defined by +target_geometry+
# will attempt to transform the image into one defined by +target_geometry+
...
@@ -11,6 +11,7 @@ module Paperclip
...
@@ -11,6 +11,7 @@ module Paperclip
# +whiny+ is true (which it is, by default. If +convert_options+ is
# +whiny+ is true (which it is, by default. If +convert_options+ is
# set, the options will be appended to the convert command upon image conversion
# set, the options will be appended to the convert command upon image conversion
def
initialize
file
,
options
=
{}
def
initialize
file
,
options
=
{}
super
geometry
=
options
[
:geometry
]
geometry
=
options
[
:geometry
]
@file
=
file
@file
=
file
@crop
=
geometry
[
-
1
,
1
]
==
'#'
@crop
=
geometry
[
-
1
,
1
]
==
'#'
...
@@ -24,12 +25,6 @@ module Paperclip
...
@@ -24,12 +25,6 @@ module Paperclip
@basename
=
File
.
basename
(
@file
.
path
,
@current_format
)
@basename
=
File
.
basename
(
@file
.
path
,
@current_format
)
end
end
# Creates a thumbnail, as specified in +initialize+, +make+s it, and returns the
# resulting Tempfile.
def
self
.
make
file
,
options
=
{}
new
(
file
,
options
).
make
end
# Returns true if the +target_geometry+ is meant to crop.
# Returns true if the +target_geometry+ is meant to crop.
def
crop?
def
crop?
@crop
@crop
...
...
test/paperclip_test.rb
View file @
f1118c6b
...
@@ -32,8 +32,12 @@ class PaperclipTest < Test::Unit::TestCase
...
@@ -32,8 +32,12 @@ 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
should
"raise when sent #processor and the name of a class that exists but isn't a subclass of Processor"
do
assert_nil
Paperclip
.
processor
(
:boogey_man
)
assert_raises
(
Paperclip
::
PaperclipError
){
Paperclip
.
processor
(
:attachment
)
}
end
should
"raise when sent #processor and the name of a class that doesn't exist"
do
assert_raises
(
NameError
){
Paperclip
.
processor
(
:boogey_man
)
}
end
end
should
"return a class when sent #processor and the name of a class under Paperclip"
do
should
"return a class when sent #processor and the name of a class under Paperclip"
do
...
...
test/processor_test.rb
0 → 100644
View file @
f1118c6b
require
'test/helper'
class
ProcessorTest
<
Test
::
Unit
::
TestCase
should
"instantiate and call #make when sent #make to the class"
do
processor
=
mock
processor
.
expects
(
:make
).
with
()
Paperclip
::
Processor
.
expects
(
:new
).
with
(
:one
,
:two
).
returns
(
processor
)
Paperclip
::
Processor
.
make
(
:one
,
:two
)
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