roachclip 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/MIT-LICENSE +20 -0
- data/README +40 -0
- data/Rakefile +20 -0
- data/VERSION +1 -0
- data/lib/roachclip.rb +62 -0
- data/lib/roachclip/version.rb +3 -0
- data/roachclip.gemspec +65 -0
- data/script/runner.rb +11 -0
- data/test/data/fonz.jpg +0 -0
- data/test/test_helper.rb +7 -0
- data/test/unit/test_helper.rb +1 -0
- data/test/unit/test_roachclip.rb +82 -0
- metadata +130 -0
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2009 Ryan Angilly
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
=Roachclip
|
2
|
+
|
3
|
+
Joint lets you do:
|
4
|
+
|
5
|
+
class Doc
|
6
|
+
include MongoMapper::Document
|
7
|
+
plugin Joint
|
8
|
+
|
9
|
+
attachment :image
|
10
|
+
end
|
11
|
+
|
12
|
+
And stores everything in GridFS, but doesn't have any image processing
|
13
|
+
|
14
|
+
Paperclip lets you do:
|
15
|
+
|
16
|
+
class Doc < ActiveRecord::Base
|
17
|
+
has_attached_file :image, :styles => {:thumb => {:geometry => '50x50>'}, :large => {:geometry => '500x500>'}}
|
18
|
+
end
|
19
|
+
|
20
|
+
But is attached to ActiveRecord and wants to work w/ a regular filesystem.
|
21
|
+
|
22
|
+
Roachclip lets you do:
|
23
|
+
|
24
|
+
class Doc
|
25
|
+
include MongoMapper::Document
|
26
|
+
plugin Roachclip
|
27
|
+
|
28
|
+
roachclip :image, :styles => {:thumb => {:geometry => '50x50>'}, :large => {:geometry => '500x500>'}}
|
29
|
+
end
|
30
|
+
|
31
|
+
Which combines Joint's GridFS-ness with Paperclip's image processing-ness
|
32
|
+
|
33
|
+
= License
|
34
|
+
|
35
|
+
roachclip is released under the MIT license.
|
36
|
+
|
37
|
+
|
38
|
+
= Support
|
39
|
+
|
40
|
+
Just email me at ryan@angilly.com with questions, bugs, or patches.
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
begin
|
2
|
+
require 'jeweler'
|
3
|
+
Jeweler::Tasks.new do |gemspec|
|
4
|
+
gemspec.name = "roachclip"
|
5
|
+
gemspec.summary = "MongoMapper plugin for Joint/Paperclip bliss"
|
6
|
+
gemspec.description = "Let you upload images and have use paperclip's hotness to post process them"
|
7
|
+
gemspec.email = "ryan@angilly.com"
|
8
|
+
gemspec.homepage = "http://github.com/ryana/roachclip"
|
9
|
+
gemspec.authors = ["Ryan Angilly"]
|
10
|
+
|
11
|
+
gemspec.add_dependency 'joint', '0.3.2'
|
12
|
+
gemspec.add_dependency 'paperclip', '2.3.3'
|
13
|
+
|
14
|
+
gemspec.add_development_dependency 'shoulda', '2.11.0'
|
15
|
+
gemspec.add_development_dependency 'mongo_mapper', '0.8.2'
|
16
|
+
end
|
17
|
+
Jeweler::GemcutterTasks.new
|
18
|
+
rescue LoadError
|
19
|
+
puts "Jeweler not available. Install it with: gem install jeweler"
|
20
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.1.0
|
data/lib/roachclip.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
require 'set'
|
2
|
+
require 'tempfile'
|
3
|
+
require 'paperclip'
|
4
|
+
require 'joint'
|
5
|
+
|
6
|
+
module Paperclip
|
7
|
+
class << self
|
8
|
+
def log *args
|
9
|
+
end
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
module Roachclip
|
14
|
+
autoload :Version, 'roachclip/version'
|
15
|
+
|
16
|
+
class InvalidAttachment < StandardError; end
|
17
|
+
|
18
|
+
def self.configure(model)
|
19
|
+
model.plugin Joint
|
20
|
+
model.class_inheritable_accessor :roaches
|
21
|
+
model.roaches = Set.new
|
22
|
+
end
|
23
|
+
|
24
|
+
module ClassMethods
|
25
|
+
def roachclip name, options
|
26
|
+
self.attachment name
|
27
|
+
|
28
|
+
raise InvalidAttachment unless attachment_names.include?(name)
|
29
|
+
|
30
|
+
self.roaches << {:name => name, :options => options}
|
31
|
+
|
32
|
+
options[:styles].each { |k,v| self.attachment "#{name}_#{k}"}
|
33
|
+
|
34
|
+
before_save :process_roaches
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
module InstanceMethods
|
39
|
+
def process_roaches
|
40
|
+
roaches.each do |img|
|
41
|
+
name = img[:name]
|
42
|
+
styles = img[:options][:styles]
|
43
|
+
|
44
|
+
return unless assigned_attachments[name]
|
45
|
+
|
46
|
+
src = Tempfile.new ["roachclip", name.to_s].join('.')
|
47
|
+
src.write assigned_attachments[name].read
|
48
|
+
src.close
|
49
|
+
|
50
|
+
assigned_attachments[name].rewind
|
51
|
+
|
52
|
+
styles.keys.each do |style_key|
|
53
|
+
thumbnail = Paperclip::Thumbnail.new src, styles[style_key]
|
54
|
+
tmp_file_name = thumbnail.make
|
55
|
+
stored_file_name = send("#{name}_name").gsub(/\.(\w*)\Z/) { "_#{style_key}.#{$1}" }
|
56
|
+
send "#{name}_#{style_key}=", tmp_file_name
|
57
|
+
send "#{name}_#{style_key}_name=", stored_file_name
|
58
|
+
end
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
data/roachclip.gemspec
ADDED
@@ -0,0 +1,65 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run the gemspec command
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{roachclip}
|
8
|
+
s.version = "0.1.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Ryan Angilly"]
|
12
|
+
s.date = %q{2010-06-23}
|
13
|
+
s.description = %q{Let you upload images and have use paperclip's hotness to post process them}
|
14
|
+
s.email = %q{ryan@angilly.com}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"README"
|
17
|
+
]
|
18
|
+
s.files = [
|
19
|
+
"MIT-LICENSE",
|
20
|
+
"README",
|
21
|
+
"Rakefile",
|
22
|
+
"VERSION",
|
23
|
+
"lib/roachclip.rb",
|
24
|
+
"lib/roachclip/version.rb",
|
25
|
+
"roachclip.gemspec",
|
26
|
+
"script/runner.rb",
|
27
|
+
"test/data/fonz.jpg",
|
28
|
+
"test/test_helper.rb",
|
29
|
+
"test/unit/test_helper.rb",
|
30
|
+
"test/unit/test_roachclip.rb"
|
31
|
+
]
|
32
|
+
s.homepage = %q{http://github.com/ryana/roachclip}
|
33
|
+
s.rdoc_options = ["--charset=UTF-8"]
|
34
|
+
s.require_paths = ["lib"]
|
35
|
+
s.rubygems_version = %q{1.3.6}
|
36
|
+
s.summary = %q{MongoMapper plugin for Joint/Paperclip bliss}
|
37
|
+
s.test_files = [
|
38
|
+
"test/test_helper.rb",
|
39
|
+
"test/unit/test_helper.rb",
|
40
|
+
"test/unit/test_roachclip.rb"
|
41
|
+
]
|
42
|
+
|
43
|
+
if s.respond_to? :specification_version then
|
44
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
45
|
+
s.specification_version = 3
|
46
|
+
|
47
|
+
if Gem::Version.new(Gem::RubyGemsVersion) >= Gem::Version.new('1.2.0') then
|
48
|
+
s.add_runtime_dependency(%q<joint>, ["= 0.3.2"])
|
49
|
+
s.add_runtime_dependency(%q<paperclip>, ["= 2.3.3"])
|
50
|
+
s.add_development_dependency(%q<shoulda>, ["= 2.11.0"])
|
51
|
+
s.add_development_dependency(%q<mongo_mapper>, ["= 0.8.2"])
|
52
|
+
else
|
53
|
+
s.add_dependency(%q<joint>, ["= 0.3.2"])
|
54
|
+
s.add_dependency(%q<paperclip>, ["= 2.3.3"])
|
55
|
+
s.add_dependency(%q<shoulda>, ["= 2.11.0"])
|
56
|
+
s.add_dependency(%q<mongo_mapper>, ["= 0.8.2"])
|
57
|
+
end
|
58
|
+
else
|
59
|
+
s.add_dependency(%q<joint>, ["= 0.3.2"])
|
60
|
+
s.add_dependency(%q<paperclip>, ["= 2.3.3"])
|
61
|
+
s.add_dependency(%q<shoulda>, ["= 2.11.0"])
|
62
|
+
s.add_dependency(%q<mongo_mapper>, ["= 0.8.2"])
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
data/script/runner.rb
ADDED
@@ -0,0 +1,11 @@
|
|
1
|
+
require 'mongo_mapper'
|
2
|
+
require File.join(File.dirname(__FILE__), '..', 'lib', 'roachclip')
|
3
|
+
|
4
|
+
MongoMapper.database = 'roachclip-runner'
|
5
|
+
|
6
|
+
class Sample
|
7
|
+
include MongoMapper::Document
|
8
|
+
plugin Roachclip
|
9
|
+
|
10
|
+
roachclip :images, :styles => {:thumb => {:geometry => '50x50>'}, :large => {:geometry => '500x500>'}}
|
11
|
+
end
|
data/test/data/fonz.jpg
ADDED
Binary file
|
data/test/test_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
@@ -0,0 +1,82 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'test_helper')
|
2
|
+
|
3
|
+
class RoachclipTest < Test::Unit::TestCase
|
4
|
+
|
5
|
+
class Doc
|
6
|
+
include MongoMapper::Document
|
7
|
+
end
|
8
|
+
|
9
|
+
MongoMapper.database = 'roachclip-test'
|
10
|
+
|
11
|
+
def teardown
|
12
|
+
Doc.all.each &:destroy
|
13
|
+
end
|
14
|
+
|
15
|
+
should "overwrite Paperclip.log" do
|
16
|
+
assert_nothing_raised {Paperclip.log "some info"}
|
17
|
+
end
|
18
|
+
|
19
|
+
context "A document with Roachclip and Joint plugged in" do
|
20
|
+
setup do
|
21
|
+
Doc.plugin Roachclip
|
22
|
+
end
|
23
|
+
|
24
|
+
should "plugin Roachclip" do
|
25
|
+
assert Doc.respond_to?(:roachclip)
|
26
|
+
end
|
27
|
+
|
28
|
+
should "get roaches" do
|
29
|
+
assert Doc.respond_to?(:roaches)
|
30
|
+
assert Doc.respond_to?(:roaches=)
|
31
|
+
end
|
32
|
+
|
33
|
+
should "add images to roaches" do
|
34
|
+
opts = {:styles => {:thumb => {:geometry => '50x50'}}}
|
35
|
+
Doc.roachclip :image, opts
|
36
|
+
|
37
|
+
assert Doc.roaches.find {|x| x == {:name => :image, :options => opts} }
|
38
|
+
end
|
39
|
+
|
40
|
+
context "with large and thumb" do
|
41
|
+
setup do
|
42
|
+
@opts = {:styles => {:thumb => {:geometry => '50x50'}, :large => {:geometry => '500x500>'}}}
|
43
|
+
Doc.roachclip :image, @opts
|
44
|
+
end
|
45
|
+
|
46
|
+
should "add attachments for each option style" do
|
47
|
+
d = Doc.new
|
48
|
+
|
49
|
+
assert d.respond_to?(:image_thumb)
|
50
|
+
assert d.respond_to?(:image_thumb=)
|
51
|
+
assert d.respond_to?(:image_large)
|
52
|
+
assert d.respond_to?(:image_large=)
|
53
|
+
end
|
54
|
+
|
55
|
+
context "with a saved document w/ image" do
|
56
|
+
setup do
|
57
|
+
@fname = 'fonz.jpg'
|
58
|
+
@test_file_path = File.join(File.dirname(__FILE__), '..', 'data', @fname)
|
59
|
+
@doc = Doc.new
|
60
|
+
@doc.image = File.open(@test_file_path)
|
61
|
+
|
62
|
+
assert @doc.save
|
63
|
+
end
|
64
|
+
|
65
|
+
should "still save documents w/ images" do
|
66
|
+
d = Doc.find @doc.id
|
67
|
+
|
68
|
+
assert_equal @fname, d.image_name
|
69
|
+
assert_equal File.size(@test_file_path), d.image_size
|
70
|
+
end
|
71
|
+
|
72
|
+
should "have thumb and large" do
|
73
|
+
assert @doc.image_thumb.size > 0
|
74
|
+
assert @doc.image_large.size > 0
|
75
|
+
|
76
|
+
assert_equal 'fonz_thumb.jpg', @doc.image_thumb_name
|
77
|
+
assert_equal 'fonz_large.jpg', @doc.image_large_name
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: roachclip
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Ryan Angilly
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2010-06-23 00:00:00 -04:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: joint
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - "="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 0
|
29
|
+
- 3
|
30
|
+
- 2
|
31
|
+
version: 0.3.2
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: paperclip
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - "="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 2
|
43
|
+
- 3
|
44
|
+
- 3
|
45
|
+
version: 2.3.3
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: shoulda
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - "="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 2
|
57
|
+
- 11
|
58
|
+
- 0
|
59
|
+
version: 2.11.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: mongo_mapper
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - "="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
- 8
|
72
|
+
- 2
|
73
|
+
version: 0.8.2
|
74
|
+
type: :development
|
75
|
+
version_requirements: *id004
|
76
|
+
description: Let you upload images and have use paperclip's hotness to post process them
|
77
|
+
email: ryan@angilly.com
|
78
|
+
executables: []
|
79
|
+
|
80
|
+
extensions: []
|
81
|
+
|
82
|
+
extra_rdoc_files:
|
83
|
+
- README
|
84
|
+
files:
|
85
|
+
- MIT-LICENSE
|
86
|
+
- README
|
87
|
+
- Rakefile
|
88
|
+
- VERSION
|
89
|
+
- lib/roachclip.rb
|
90
|
+
- lib/roachclip/version.rb
|
91
|
+
- roachclip.gemspec
|
92
|
+
- script/runner.rb
|
93
|
+
- test/data/fonz.jpg
|
94
|
+
- test/test_helper.rb
|
95
|
+
- test/unit/test_helper.rb
|
96
|
+
- test/unit/test_roachclip.rb
|
97
|
+
has_rdoc: true
|
98
|
+
homepage: http://github.com/ryana/roachclip
|
99
|
+
licenses: []
|
100
|
+
|
101
|
+
post_install_message:
|
102
|
+
rdoc_options:
|
103
|
+
- --charset=UTF-8
|
104
|
+
require_paths:
|
105
|
+
- lib
|
106
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
segments:
|
111
|
+
- 0
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
segments:
|
118
|
+
- 0
|
119
|
+
version: "0"
|
120
|
+
requirements: []
|
121
|
+
|
122
|
+
rubyforge_project:
|
123
|
+
rubygems_version: 1.3.6
|
124
|
+
signing_key:
|
125
|
+
specification_version: 3
|
126
|
+
summary: MongoMapper plugin for Joint/Paperclip bliss
|
127
|
+
test_files:
|
128
|
+
- test/test_helper.rb
|
129
|
+
- test/unit/test_helper.rb
|
130
|
+
- test/unit/test_roachclip.rb
|