card-mod-carrierwave 0.11.3 → 0.11.7

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: bb935d915f6d43df67ffd9f655d792588816386ab9ecb3bcb9ba33103d15f6fe
4
+ data.tar.gz: '08bd07bc39c702082d299deaa43208e2a5344bf497658e5e86ace039534b283c'
5
5
  SHA512:
6
- metadata.gz: 2c5c2e376a1e068a70ec7bbc6f3675da0c6cb3de0e2e51e01f9bc4b34a18c453515a939b8d7372267b9a218acd111750876b50f682b8586ffb4fc47622bb06d0
7
- data.tar.gz: fe0acad939beedab5b5284f357089e2157095c97326b4486f0d8810111ddff23cfc7e75d058f8f034b3b25735d982823a85cfb946ab1fdc6d3ecef717b3c9010
6
+ metadata.gz: 2853818c6e980fe6ca987d76ef8ec8c442d881311382694315b00040fd9fd2039fda78701338638c37c85dc5cd98e9110a4c57a7358047945e6ef5ea315fed04
7
+ data.tar.gz: da7d7911ec9180946ab6d4dbd16bd487105ab3e7017c0875aa2bb53aa952fb9e5a135b5cead2ae4aaf68f4713ab519821e13a5d729374fdf84c4eb0e276fe48e
@@ -28,14 +28,17 @@ module CarrierWave
28
28
  on: :delete, when: proc { |c| !c.history? } do
29
29
  remove_#{column}!
30
30
  end
31
+
31
32
  event :mark_remove_#{column}_false_event, :finalize,
32
33
  on: :update do
33
34
  mark_remove_#{column}_false
34
35
  end
36
+
35
37
  event :store_previous_changes_for_#{column}_event, :store,
36
38
  on: :update, when: proc { |c| !c.history? } do
37
39
  store_previous_changes_for_#{column}
38
40
  end
41
+
39
42
  event :remove_previously_stored_#{column}_event, :finalize,
40
43
  on: :update, when: proc { |c| !c.history?} do
41
44
  remove_previously_stored_#{column}
@@ -68,6 +71,7 @@ module CarrierWave
68
71
 
69
72
  def #{column}=(new_file)
70
73
  return if new_file.blank?
74
+ self.selected_action_id = Time.now.to_i unless history?
71
75
  assign_file(new_file) { super }
72
76
  end
73
77
 
@@ -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
@@ -161,15 +125,17 @@ module CarrierWave
161
125
  #
162
126
  class FileCardUploader < Uploader::Base
163
127
  attr_accessor :mod
128
+
164
129
  include Card::Env::Location
130
+ include Path
165
131
 
166
- STORAGE_TYPES = [:cloud, :web, :coded, :local].freeze
167
- CONFIG_OPTIONS = [:provider, :attributes, :directory, :public, :credentials,
168
- :authenticated_url_expiration, :use_ssl_for_aws].freeze
169
- CONFIG_CREDENTIAL_OPTIONS = [
170
- :provider,
171
- :aws_access_key_id, :aws_secret_access_key, :region, :host, :endpoint,
172
- :google_access_key_id, :google_secret_access_key
132
+ STORAGE_TYPES = %i[cloud web coded local].freeze
133
+ CONFIG_OPTIONS = %i[provider attributes directory public credentials
134
+ authenticated_url_expiration use_ssl_for_aws].freeze
135
+ CONFIG_CREDENTIAL_OPTIONS = %i[
136
+ provider
137
+ aws_access_key_id aws_secret_access_key region host endpoint
138
+ google_access_key_id google_secret_access_key
173
139
  ].freeze
174
140
  delegate :store_dir, :retrieve_dir, :file_dir, :mod, :bucket, to: :model
175
141
 
@@ -205,6 +171,7 @@ module CarrierWave
205
171
  model.with_storage_options opts do
206
172
  return model.content if model.web?
207
173
  return "" unless file.present?
174
+
208
175
  "%s/%s" % [file_dir, url_filename]
209
176
  end
210
177
  end
@@ -230,54 +197,10 @@ module CarrierWave
230
197
  end
231
198
  end
232
199
 
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
200
  def create_versions? new_file
273
201
  model.create_versions? new_file
274
202
  end
275
203
 
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
204
  def original_filename
282
205
  @original_filename ||= model.selected_action&.comment
283
206
  end
@@ -316,4 +239,34 @@ module CarrierWave
316
239
  end
317
240
  end
318
241
  end
242
+
243
+ class SanitizedFile
244
+ def content_type
245
+ # the original content_type method doesn't seem to be very reliable
246
+ # It uses mime_magic_content_type - which returns invalid/invalid for css files
247
+ # that start with a comment - as the second option. (we switch the order and
248
+ # use it as the third option)
249
+ @content_type ||=
250
+ existing_content_type ||
251
+ mini_mime_content_type ||
252
+ mime_magic_content_type
253
+ end
254
+ end
255
+
256
+ module Uploader
257
+ # Implements a different name pattern for versions than CarrierWave's
258
+ # default: we expect the version name at the end of the filename separated
259
+ # by a dash
260
+ module Versions
261
+ private
262
+
263
+ # put version at the end of the filename
264
+ def full_filename for_file
265
+ name = super(for_file)
266
+ parts = name.split "."
267
+ basename = [parts.shift, version_name].compact.join("-")
268
+ "#{basename}.#{parts.join('.')}"
269
+ end
270
+ end
271
+ end
319
272
  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
@@ -10,7 +10,7 @@ module CarrierWave
10
10
  include CarrierWave::MiniMagick
11
11
 
12
12
  def path version=nil
13
- (version && version != :original) ? versions[version].path : super()
13
+ version && version != :original ? versions[version].path : super()
14
14
  end
15
15
 
16
16
  version :icon, if: :create_versions?, from_version: :small do
@@ -17,11 +17,13 @@ end
17
17
 
18
18
  event :save_original_filename, :prepare_to_store, on: :save, when: :file_ready_to_save? do
19
19
  return unless @current_action
20
+
20
21
  @current_action.update! comment: original_filename
21
22
  end
22
23
 
23
24
  event :validate_file_exist, :validate, on: :create do
24
25
  return if empty_ok?
26
+
25
27
  if will_be_stored_as == :web
26
28
  errors.add "url is missing" if content.blank?
27
29
  elsif !attachment.file.present?
@@ -40,12 +42,14 @@ def file_ready_to_save?
40
42
  attachment_is_changing?
41
43
  end
42
44
 
43
- def item_names _args={} # needed for flexmail attachments. hacky.
45
+ # needed for flexmail attachments. hacky.
46
+ def item_names _args={}
44
47
  [name]
45
48
  end
46
49
 
47
50
  def original_filename
48
51
  return content.split("/").last if web?
52
+
49
53
  attachment.original_filename
50
54
  end
51
55
 
@@ -90,6 +94,7 @@ end
90
94
 
91
95
  def revision action, before_action=false
92
96
  return unless (result = super)
97
+
93
98
  result[:empty_ok] = true
94
99
  result
95
100
  end
@@ -110,7 +115,7 @@ rescue StandardError => e
110
115
  end
111
116
 
112
117
  def detect_extension ext
113
- return unless (mime_types = Mime::Types[attachment.content_type])
118
+ return unless (mime_types = MIME::Types[attachment.content_type])
114
119
 
115
120
  recognized_extension?(mime_types, ext) ? ext : mime_types[0].extensions[0]
116
121
  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
@@ -20,6 +20,7 @@ end
20
20
 
21
21
  def new_card_bucket
22
22
  return unless new_card?
23
+
23
24
  # If the file is assigned before the bucket option we have to
24
25
  # check if there is a bucket options in set_specific.
25
26
  # That happens for exmaple when the file appears before the bucket in the
@@ -34,6 +35,7 @@ end
34
35
 
35
36
  def load_bucket_config
36
37
  return {} unless bucket
38
+
37
39
  bucket_config = Cardio.config.file_buckets&.dig(bucket.to_sym) || {}
38
40
  bucket_config.symbolize_keys!
39
41
  bucket_config[:credentials]&.symbolize_keys!
@@ -96,6 +98,7 @@ def each_credential_from_env
96
98
  regexp = credential_from_env_regexp
97
99
  ENV.each_key do |env_key|
98
100
  next unless (m = regexp.match env_key)
101
+
99
102
  yield m[:option].downcase.to_sym
100
103
  end
101
104
  end
@@ -112,6 +115,7 @@ end
112
115
 
113
116
  def bucket_from_content
114
117
  return unless content
118
+
115
119
  content.match(/^\((?<bucket>[^)]+)\)/) { |m| m[:bucket] }
116
120
  end
117
121
 
@@ -1,12 +1,17 @@
1
1
  event :lose_coded_status_on_update, :initialize, on: :update, when: :coded? do
2
2
  # unless explicit
3
3
  return if @new_mod
4
+
4
5
  @new_storage_type ||= storage_type_from_config
5
6
  end
6
7
 
7
8
  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?
9
+ storage_type_error :mod_argument_needed_to_save unless mod || @new_mod
10
+ storage_type_error :codename_needed_for_storage if codename.blank?
11
+ end
12
+
13
+ def storage_type_error error_name
14
+ errors.add :storage_type, t("carrierwave_#{error_name}")
10
15
  end
11
16
 
12
17
  def will_become_coded?
@@ -1,4 +1,3 @@
1
-
2
1
  event :update_public_link_on_create, :integrate, on: :create, when: :local? do
3
2
  update_public_link
4
3
  end
@@ -9,6 +8,7 @@ end
9
8
 
10
9
  event :update_public_link, after: :update_read_rule, when: :local? do
11
10
  return if content.blank?
11
+
12
12
  if who_can(:read).include? Card::AnyoneID
13
13
  create_public_links
14
14
  else
@@ -21,6 +21,7 @@ private
21
21
  def create_public_links
22
22
  path = attachment.public_path
23
23
  return if File.exist? path
24
+
24
25
  FileUtils.mkdir_p File.dirname(path)
25
26
  File.symlink attachment.path, path unless File.symlink? path
26
27
  create_versions_public_links
@@ -29,6 +30,7 @@ end
29
30
  def create_versions_public_links
30
31
  attachment.versions.each_value do |version|
31
32
  next if File.symlink? version.public_path
33
+
32
34
  File.symlink version.path, version.public_path
33
35
  end
34
36
  end
@@ -36,5 +38,6 @@ end
36
38
  def remove_public_links
37
39
  symlink_dir = File.dirname attachment.public_path
38
40
  return unless Dir.exist? symlink_dir
41
+
39
42
  FileUtils.rm_rf symlink_dir
40
43
  end
@@ -25,6 +25,7 @@ def mod_dir new_mod=nil
25
25
  dir = Cardio::Mod.dirs.path(mod_name) || (mod_name.to_sym == :test && "test")
26
26
 
27
27
  raise Error, "can't find mod \"#{mod_name}\"" unless dir
28
+
28
29
  dir
29
30
  end
30
31
 
@@ -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
@@ -64,8 +61,8 @@ def mod
64
61
  end
65
62
 
66
63
  def mod_from_content
67
- if content =~ %r{^:[^/]+/([^.]+)}
68
- Regexp.last_match(1) # current mod_file format
64
+ if (m = content.match %r{^:[^/]+/([^.]+)})
65
+ m[1] # current mod_file format
69
66
  else
70
67
  mod_from_deprecated_content
71
68
  end
@@ -73,8 +70,9 @@ end
73
70
 
74
71
  # old format is still used in card_changes
75
72
  def mod_from_deprecated_content
76
- return if content =~ /^\~/
73
+ return if content.match?(/^~/)
77
74
  return unless (lines = content.split("\n")) && lines.size == 4
75
+
78
76
  lines.last
79
77
  end
80
78
 
@@ -93,15 +91,15 @@ def valid_storage_type_list
93
91
  end
94
92
 
95
93
  def invalid_storage_type! type
96
- raise Card::Error, tr(:error_invalid_storage_type, type: type)
94
+ raise Card::Error, t(:carrierwave_error_invalid_storage_type, type: type)
97
95
  end
98
96
 
99
97
  def storage_type_from_content
100
98
  case content
101
- when /^\(/ then :cloud
102
- when %r{/^https?\:/} then :web
103
- when /^~/ then :local
104
- when /^\:/ then :coded
99
+ when /^\(/ then :cloud
100
+ when %r{/^https?:/} then :web
101
+ when /^~/ then :local
102
+ when /^:/ then :coded
105
103
  else
106
104
  if deprecated_mod_file?
107
105
  :coded
@@ -123,7 +121,7 @@ end
123
121
 
124
122
  def storage_type= value
125
123
  known_storage_type? value
126
- if @action == :update #&& storage_type != value
124
+ if @action == :update # && storage_type != value
127
125
  # we cant update the storage type directly here
128
126
  # if we do then the uploader doesn't find the file we want to update
129
127
  @new_storage_type = value
@@ -133,19 +131,22 @@ def storage_type= value
133
131
  end
134
132
 
135
133
  def with_storage_options opts={}
136
- old_values = {}
134
+ old_values = stash_and_set_storage_options opts
137
135
  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
136
+ @temp_storage_type = true
144
137
  yield
145
138
  ensure
146
139
  @temp_storage_type = false
147
- old_values.each do |key, val|
148
- instance_variable_set "@#{key}", val
140
+ old_values.each { |key, val| instance_variable_set "@#{key}", val }
141
+ end
142
+
143
+ def stash_and_set_storage_options opts
144
+ %i[storage_type mod bucket].each_with_object({}) do |opt_name, old_values|
145
+ next unless opts[opt_name]
146
+
147
+ old_values[opt_name] = instance_variable_get "@#{opt_name}"
148
+ instance_variable_set "@#{opt_name}", opts[opt_name]
149
+ old_values
149
150
  end
150
151
  end
151
152
 
@@ -153,14 +154,10 @@ def temporary_storage_type_change?
153
154
  @temp_storage_type
154
155
  end
155
156
 
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?
157
+ def validate_temporary_storage_type_change type=nil
158
+ return unless type ||= @new_storage_type
159
+ raise Error, unknown_storage_type(type) unless known_storage_type? type
160
+ if type == :coded && codename.blank?
164
161
  raise Error, "codename needed for storage type :coded"
165
162
  end
166
163
  end
@@ -168,3 +165,7 @@ end
168
165
  def known_storage_type? type=storage_type
169
166
  type.in? CarrierWave::FileCardUploader::STORAGE_TYPES
170
167
  end
168
+
169
+ def unknown_storage_type type
170
+ t :carrierwave_unknown_storage_type, new_storage_type: type
171
+ end
@@ -27,6 +27,7 @@ end
27
27
  event :assign_attachment_on_create, :initialize,
28
28
  after: :assign_action, on: :create, when: :save_preliminary_upload? do
29
29
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
30
+
30
31
  upload_cache_card.selected_action_id = action.id
31
32
  upload_cache_card.select_file_revision
32
33
  assign_attachment upload_cache_card.attachment.file, action.comment
@@ -35,6 +36,7 @@ end
35
36
  event :assign_attachment_on_update, :initialize,
36
37
  after: :assign_action, on: :update, when: :save_preliminary_upload? do
37
38
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
39
+
38
40
  uploaded_file = with_selected_action_id(action.id) { attachment.file }
39
41
  assign_attachment uploaded_file, action.comment
40
42
  end
@@ -48,6 +50,7 @@ end
48
50
  event :delete_cached_upload_file_on_create, :integrate,
49
51
  on: :create, when: :save_preliminary_upload? do
50
52
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
53
+
51
54
  upload_cache_card.delete_files_for_action action
52
55
  action.delete
53
56
  end
@@ -61,6 +64,7 @@ end
61
64
  event :delete_cached_upload_file_on_update, :integrate,
62
65
  on: :update, when: :save_preliminary_upload? do
63
66
  return unless (action = Card::Action.fetch(@action_id_of_cached_upload))
67
+
64
68
  delete_files_for_action action
65
69
  action.delete
66
70
  end
data/set/self/favicon.rb CHANGED
@@ -6,6 +6,7 @@ format :html do
6
6
 
7
7
  view :link_tag, perms: :none do
8
8
  return unless (source = render :source, size: :small)
9
+
9
10
  tag :link, rel: "shortcut icon", href: source
10
11
  end
11
12
 
data/set/type/file.rb CHANGED
@@ -9,8 +9,9 @@ module SelectedAction
9
9
 
10
10
  def last_content_action_id
11
11
  return super if temporary_storage_type_change?
12
+
12
13
  # find action id from content (saves lookups)
13
- db_content.to_s.split(%r{[/\.]})[-2]
14
+ db_content.to_s.split(%r{[/.]})[-2]
14
15
  end
15
16
  end
16
17
  include SelectedAction
@@ -18,8 +19,7 @@ include SelectedAction
18
19
  format do
19
20
  view :source do
20
21
  file = card.attachment
21
- return "" unless file.valid?
22
- contextualize_path file.url
22
+ file.valid? ? contextualize_path(file.url) : ""
23
23
  end
24
24
 
25
25
  view :core do
@@ -33,17 +33,30 @@ format do
33
33
  end
34
34
 
35
35
  def handle_source
36
- source = _render_source
37
- return "" if source.blank?
38
- block_given? ? yield(source) : source
39
- rescue => e
40
- Rails.logger.info "Error with file source: #{e.message}"
41
- tr :file_error
36
+ rescuing_file_source_error do
37
+ source = _render_source
38
+ if source.blank?
39
+ ""
40
+ elsif block_given?
41
+ yield source
42
+ else
43
+ source
44
+ end
45
+ end
42
46
  end
43
47
 
44
48
  def selected_version
45
49
  card.attachment
46
50
  end
51
+
52
+ private
53
+
54
+ def rescuing_file_source_error
55
+ yield
56
+ rescue StandardError => e
57
+ Rails.logger.info "Error with file source: #{e.message}"
58
+ t :carrierwave_file_error
59
+ end
47
60
  end
48
61
 
49
62
  format :file do
@@ -53,6 +66,7 @@ format :file do
53
66
  attachment_format = card.attachment_format(params[:format])
54
67
  return _render_not_found unless attachment_format
55
68
  return card.format(:html).render_core if card.remote_storage?
69
+
56
70
  set_response_headers
57
71
  args_for_send_file
58
72
  end
@@ -60,13 +74,14 @@ format :file do
60
74
  def args_for_send_file
61
75
  file = selected_version
62
76
  [file.path, { type: file.content_type,
63
- filename: "#{card.name.safe_key}#{file.extension}",
77
+ filename: "#{card.name.safe_key}#{file.extension}",
64
78
  x_sendfile: true,
65
79
  disposition: (params[:format] == "file" ? "attachment" : "inline") }]
66
80
  end
67
81
 
68
82
  def set_response_headers
69
83
  return unless params[:explicit_file] && (response = controller&.response)
84
+
70
85
  response.headers["Expires"] = 1.year.from_now.httpdate
71
86
  # currently using default "private", because proxy servers could block
72
87
  # needed permission checks
@@ -74,10 +89,14 @@ format :file do
74
89
  end
75
90
  end
76
91
 
92
+ format :json do
93
+ view(:content) { render_core }
94
+ end
95
+
77
96
  format :html do
78
97
  view :core do
79
98
  handle_source do |source|
80
- "<a href=\"#{source}\">#{tr :download, title: title_in_context(voo.title)}</a>"
99
+ haml :core, source: source
81
100
  end
82
101
  end
83
102
 
@@ -111,6 +130,6 @@ format :html do
111
130
  end
112
131
 
113
132
  def preview_editor_delete_text
114
- tr :delete
133
+ t :carrierwave_delete
115
134
  end
116
135
  end
@@ -0,0 +1,2 @@
1
+ %a{ href: source }<
2
+ = t :carrierwave_download, title: title_in_context(voo.title)
data/set/type/image.rb CHANGED
@@ -23,8 +23,10 @@ format do
23
23
 
24
24
  view :source do
25
25
  return card.content if card.web?
26
+
26
27
  image = selected_version
27
28
  return "" unless image.valid?
29
+
28
30
  contextualize_path image.url
29
31
  end
30
32
 
@@ -37,10 +39,6 @@ format do
37
39
  end
38
40
  end
39
41
 
40
- def handle_source
41
- super
42
- end
43
-
44
42
  def closed_size
45
43
  :icon
46
44
  end
@@ -70,11 +68,16 @@ format do
70
68
  end
71
69
  end
72
70
 
71
+ format :json do
72
+ include File::JsonFormat
73
+ end
74
+
73
75
  format :email_html do
74
76
  view :inline, cache: :never do
75
77
  handle_source do |source|
76
78
  return source unless (mail = inherit :active_mail) &&
77
79
  ::File.exist?(path = selected_version.path)
80
+
78
81
  url = attach_image mail, path
79
82
  image_tag url
80
83
  end
@@ -4,6 +4,7 @@ format :html do
4
4
  # core HTML image view.
5
5
  view :core do
6
6
  return card.attachment.read if card.svg?
7
+
7
8
  with_valid_source do |source|
8
9
  image_tag source, alt: card.name
9
10
  end
@@ -34,6 +35,7 @@ format :html do
34
35
 
35
36
  def preview
36
37
  return if card.new_card? && !card.preliminary_upload?
38
+
37
39
  wrap_with :div, class: "attachment-preview",
38
40
  id: "#{card.attachment.filename}-preview" do
39
41
  _render_core size: :medium
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.7
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-08-01 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.7
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.7
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.7
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.7
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.7
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.7
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
@@ -136,7 +138,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
136
138
  - !ruby/object:Gem::Version
137
139
  version: '0'
138
140
  requirements: []
139
- rubygems_version: 3.1.4
141
+ rubygems_version: 3.1.6
140
142
  signing_key:
141
143
  specification_version: 4
142
144
  summary: File and Image handling