card-mod-carrierwave 0.11.3 → 0.11.4

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
  SHA256:
3
- metadata.gz: d3780d7a761d471d21388bf3fd35501a6a5aeb0c2e81d8dd96c80cb455193ced
4
- data.tar.gz: ffea7deb06932ccdf53e45a58ef86404b52675d24fc583ea8b1541958143f2c3
3
+ metadata.gz: 4db88ba4c61088ed0c4b4f7f449391c40989dc9e65dab9351ba39adbca478ab3
4
+ data.tar.gz: 00eeb5ca66fcc328ab975537e1412c6321fe9698830ef0118b627f81e88a1a9f
5
5
  SHA512:
6
- metadata.gz: 2c5c2e376a1e068a70ec7bbc6f3675da0c6cb3de0e2e51e01f9bc4b34a18c453515a939b8d7372267b9a218acd111750876b50f682b8586ffb4fc47622bb06d0
7
- data.tar.gz: fe0acad939beedab5b5284f357089e2157095c97326b4486f0d8810111ddff23cfc7e75d058f8f034b3b25735d982823a85cfb946ab1fdc6d3ecef717b3c9010
6
+ metadata.gz: a9c4885adefd2d41ebbc579a427c06431b3b88539fba3723a27cccefe18603853ee21f8cce4423f7f4c52acbe83173b94bee094833d3db21b47ce46349b94ad9
7
+ data.tar.gz: c67f091d70fed1c80f7a842ac69f4f620547ef9b4679e9c48f036021f255be0c2a88b6ee81940c09c25b63b17056fca344b60d47b6c8d77bd437c655efd49f70
@@ -1,40 +1,4 @@
1
1
  module CarrierWave
2
- class << self
3
- def tmp_path
4
- @tmp_path ||= Card.paths["tmp"].existent.first
5
- end
6
- end
7
-
8
- class SanitizedFile
9
- def content_type
10
- # the original content_type method doesn't seem to be very reliable
11
- # It uses mime_magic_content_type - which returns invalid/invalid for css files
12
- # that start with a comment - as the second option. (we switch the order and
13
- # use it as the third option)
14
- @content_type ||=
15
- existing_content_type ||
16
- mini_mime_content_type ||
17
- mime_magic_content_type
18
- end
19
- end
20
-
21
- module Uploader
22
- # Implements a different name pattern for versions than CarrierWave's
23
- # default: we expect the version name at the end of the filename separated
24
- # by a dash
25
- module Versions
26
- private
27
-
28
- # put version at the end of the filename
29
- def full_filename for_file
30
- name = super(for_file)
31
- parts = name.split "."
32
- basename = [parts.shift, version_name].compact.join("-")
33
- "#{basename}.#{parts.join('.')}"
34
- end
35
- end
36
- end
37
-
38
2
  # Takes care of the file upload for cards with attached files.
39
3
  # Most of the upload behaviour depends on the card itself.
40
4
  # (e.g. card type and storage option chosen for the card). So in contrary
@@ -162,6 +126,7 @@ module CarrierWave
162
126
  class FileCardUploader < Uploader::Base
163
127
  attr_accessor :mod
164
128
  include Card::Env::Location
129
+ include Path
165
130
 
166
131
  STORAGE_TYPES = [:cloud, :web, :coded, :local].freeze
167
132
  CONFIG_OPTIONS = [:provider, :attributes, :directory, :public, :credentials,
@@ -230,54 +195,10 @@ module CarrierWave
230
195
  end
231
196
  end
232
197
 
233
- def local_url opts={}
234
- "%s/%s/%s" % [local_url_base(opts), file_dir, full_filename(url_filename(opts))]
235
- end
236
-
237
- def local_url_base opts={}
238
- web_path = Card.config.files_web_path
239
- opts.delete(:absolute) ? card_url(web_path) : card_path(web_path)
240
- end
241
-
242
- def public_path
243
- File.join Cardio.paths["public"].existent.first, url
244
- end
245
-
246
- def cache_dir
247
- @model.files_base_dir + "/cache"
248
- end
249
-
250
- # Carrierwave calls store_path without argument when it stores the file
251
- # and with the identifier from the db when it retrieves the file.
252
- # In our case the first part of our identifier is not part of the path
253
- # but we can construct the filename from db data. So we don't need the
254
- # identifier.
255
- def store_path for_file=nil
256
- if for_file
257
- retrieve_path
258
- else
259
- File.join([store_dir, full_filename(filename)].compact)
260
- end
261
- end
262
-
263
- def retrieve_path
264
- File.join([retrieve_dir, full_filename(filename)].compact)
265
- end
266
-
267
- def tmp_path
268
- Dir.mkdir model.tmp_upload_dir unless Dir.exist? model.tmp_upload_dir
269
- File.join model.tmp_upload_dir, filename
270
- end
271
-
272
198
  def create_versions? new_file
273
199
  model.create_versions? new_file
274
200
  end
275
201
 
276
- # paperclip compatibility used in type/file.rb#core (base format)
277
- def path version=nil
278
- version ? versions[version].path : super()
279
- end
280
-
281
202
  def original_filename
282
203
  @original_filename ||= model.selected_action&.comment
283
204
  end
@@ -316,4 +237,34 @@ module CarrierWave
316
237
  end
317
238
  end
318
239
  end
240
+
241
+ class SanitizedFile
242
+ def content_type
243
+ # the original content_type method doesn't seem to be very reliable
244
+ # It uses mime_magic_content_type - which returns invalid/invalid for css files
245
+ # that start with a comment - as the second option. (we switch the order and
246
+ # use it as the third option)
247
+ @content_type ||=
248
+ existing_content_type ||
249
+ mini_mime_content_type ||
250
+ mime_magic_content_type
251
+ end
252
+ end
253
+
254
+ module Uploader
255
+ # Implements a different name pattern for versions than CarrierWave's
256
+ # default: we expect the version name at the end of the filename separated
257
+ # by a dash
258
+ module Versions
259
+ private
260
+
261
+ # put version at the end of the filename
262
+ def full_filename for_file
263
+ name = super(for_file)
264
+ parts = name.split "."
265
+ basename = [parts.shift, version_name].compact.join("-")
266
+ "#{basename}.#{parts.join('.')}"
267
+ end
268
+ end
269
+ end
319
270
  end
@@ -0,0 +1,54 @@
1
+ module CarrierWave
2
+ def self.tmp_path
3
+ @tmp_path ||= Card.paths["tmp"].existent.first
4
+ end
5
+
6
+ class FileCardUploader
7
+ # path-related methods for uploader
8
+ module Path
9
+ def local_url opts={}
10
+ "%s/%s/%s" % [local_url_base(opts), file_dir, full_filename(url_filename(opts))]
11
+ end
12
+
13
+ def local_url_base opts={}
14
+ web_path = Card.config.files_web_path
15
+ opts.delete(:absolute) ? card_url(web_path) : card_path(web_path)
16
+ end
17
+
18
+ def public_path
19
+ File.join Cardio.paths["public"].existent.first, url
20
+ end
21
+
22
+ def cache_dir
23
+ @model.files_base_dir + "/cache"
24
+ end
25
+
26
+ # Carrierwave calls store_path without argument when it stores the file
27
+ # and with the identifier from the db when it retrieves the file.
28
+ # In our case the first part of our identifier is not part of the path
29
+ # but we can construct the filename from db data. So we don't need the
30
+ # identifier.
31
+ def store_path for_file=nil
32
+ if for_file
33
+ retrieve_path
34
+ else
35
+ File.join([store_dir, full_filename(filename)].compact)
36
+ end
37
+ end
38
+
39
+ def retrieve_path
40
+ File.join([retrieve_dir, full_filename(filename)].compact)
41
+ end
42
+
43
+ def tmp_path
44
+ Dir.mkdir model.tmp_upload_dir unless Dir.exist? model.tmp_upload_dir
45
+ File.join model.tmp_upload_dir, filename
46
+ end
47
+
48
+ # paperclip compatibility used in type/file.rb#core (base format)
49
+ def path version=nil
50
+ version ? versions[version].path : super()
51
+ end
52
+ end
53
+ end
54
+ end
@@ -110,7 +110,7 @@ rescue StandardError => e
110
110
  end
111
111
 
112
112
  def detect_extension ext
113
- return unless (mime_types = Mime::Types[attachment.content_type])
113
+ return unless (mime_types = MIME::Types[attachment.content_type])
114
114
 
115
115
  recognized_extension?(mime_types, ext) ? ext : mime_types[0].extensions[0]
116
116
  end
@@ -11,7 +11,7 @@ event :validate_storage_type_update, :validate, on: :update, when: :cloud? do
11
11
  # `update storage_type: :local, file: [file handle]` is ok
12
12
  return unless storage_type_changed? && !attachment_is_changing?
13
13
 
14
- errors.add :storage_type, tr(:moving_files_is_not_supported)
14
+ errors.add :storage_type, t(:carrierwave_moving_files_is_not_supported)
15
15
  end
16
16
 
17
17
  def bucket
@@ -5,8 +5,12 @@ event :lose_coded_status_on_update, :initialize, on: :update, when: :coded? do
5
5
  end
6
6
 
7
7
  event :validate_coded_storage_type, :validate, on: :save, when: :will_become_coded? do
8
- errors.add :storage_type, tr(:mod_argument_needed_to_save) unless mod || @new_mod
9
- errors.add :storage_type, tr(:codename_needed_for_storage) if codename.blank?
8
+ storage_type_error :mod_argument_needed_to_save unless mod || @new_mod
9
+ storage_type_error :codename_needed_for_storage if codename.blank?
10
+ end
11
+
12
+ def storage_type_error error_name
13
+ errors.add :storage_type, t("carrierwave_#{error_name}")
10
14
  end
11
15
 
12
16
  def will_become_coded?
@@ -14,12 +14,9 @@ event :storage_type_change, :store, on: :update, when: :storage_type_changed? do
14
14
  end
15
15
 
16
16
  event :validate_storage_type, :validate, on: :save do
17
- unless known_storage_type? will_be_stored_as
18
- errors.add :storage_type, tr(
19
- :unknown_storage_type,
20
- new_storage_type: @new_storage_type
21
- )
22
- end
17
+ return if known_storage_type? will_be_stored_as
18
+
19
+ errors.add :storage_type, unknown_storage_type(@new_storage_type)
23
20
  end
24
21
 
25
22
  def will_be_stored_as
@@ -93,7 +90,7 @@ def valid_storage_type_list
93
90
  end
94
91
 
95
92
  def invalid_storage_type! type
96
- raise Card::Error, tr(:error_invalid_storage_type, type: type)
93
+ raise Card::Error, t(:carrierwave_error_invalid_storage_type, type: type)
97
94
  end
98
95
 
99
96
  def storage_type_from_content
@@ -133,19 +130,21 @@ def storage_type= value
133
130
  end
134
131
 
135
132
  def with_storage_options opts={}
136
- old_values = {}
133
+ old_values = stash_and_set_storage_options opts
137
134
  validate_temporary_storage_type_change opts[:storage_type]
138
- %i[storage_type mod bucket].each do |opt_name|
139
- next unless opts[opt_name]
140
- old_values[opt_name] = instance_variable_get "@#{opt_name}"
141
- instance_variable_set "@#{opt_name}", opts[opt_name]
142
- @temp_storage_type = true
143
- end
135
+ @temp_storage_type = true
144
136
  yield
145
137
  ensure
146
138
  @temp_storage_type = false
147
- old_values.each do |key, val|
148
- instance_variable_set "@#{key}", val
139
+ old_values.each { |key, val| instance_variable_set "@#{key}", val }
140
+ end
141
+
142
+ def stash_and_set_storage_options opts
143
+ %i[storage_type mod bucket].each_with_object({}) do |opt_name, old_values|
144
+ next unless opts[opt_name]
145
+ old_values[opt_name] = instance_variable_get "@#{opt_name}"
146
+ instance_variable_set "@#{opt_name}", opts[opt_name]
147
+ old_values
149
148
  end
150
149
  end
151
150
 
@@ -153,14 +152,10 @@ def temporary_storage_type_change?
153
152
  @temp_storage_type
154
153
  end
155
154
 
156
- def validate_temporary_storage_type_change new_storage_type=nil
157
- new_storage_type ||= @new_storage_type
158
- return unless new_storage_type
159
- unless known_storage_type? new_storage_type
160
- raise Error, tr(:unknown_storage_type, new_storage_type: new_storage_type)
161
- end
162
-
163
- if new_storage_type == :coded && codename.blank?
155
+ def validate_temporary_storage_type_change type=nil
156
+ return unless (type ||= @new_storage_type)
157
+ raise Error, unknown_storage_type(type) unless known_storage_type? type
158
+ if type == :coded && codename.blank?
164
159
  raise Error, "codename needed for storage type :coded"
165
160
  end
166
161
  end
@@ -168,3 +163,7 @@ end
168
163
  def known_storage_type? type=storage_type
169
164
  type.in? CarrierWave::FileCardUploader::STORAGE_TYPES
170
165
  end
166
+
167
+ def unknown_storage_type type
168
+ t :carrierwave_unknown_storage_type, new_storage_type: type
169
+ end
data/set/type/file.rb CHANGED
@@ -38,7 +38,7 @@ format do
38
38
  block_given? ? yield(source) : source
39
39
  rescue => e
40
40
  Rails.logger.info "Error with file source: #{e.message}"
41
- tr :file_error
41
+ t :carrierwave_file_error
42
42
  end
43
43
 
44
44
  def selected_version
@@ -77,7 +77,7 @@ end
77
77
  format :html do
78
78
  view :core do
79
79
  handle_source do |source|
80
- "<a href=\"#{source}\">#{tr :download, title: title_in_context(voo.title)}</a>"
80
+ haml :core, source: source
81
81
  end
82
82
  end
83
83
 
@@ -111,6 +111,6 @@ format :html do
111
111
  end
112
112
 
113
113
  def preview_editor_delete_text
114
- tr :delete
114
+ t :carrierwave_delete
115
115
  end
116
116
  end
@@ -0,0 +1,2 @@
1
+ %a{ href: source }<
2
+ = t :carrierwave_download, title: title_in_context(voo.title)
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: card-mod-carrierwave
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.11.3
4
+ version: 0.11.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ethan McCutchen
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2021-04-01 00:00:00.000000000 Z
13
+ date: 2021-05-05 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: card
@@ -18,14 +18,14 @@ dependencies:
18
18
  requirements:
19
19
  - - '='
20
20
  - !ruby/object:Gem::Version
21
- version: 1.101.3
21
+ version: 1.101.4
22
22
  type: :runtime
23
23
  prerelease: false
24
24
  version_requirements: !ruby/object:Gem::Requirement
25
25
  requirements:
26
26
  - - '='
27
27
  - !ruby/object:Gem::Version
28
- version: 1.101.3
28
+ version: 1.101.4
29
29
  - !ruby/object:Gem::Dependency
30
30
  name: carrierwave
31
31
  requirement: !ruby/object:Gem::Requirement
@@ -60,28 +60,28 @@ dependencies:
60
60
  requirements:
61
61
  - - '='
62
62
  - !ruby/object:Gem::Version
63
- version: 0.11.3
63
+ version: 0.11.4
64
64
  type: :runtime
65
65
  prerelease: false
66
66
  version_requirements: !ruby/object:Gem::Requirement
67
67
  requirements:
68
68
  - - '='
69
69
  - !ruby/object:Gem::Version
70
- version: 0.11.3
70
+ version: 0.11.4
71
71
  - !ruby/object:Gem::Dependency
72
72
  name: card-mod-permissions
73
73
  requirement: !ruby/object:Gem::Requirement
74
74
  requirements:
75
75
  - - '='
76
76
  - !ruby/object:Gem::Version
77
- version: 0.11.3
77
+ version: 0.11.4
78
78
  type: :runtime
79
79
  prerelease: false
80
80
  version_requirements: !ruby/object:Gem::Requirement
81
81
  requirements:
82
82
  - - '='
83
83
  - !ruby/object:Gem::Version
84
- version: 0.11.3
84
+ version: 0.11.4
85
85
  description: ''
86
86
  email:
87
87
  - info@decko.org
@@ -92,6 +92,7 @@ files:
92
92
  - config/core_initializers/carrierwave.rb
93
93
  - lib/carrier_wave/card_mount.rb
94
94
  - lib/carrier_wave/file_card_uploader.rb
95
+ - lib/carrier_wave/file_card_uploader/path.rb
95
96
  - lib/carrier_wave/image_card_uploader.rb
96
97
  - set/abstract/attachment.rb
97
98
  - set/abstract/attachment/cloud.rb
@@ -107,6 +108,7 @@ files:
107
108
  - set/self/new_file.rb
108
109
  - set/self/new_image.rb
109
110
  - set/type/file.rb
111
+ - set/type/file/core.haml
110
112
  - set/type/file/file_chooser.haml
111
113
  - set/type/file/preview_editor.haml
112
114
  - set/type/image.rb