paperclip-globalize3 2.0.0 → 2.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MjI1ODFiYzY1NGRiYzVmYmM0NTI2YTNhMDM0MTAwYzljYjIzMmE2Zg==
5
- data.tar.gz: !binary |-
6
- NDZkYjk4MWU4OTU3Nzk5NGQ0MDc0NDMwNWQzM2M0ZWU3MzllYjQzYw==
2
+ SHA1:
3
+ metadata.gz: a27d7f1cd8ff477e2c557c2c4f5d736f923b115d
4
+ data.tar.gz: df9d760d21fd2e45a13e99fb0fedb3e37b614916
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MjJkZDU5MTA1MzdiYzUzMzc2NDhmYWJiZGFkMTMxNzUyYjllOGMxMDgxZDFh
10
- MjU4N2QwNWQzYzFmODM2ODIyY2M1ZTBkNThmYTc4MmU4NjYwYWE3OGM2OGJi
11
- N2U1YzFiMGRmY2Y1MDYwODU3NWYyMDM2Njk3MjI2MGI5ODc2MDk=
12
- data.tar.gz: !binary |-
13
- NmQyYTg0YjM0N2M2MmI2MTc1MThmNDk2YTM0NzExMTk5MWM0MWVkNGNmODI3
14
- NTBiYjk4ZDlhMzZkY2E4Y2U0YTFkZGI1OTg5ZmVmZTZiNjBkMGQ2NzdiZWQy
15
- ZWUzNTc4MGQzNGIwYjI2ZmI0ZDJkYjExMDE1YThiMmE4NjhmMjM=
6
+ metadata.gz: a96c8d616f3d5e8e3955d196b0d1ce18bb2d35734450c6898696d56bf20c48d89aca349c61fddf65514bf1ab6785e9ecd4e5500ea5b479e8a31133cfb69659b2
7
+ data.tar.gz: c6098de0d37c1708279f743557877287b5970aba77a6d94f990d1599acf346a734e843109a937a285ca096ec3f3d22a91ac859a9f7aabade1969259175ffa81c
@@ -2,7 +2,7 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- - 2.1.3
5
+ - 2.1.5
6
6
  script: "bundle exec rake spec"
7
7
  gemfile:
8
8
  - gemfiles/rails_4.0_paperclip_4_1.gemfile
@@ -1,4 +1,4 @@
1
- Copyright (c) 2014 emjot GmbH & Co. KG
1
+ Copyright (c) 2015 emjot GmbH & Co. KG
2
2
 
3
3
  MIT License
4
4
 
@@ -4,13 +4,26 @@ require "paperclip/globalize3/attachment"
4
4
  require "globalize"
5
5
  require "paperclip"
6
6
 
7
- Paperclip.interpolates(:locale) { |attachment, _|
8
- if attachment.instance.send("#{attachment.name}_file_name").respond_to?(:translation_metadata)
9
- attachment.instance.send("#{attachment.name}_file_name").translation_metadata[:locale].to_s
10
- else
11
- Globalize.locale.to_s
12
- end
13
- }
7
+ # Paperclip locale interpolation: if locale fallbacks are used, we need to determine & use the fallback locale
8
+ Paperclip.interpolates(:locale) do |attachment, _style_name|
9
+ record = attachment.instance
10
+ file_name_attr = "#{attachment.name}_file_name"
11
+ attachment_locale =
12
+ if record.respond_to?(:translation) && record.translated?(file_name_attr)
13
+ # determine via metadata if activated (I18n::Backend::Simple.include(I18n::Backend::Metadata))
14
+ if record.send(file_name_attr).respond_to?(:translation_metadata)
15
+ record.send(file_name_attr).translation_metadata[:locale]
16
+ else # determine via globalize fallback configuration
17
+ (record.globalize_fallbacks(Globalize.locale) & record.translated_locales).first # (nil if record is new)
18
+ end
19
+ else
20
+ Rails.logger.warn(
21
+ "WARN You have used :locale in a paperclip url/path for an untranslated model (in #{record.class.to_s})."
22
+ )
23
+ nil
24
+ end
25
+ (attachment_locale || Globalize.locale).to_s
26
+ end
14
27
 
15
28
  unless Paperclip::Attachment.instance_methods.include?(:assign_attributes)
16
29
  Paperclip::Attachment.send(:include, Paperclip::Globalize3::Attachment::Compatibility::Paperclip41)
@@ -52,19 +52,25 @@ module Paperclip
52
52
 
53
53
  def queue_some_for_delete_with_globalize3(*args)
54
54
  options = args.extract_options!
55
- styles = args
55
+ styles = args
56
56
  with_locales_if_translated(options[:locales]) do
57
57
  queue_some_for_delete_without_globalize3(styles)
58
58
  end
59
59
  end
60
60
 
61
61
  # If translated, execute the block for the given locales only (or for all translated locales if none are given).
62
- # Otherwise, simply execute the block.
62
+ # If any locales are given, only those for which a translation exists are used.
63
+ # If attachment is untranslated, simply execute the block.
63
64
  def with_locales_if_translated(with_locales = nil, &block)
64
65
  if instance.respond_to?(:translated_locales) && instance.translated?(:"#{name}_file_name")
65
66
  # TODO translated_locales are not present any more when this is called via destroy callback (unless 'translates' is defined AFTER 'has_attached_file' in the model class)
66
- with_locales = instance.translated_locales if with_locales.nil?
67
- Globalize.with_locales([*with_locales]) { yield }
67
+ with_locales =
68
+ if with_locales.nil?
69
+ [*instance.translated_locales]
70
+ else
71
+ [*with_locales] & instance.translated_locales
72
+ end
73
+ Globalize.with_locales(with_locales) { yield }
68
74
  else
69
75
  yield
70
76
  end
@@ -1,5 +1,5 @@
1
1
  module Paperclip
2
2
  module Globalize3
3
- VERSION = "2.0.0"
3
+ VERSION = "2.1.0"
4
4
  end
5
5
  end
@@ -23,7 +23,7 @@ Gem::Specification.new do |spec|
23
23
 
24
24
  spec.add_development_dependency "bundler", "~> 1.3"
25
25
  spec.add_development_dependency "appraisal", "~> 0.5.1"
26
- spec.add_development_dependency "rspec-rails", "~> 2.14.1"
26
+ spec.add_development_dependency "rspec-rails", ["~> 2.14.1", "< 2.99"]
27
27
  spec.add_development_dependency "sqlite3"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "wwtd", "~> 0.5"
@@ -24,7 +24,7 @@ describe 'Paperclip::Globalize3::Attachment' do
24
24
 
25
25
  context 'with translations' do
26
26
 
27
- it 'should save different images for different locales' do
27
+ it 'saves different images for different locales' do
28
28
  p = Post.create
29
29
  Globalize.with_locale(:en) do
30
30
  p.image_file_name.should be_nil
@@ -46,7 +46,7 @@ describe 'Paperclip::Globalize3::Attachment' do
46
46
  Post.translation_class.count.should == 2
47
47
  end
48
48
 
49
- it 'should only overwrite the image file for the current locale on re-assign' do
49
+ it 'only overwrites the image file for the current locale on re-assign' do
50
50
  p = Post.create
51
51
  path_en = Globalize.with_locale(:en) do
52
52
  p.update_attributes!(:image => test_image_file)
@@ -70,7 +70,7 @@ describe 'Paperclip::Globalize3::Attachment' do
70
70
  File.exist?(path_de).should be_true
71
71
  end
72
72
 
73
- it 'should delete image files in all locales on destroy' do
73
+ it 'deletes image files in all locales on destroy' do
74
74
  p = Post.create
75
75
  path_en = Globalize.with_locale(:en) do
76
76
  p.update_attributes!(:image => test_image_file)
@@ -90,7 +90,7 @@ describe 'Paperclip::Globalize3::Attachment' do
90
90
 
91
91
  context 'with :only_process' do
92
92
 
93
- it 'should only clear the provided style in the current locale on assign' do
93
+ it 'only clears the provided style in the current locale on assign' do
94
94
  p = OnlyProcessPost.create
95
95
  p.image.should_receive(:queue_some_for_delete).with(:thumb, :locales => :en)
96
96
  p.image.should_not_receive(:queue_all_for_delete)
@@ -106,7 +106,7 @@ describe 'Paperclip::Globalize3::Attachment' do
106
106
 
107
107
  context 'without translations' do
108
108
 
109
- it 'should delete image files on destroy' do
109
+ it 'deletes image files on destroy' do
110
110
  p = Untranslated.create
111
111
  p.update_attributes!(:image => test_image_file)
112
112
  path = p.image.path
@@ -118,4 +118,34 @@ describe 'Paperclip::Globalize3::Attachment' do
118
118
 
119
119
  end
120
120
 
121
+ context 'with fallbacks' do
122
+ around :each do |example|
123
+ old_fallbacks = Globalize.fallbacks
124
+ Globalize.fallbacks = {en: [:en, :de], de: [:de, :en]}
125
+ example.run
126
+ Globalize.fallbacks = old_fallbacks
127
+ end
128
+
129
+ it 'interpolates the correct locale if fallback is used' do
130
+ p = nil
131
+ Globalize.with_locale(:en) { p = Post.new( image: test_image_file); p.save! }
132
+ Globalize.with_locale(:de) { expect(p.image.url).to match('/en/') }
133
+ end
134
+
135
+ it 'preserves attachments when a new translation is created' do
136
+ p = nil
137
+ Globalize.with_locale(:de) do
138
+ p = Post.new(image: test_image_file)
139
+ p.save!
140
+ end
141
+ Globalize.with_locale(:en) do
142
+ p.image = test_image_file
143
+ p.save!
144
+ end
145
+
146
+ Globalize.with_locale(:en) { expect(File.exists?(p.image.path)).to be_true }
147
+ Globalize.with_locale(:de) { expect(File.exists?(p.image.path)).to be_true }
148
+ end
149
+ end
150
+
121
151
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: paperclip-globalize3
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Maximilian Herold
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-09-25 00:00:00.000000000 Z
11
+ date: 2015-02-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: paperclip
@@ -73,6 +73,9 @@ dependencies:
73
73
  - - ~>
74
74
  - !ruby/object:Gem::Version
75
75
  version: 2.14.1
76
+ - - <
77
+ - !ruby/object:Gem::Version
78
+ version: '2.99'
76
79
  type: :development
77
80
  prerelease: false
78
81
  version_requirements: !ruby/object:Gem::Requirement
@@ -80,32 +83,35 @@ dependencies:
80
83
  - - ~>
81
84
  - !ruby/object:Gem::Version
82
85
  version: 2.14.1
86
+ - - <
87
+ - !ruby/object:Gem::Version
88
+ version: '2.99'
83
89
  - !ruby/object:Gem::Dependency
84
90
  name: sqlite3
85
91
  requirement: !ruby/object:Gem::Requirement
86
92
  requirements:
87
- - - ! '>='
93
+ - - '>='
88
94
  - !ruby/object:Gem::Version
89
95
  version: '0'
90
96
  type: :development
91
97
  prerelease: false
92
98
  version_requirements: !ruby/object:Gem::Requirement
93
99
  requirements:
94
- - - ! '>='
100
+ - - '>='
95
101
  - !ruby/object:Gem::Version
96
102
  version: '0'
97
103
  - !ruby/object:Gem::Dependency
98
104
  name: rake
99
105
  requirement: !ruby/object:Gem::Requirement
100
106
  requirements:
101
- - - ! '>='
107
+ - - '>='
102
108
  - !ruby/object:Gem::Version
103
109
  version: '0'
104
110
  type: :development
105
111
  prerelease: false
106
112
  version_requirements: !ruby/object:Gem::Requirement
107
113
  requirements:
108
- - - ! '>='
114
+ - - '>='
109
115
  - !ruby/object:Gem::Version
110
116
  version: '0'
111
117
  - !ruby/object:Gem::Dependency
@@ -163,17 +169,17 @@ require_paths:
163
169
  - lib
164
170
  required_ruby_version: !ruby/object:Gem::Requirement
165
171
  requirements:
166
- - - ! '>='
172
+ - - '>='
167
173
  - !ruby/object:Gem::Version
168
174
  version: '0'
169
175
  required_rubygems_version: !ruby/object:Gem::Requirement
170
176
  requirements:
171
- - - ! '>='
177
+ - - '>='
172
178
  - !ruby/object:Gem::Version
173
179
  version: '0'
174
180
  requirements: []
175
181
  rubyforge_project:
176
- rubygems_version: 2.2.2
182
+ rubygems_version: 2.4.5
177
183
  signing_key:
178
184
  specification_version: 4
179
185
  summary: locale-specific attachments with paperclip and globalize