paperdragon 0.0.5 → 0.0.6

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 4c124aecf9f335b22baf9214604df964e1a965dd
4
- data.tar.gz: 6328ab40a1eead17adc5b399678383cc88761a48
3
+ metadata.gz: 7ae7a952a0d1b965849bfd22d565fe9e8a839935
4
+ data.tar.gz: 9b4f84cd5d10ecc7cc66ad4e407c0f0e2396956f
5
5
  SHA512:
6
- metadata.gz: 0fc0da95f318aeab85656c5d76cc06e008e0fb2cddfac3da524501f1633f5cd04ef9fedc14ce11badc2e1a91ea3259482d9f1b95d5609523eca446163e0880ac
7
- data.tar.gz: e6b9f994f29266b394c5d8c5999b40425a2808002419dea331bf628985d746a4f2bf7e331c495204441de4bbcf84c0fae753be2e021f7b74b8a77dabbc9221cc
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.new(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.
@@ -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 initialize(hash)
8
- @hash = hash || {}
6
+ class Metadata < Hash
7
+ def self.[](hash) # allow Metadata[nil]
8
+ super hash || {}
9
9
  end
10
10
 
11
11
  def [](name)
12
- @hash[name] || {}
12
+ super || {}
13
13
  end
14
14
 
15
15
  def populated?
16
- @hash.size > 0
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
- @hash
21
+ Hash[self]
29
22
  end
30
23
  end
31
24
  end
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Paperdragon
2
- VERSION = "0.0.5"
2
+ VERSION = "0.0.6"
3
3
  end
@@ -3,7 +3,7 @@ require 'test_helper'
3
3
  class AttachmentSpec < MiniTest::Spec
4
4
  class Attachment < Paperdragon::Attachment
5
5
  private
6
- def uid_from(style)
6
+ def uid_from(style, file)
7
7
  "/uid/#{style}"
8
8
  end
9
9
  end
@@ -9,7 +9,7 @@ class MetadataTest < MiniTest::Spec
9
9
  }
10
10
  }
11
11
 
12
- subject { Paperdragon::Metadata.new(valid) }
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.new(nil) }
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.new({}) }
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.new(original).dup.merge!(:additional => {})
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.new(original).to_hash.must_equal({:original=>{}}) }
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
@@ -9,4 +9,9 @@ MiniTest::Spec.class_eval do
9
9
  def generate_uid
10
10
  Dragonfly.app.datastore.send(:relative_path_for, "aptomo.png")
11
11
  end
12
+
13
+ def self.it(name=nil, *args)
14
+ name ||= Random.rand
15
+ super
16
+ end
12
17
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperdragon
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.5
4
+ version: 0.0.6
5
5
  platform: ruby
6
6
  authors:
7
7
  - Nick Sutterer