paperdragon 0.0.5 → 0.0.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/lib/paperdragon/attachment.rb +1 -1
- data/lib/paperdragon/metadata.rb +7 -14
- data/lib/paperdragon/model.rb +2 -2
- data/lib/paperdragon/version.rb +1 -1
- data/test/attachment_test.rb +1 -1
- data/test/metadata_test.rb +6 -8
- data/test/model_test.rb +35 -0
- data/test/task_test.rb +9 -0
- data/test/test_helper.rb +5 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7ae7a952a0d1b965849bfd22d565fe9e8a839935
|
4
|
+
data.tar.gz: 9b4f84cd5d10ecc7cc66ad4e407c0f0e2396956f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0e2550a838b86707593ba45bc64d71748bc1828099439e39cc81fd0b298f29d04460fe854619554bdd47c39a5167dbd8ec39a9835acc42a2e244bc99f803bade
|
7
|
+
data.tar.gz: c1278828b15d425f0237667ec2643cdc358796f19a5e571c584b3b07dc1f87970ca51fb972b5f3f3b99240d24ac44fd29540f5929f9abbbd1249b48784b42030
|
data/README.md
CHANGED
@@ -4,7 +4,7 @@ _Explicit image processing._
|
|
4
4
|
|
5
5
|
## Summary
|
6
6
|
|
7
|
-
Paperdragon gives you image processing as known from [Paperclip](https://github.com/thoughtbot/paperclip, [CarrierWave](https://github.com/carrierwaveuploader/carrierwave) or [Dragonfly](https://github.com/markevans/dragonfly). It allows uploading, cropping, resizing, watermarking, maintaining different versions of an image, and so on.
|
7
|
+
Paperdragon gives you image processing as known from [Paperclip](https://github.com/thoughtbot/paperclip), [CarrierWave](https://github.com/carrierwaveuploader/carrierwave) or [Dragonfly](https://github.com/markevans/dragonfly). It allows uploading, cropping, resizing, watermarking, maintaining different versions of an image, and so on.
|
8
8
|
|
9
9
|
It provides a very explicit DSL: **No magic is happening behind the scenes, paperdragon makes _you_ implement the processing steps.**
|
10
10
|
|
@@ -15,7 +15,7 @@ module Paperdragon
|
|
15
15
|
|
16
16
|
module InstanceMethods
|
17
17
|
def initialize(metadata, options={})
|
18
|
-
@metadata = Metadata
|
18
|
+
@metadata = Metadata[metadata]
|
19
19
|
@options = options # to be used in #(re)build_uid for your convenience. # DISCUSS: we pass in the model here - is that what we want?
|
20
20
|
end
|
21
21
|
attr_reader :metadata # TODO: test me.
|
data/lib/paperdragon/metadata.rb
CHANGED
@@ -3,29 +3,22 @@ module Paperdragon
|
|
3
3
|
# Metadata.new(nil)[:original][:width] => ""
|
4
4
|
# Holds metadata for an attachment. This is a hash keyed by versions, e.g. +:original+,
|
5
5
|
# +:thumb+, and so on.
|
6
|
-
class Metadata
|
7
|
-
def
|
8
|
-
|
6
|
+
class Metadata < Hash
|
7
|
+
def self.[](hash) # allow Metadata[nil]
|
8
|
+
super hash || {}
|
9
9
|
end
|
10
10
|
|
11
11
|
def [](name)
|
12
|
-
|
12
|
+
super || {}
|
13
13
|
end
|
14
14
|
|
15
15
|
def populated?
|
16
|
-
|
17
|
-
end
|
18
|
-
|
19
|
-
def merge!(hash)
|
20
|
-
@hash.merge!(hash)
|
21
|
-
end
|
22
|
-
|
23
|
-
def dup
|
24
|
-
self.class.new(@hash.dup)
|
16
|
+
size > 0
|
25
17
|
end
|
26
18
|
|
19
|
+
# Consider this semi-public. This is used the make the metadata hash serialisable (as a plain hash).
|
27
20
|
def to_hash
|
28
|
-
|
21
|
+
Hash[self]
|
29
22
|
end
|
30
23
|
end
|
31
24
|
end
|
data/lib/paperdragon/model.rb
CHANGED
@@ -13,8 +13,8 @@ module Paperdragon
|
|
13
13
|
# Creates Avatar#image that returns a Paperdragon::File instance.
|
14
14
|
def attachment_accessor_for(name, attachment_class)
|
15
15
|
mod = Module.new do # TODO: abstract that into Uber, we use it everywhere.
|
16
|
-
define_method name do |file=nil, &block|
|
17
|
-
attachment = attachment_class.new(self.image_meta_data, {:model => self})
|
16
|
+
define_method name do |file=nil, options={}, &block|
|
17
|
+
attachment = attachment_class.new(self.image_meta_data, options.merge({:model => self}))
|
18
18
|
|
19
19
|
return attachment unless file or block
|
20
20
|
|
data/lib/paperdragon/version.rb
CHANGED
data/test/attachment_test.rb
CHANGED
data/test/metadata_test.rb
CHANGED
@@ -9,7 +9,7 @@ class MetadataTest < MiniTest::Spec
|
|
9
9
|
}
|
10
10
|
}
|
11
11
|
|
12
|
-
subject { Paperdragon::Metadata
|
12
|
+
subject { Paperdragon::Metadata[valid] }
|
13
13
|
|
14
14
|
it { subject.populated?.must_equal true }
|
15
15
|
it { subject[:original][:width].must_equal 960 }
|
@@ -22,7 +22,7 @@ class MetadataTest < MiniTest::Spec
|
|
22
22
|
|
23
23
|
|
24
24
|
describe "nil" do
|
25
|
-
subject { Paperdragon::Metadata
|
25
|
+
subject { Paperdragon::Metadata[nil] }
|
26
26
|
|
27
27
|
it { subject.populated?.must_equal false }
|
28
28
|
it { subject[:page].must_equal({}) }
|
@@ -30,7 +30,7 @@ class MetadataTest < MiniTest::Spec
|
|
30
30
|
end
|
31
31
|
|
32
32
|
describe "empty hash" do
|
33
|
-
subject { Paperdragon::Metadata
|
33
|
+
subject { Paperdragon::Metadata[{}] }
|
34
34
|
|
35
35
|
it { subject.populated?.must_equal false }
|
36
36
|
it { subject[:page].must_equal({}) }
|
@@ -42,13 +42,11 @@ class MetadataTest < MiniTest::Spec
|
|
42
42
|
# #dup
|
43
43
|
# don't change original hash.
|
44
44
|
it do
|
45
|
-
Paperdragon::Metadata
|
45
|
+
Paperdragon::Metadata[original].dup.merge!(:additional => {})
|
46
46
|
original[:additional].must_equal nil
|
47
47
|
end
|
48
48
|
|
49
|
-
# #merge!
|
50
|
-
it { Paperdragon::Metadata.new(original).merge!(:additional => {}).to_hash.must_equal({:original=>{}, :additional=>{}}) }
|
51
|
-
|
52
49
|
# #to_hash
|
53
|
-
it { Paperdragon::Metadata
|
50
|
+
it { Paperdragon::Metadata[original].to_hash.must_equal({:original=>{}}) }
|
51
|
+
it { Paperdragon::Metadata[original].to_hash.class.must_equal(Hash) }
|
54
52
|
end
|
data/test/model_test.rb
CHANGED
@@ -47,6 +47,41 @@ class PaperdragonModelTest < MiniTest::Spec
|
|
47
47
|
v.reprocess!(:thumb, "1") { |j| j.thumb!("8x8") }
|
48
48
|
end
|
49
49
|
|
50
|
+
model.image_meta_data.class.must_equal Hash
|
50
51
|
model.image_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>8, :height=>2, :uid=>"thumb-apotomo-1.png"}})
|
51
52
|
end
|
53
|
+
|
54
|
+
|
55
|
+
# passing options from image(file, {..}) to the Attachment.
|
56
|
+
class ImageWithAttachment < OpenStruct
|
57
|
+
include Paperdragon::Model
|
58
|
+
|
59
|
+
class Attachment < Paperdragon::Attachment
|
60
|
+
def build_uid(style, file)
|
61
|
+
@options.inspect # we use options here!
|
62
|
+
end
|
63
|
+
|
64
|
+
def rebuild_uid(style, file)
|
65
|
+
@options.inspect
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
processable :image, Attachment
|
70
|
+
end
|
71
|
+
|
72
|
+
it do
|
73
|
+
model = ImageWithAttachment.new
|
74
|
+
model.image(logo, :path => "/") do |v|
|
75
|
+
v.process!(:original)
|
76
|
+
end
|
77
|
+
|
78
|
+
# this assures that both :model and :path (see above) are passed through.
|
79
|
+
model.image_meta_data.must_equal({:original=>{:width=>216, :height=>63, :uid=>"{:path=>\"/\", :model=>_<PaperdragonModelTest::ImageWithAttachment>}"}})
|
80
|
+
|
81
|
+
model.image(nil, :new => true) do |v|
|
82
|
+
v.reprocess!(:original, "1") { |j| j.thumb!("8x8") }
|
83
|
+
end
|
84
|
+
|
85
|
+
model.image_meta_data.must_equal({:original=>{:width=>8, :height=>2, :uid=>"{:new=>true, :model=>#<PaperdragonModelTest::ImageWithAttachment image_meta_data={:original=>{:width=>216, :height=>63, :uid=>\"{:path=>\\\"/\\\", :model=>_<PaperdragonModelTest::ImageWithAttachment>}\"}}>}"}})
|
86
|
+
end
|
52
87
|
end
|
data/test/task_test.rb
CHANGED
@@ -18,6 +18,15 @@ class TaskSpec < MiniTest::Spec
|
|
18
18
|
t.process!(:thumb) { |j| j.thumb!("16x16") }
|
19
19
|
end.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :thumb=>{:width=>16, :height=>5, :uid=>"thumb-apotomo.png"}})
|
20
20
|
end
|
21
|
+
|
22
|
+
# modify metadata in task
|
23
|
+
it do
|
24
|
+
Attachment.new({:processing => true, :approved => true}).task(logo) do |t|
|
25
|
+
t.process!(:original)
|
26
|
+
t.metadata.delete(:processing)
|
27
|
+
end.must_equal({:original=>{:width=>216, :height=>63, :uid=>"original-apotomo.png"}, :approved => true})
|
28
|
+
end
|
29
|
+
|
21
30
|
end
|
22
31
|
|
23
32
|
# task without block
|
data/test/test_helper.rb
CHANGED