card-mod-carrierwave 0.18.1 → 0.19.0
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/data/transform/20250204175412_fix_compound_self_sets.rb +13 -0
- data/lib/carrier_wave/card_mount/helper.rb +44 -0
- data/lib/carrier_wave/card_mount.rb +16 -26
- data/lib/carrier_wave/file_card_uploader/path.rb +4 -2
- data/lib/carrier_wave/file_card_uploader.rb +3 -1
- data/lib/carrier_wave/image_card_uploader.rb +2 -2
- data/set/abstract/attachment/00_upload_cache.rb +1 -1
- data/set/abstract/attachment/coded.rb +14 -3
- data/set/abstract/attachment/paths.rb +3 -3
- data/set/abstract/attachment.rb +24 -16
- data/set/all/file_utils.rb +4 -4
- data/set/self/favicon.rb +2 -2
- data/set/type/file.rb +1 -0
- metadata +13 -14
- /data/data/files/{mod_carrierwave_script_asset_output → mod_carrierwave/script/asset_output}/file.js +0 -0
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9d9cccb0bf38f2b63fbae9b148388cb1744a0f9c09e9f707661c8337ff11b7b2
|
4
|
+
data.tar.gz: 7210e5767e0d36588635ff67dfd2c72a420d1e0f6ed83fcc52dbff49e4c88288
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0b14c9478d50ac2c82b23f257f4814074c7956077c6a3ae8e4abe3ee6fc03458b9acd3674de91d6eae7ef45ccba708c2d0c24e5d563e2d337da8c785604ab83e
|
7
|
+
data.tar.gz: f0ad9f38f2f2cb891da667e5f80d0b7f78a0bc1e18a3f93c55d46e1dfcdca2550b01f7b454ec9143c69cad4bcf1f7d1cae21bb0838cdf8008c919de259f8f5b2
|
@@ -0,0 +1,13 @@
|
|
1
|
+
# -*- encoding : utf-8 -*-
|
2
|
+
|
3
|
+
class FixCompoundSelfSets < Cardio::Migration::Transform
|
4
|
+
def up
|
5
|
+
Card.where("codename is not null and name is null").each do |card|
|
6
|
+
card.include_set_modules
|
7
|
+
card.update_column :codename, nil
|
8
|
+
next unless card.respond_to? :attachment
|
9
|
+
|
10
|
+
card.update_column :db_content, card.attachment.db_content
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
module CarrierWave
|
2
|
+
module CardMount
|
3
|
+
# helper methods for mounted cards
|
4
|
+
module Helper
|
5
|
+
def read_uploader *args
|
6
|
+
read_attribute(*args)
|
7
|
+
end
|
8
|
+
|
9
|
+
def write_uploader *args
|
10
|
+
write_attribute(*args)
|
11
|
+
end
|
12
|
+
|
13
|
+
def reload *_args
|
14
|
+
@_mounters = nil
|
15
|
+
super
|
16
|
+
end
|
17
|
+
|
18
|
+
def serializable_hash opts=nil
|
19
|
+
except = serializable_hash_config opts, :except
|
20
|
+
only = serializable_hash_config opts, :only
|
21
|
+
|
22
|
+
self.class.uploaders.each_with_object(super(opts)) do |(column, _uploader), hash|
|
23
|
+
if add_column_to_serializable_hash? column.to_s, only, except
|
24
|
+
hash[column.to_s] = _mounter(column).uploader.serializable_hash
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
private
|
30
|
+
|
31
|
+
def serializable_hash_config opts, key
|
32
|
+
opts&.dig(key) && Array.wrap(opts[:key]).map(&:to_s)
|
33
|
+
end
|
34
|
+
|
35
|
+
def add_column_to_serializable_hash? column, only, except
|
36
|
+
if only
|
37
|
+
only.include? column
|
38
|
+
elsif except
|
39
|
+
!except.include? column
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
@@ -7,6 +7,7 @@ module CarrierWave
|
|
7
7
|
# to card events.
|
8
8
|
module CardMount
|
9
9
|
include CarrierWave::Mount
|
10
|
+
# Helper # load helper module so it's available to mounted cards
|
10
11
|
|
11
12
|
def uploaders
|
12
13
|
Card.uploaders ||= {}
|
@@ -21,6 +22,12 @@ module CarrierWave
|
|
21
22
|
super
|
22
23
|
|
23
24
|
class_eval <<-RUBY, __FILE__, __LINE__ + 1
|
25
|
+
include CarrierWave::CardMount::Helper
|
26
|
+
|
27
|
+
def attachment
|
28
|
+
#{column}
|
29
|
+
end
|
30
|
+
|
24
31
|
event :store_#{column}_event, :finalize, when: :store_#{column}_event? do
|
25
32
|
store_#{column}!
|
26
33
|
end
|
@@ -49,10 +56,6 @@ module CarrierWave
|
|
49
56
|
!coded? || ENV["STORE_CODED_FILES"]
|
50
57
|
end
|
51
58
|
|
52
|
-
def attachment
|
53
|
-
#{column}
|
54
|
-
end
|
55
|
-
|
56
59
|
def store_attachment!
|
57
60
|
set_specific.delete :#{column}
|
58
61
|
store_#{column}!
|
@@ -62,15 +65,20 @@ module CarrierWave
|
|
62
65
|
"#{column}".to_sym
|
63
66
|
end
|
64
67
|
|
65
|
-
def read_uploader *args; read_attribute *args; end
|
66
|
-
def write_uploader *args; write_attribute *args; end
|
67
|
-
|
68
68
|
def #{column}=(new_file)
|
69
|
-
return if new_file.blank?
|
69
|
+
return if new_file.blank? || identical_file?(new_file)
|
70
70
|
self.selected_action_id = Time.now.to_i unless history?
|
71
71
|
assign_file(new_file) { super }
|
72
72
|
end
|
73
73
|
|
74
|
+
def identical_file? new_file
|
75
|
+
return false if new?
|
76
|
+
|
77
|
+
::File.identical? #{column}.file.to_file, new_file
|
78
|
+
rescue StandardError
|
79
|
+
false
|
80
|
+
end
|
81
|
+
|
74
82
|
def remote_#{column}_url=(url)
|
75
83
|
assign_file(url) { super }
|
76
84
|
end
|
@@ -111,24 +119,6 @@ module CarrierWave
|
|
111
119
|
def #{column}_changed?
|
112
120
|
@#{column}_changed
|
113
121
|
end
|
114
|
-
|
115
|
-
def serializable_hash(opts=nil)
|
116
|
-
except = opts&.dig(:except) && Array.wrap(opts[:except]).map(&:to_s)
|
117
|
-
only = opts&.dig(:only) && Array.wrap(opts[:only]).map(&:to_s)
|
118
|
-
|
119
|
-
self.class.uploaders.each_with_object(super(opts)) do |(column, uploader), hash|
|
120
|
-
if (!only && !except) ||
|
121
|
-
(only && only.include?(column.to_s)) ||
|
122
|
-
(!only && except && !except.include?(column.to_s))
|
123
|
-
hash[column.to_s] = _mounter(column).uploader.serializable_hash
|
124
|
-
end
|
125
|
-
end
|
126
|
-
end
|
127
|
-
|
128
|
-
def reload(*)
|
129
|
-
@_mounters = nil
|
130
|
-
super
|
131
|
-
end
|
132
122
|
RUBY
|
133
123
|
end
|
134
124
|
end
|
@@ -1,8 +1,10 @@
|
|
1
|
+
# extend core module from carrierwave gem
|
1
2
|
module CarrierWave
|
2
3
|
def self.tmp_path
|
3
4
|
@tmp_path ||= Card.paths["tmp"].existent.first
|
4
5
|
end
|
5
6
|
|
7
|
+
# custom uploader class for cards
|
6
8
|
class FileCardUploader
|
7
9
|
# path-related methods for uploader
|
8
10
|
module Path
|
@@ -20,7 +22,7 @@ module CarrierWave
|
|
20
22
|
end
|
21
23
|
|
22
24
|
def cache_dir
|
23
|
-
"#{@model.files_base_dir}/cache"
|
25
|
+
"#{@model.files_base_dir 'tmp'}/cache"
|
24
26
|
end
|
25
27
|
|
26
28
|
# Carrierwave calls store_path without argument when it stores the file
|
@@ -41,7 +43,7 @@ module CarrierWave
|
|
41
43
|
end
|
42
44
|
|
43
45
|
def tmp_path
|
44
|
-
Dir.
|
46
|
+
Dir.mkdir_p model.tmp_upload_dir
|
45
47
|
File.join model.tmp_upload_dir, filename
|
46
48
|
end
|
47
49
|
|
@@ -1,3 +1,4 @@
|
|
1
|
+
# extend the carrierwave gem modules/classes
|
1
2
|
module CarrierWave
|
2
3
|
# Takes care of the file upload for cards with attached files.
|
3
4
|
# Most of the upload behaviour depends on the card itself.
|
@@ -235,6 +236,7 @@ module CarrierWave
|
|
235
236
|
end
|
236
237
|
end
|
237
238
|
|
239
|
+
# alterations to Carrierwave methods
|
238
240
|
class SanitizedFile
|
239
241
|
def content_type
|
240
242
|
# the original content_type method doesn't seem to be very reliable
|
@@ -270,7 +272,7 @@ module CarrierWave
|
|
270
272
|
|
271
273
|
# put version at the end of the filename
|
272
274
|
def full_filename for_file
|
273
|
-
name = super
|
275
|
+
name = super
|
274
276
|
return unless name.present?
|
275
277
|
|
276
278
|
parts = name.split "."
|
@@ -42,12 +42,12 @@ module CarrierWave
|
|
42
42
|
# end
|
43
43
|
|
44
44
|
def identifier
|
45
|
-
full_filename(super
|
45
|
+
full_filename(super)
|
46
46
|
end
|
47
47
|
|
48
48
|
# add 'original' if no version is given
|
49
49
|
def full_filename for_file
|
50
|
-
name = super
|
50
|
+
name = super
|
51
51
|
if name.blank? || version_name
|
52
52
|
name
|
53
53
|
else
|
@@ -6,7 +6,7 @@ end
|
|
6
6
|
|
7
7
|
event :validate_coded_storage_type, :validate, on: :save, when: :coded? do
|
8
8
|
storage_type_error :mod_argument_needed_to_save unless mod
|
9
|
-
storage_type_error :codename_needed_for_storage
|
9
|
+
storage_type_error :codename_needed_for_storage unless coded_ok?
|
10
10
|
end
|
11
11
|
|
12
12
|
def mod= value
|
@@ -19,6 +19,10 @@ end
|
|
19
19
|
|
20
20
|
private
|
21
21
|
|
22
|
+
def coded_ok?
|
23
|
+
!codename_parts.find(&:blank?)
|
24
|
+
end
|
25
|
+
|
22
26
|
def uncode?
|
23
27
|
(@explicit_storage_type != :coded) && !set_specific[:mod].present? && current.coded?
|
24
28
|
# (@explicit_storage_type != :coded) && !mod && current.coded?
|
@@ -37,16 +41,23 @@ def mod_from_content
|
|
37
41
|
end
|
38
42
|
|
39
43
|
def mod_name_match cont
|
40
|
-
cont&.match %r{^:[
|
44
|
+
cont&.match %r{^:[:\w/+]+/([^./]+)\.}
|
41
45
|
end
|
42
46
|
|
43
47
|
# place for files of mod file cards
|
44
48
|
def coded_dir new_mod=nil
|
45
|
-
|
49
|
+
dir_parts = [mod_dir(new_mod), MOD_FILE_DIR] + codename_parts
|
50
|
+
dir = File.join(*dir_parts)
|
46
51
|
FileUtils.mkdir_p(dir) unless File.directory?(dir)
|
47
52
|
dir
|
48
53
|
end
|
49
54
|
|
55
|
+
def codename_parts
|
56
|
+
return [codename.to_s] if name.simple?
|
57
|
+
|
58
|
+
@codename_parts ||= name.parts.map { |p| p.codename&.to_s }
|
59
|
+
end
|
60
|
+
|
50
61
|
def mod_dir new_mod=nil
|
51
62
|
mod_name = new_mod || mod
|
52
63
|
dir = Cardio::Mod.dirs.path(mod_name) || (mod_name.to_sym == :test && "test")
|
@@ -11,8 +11,8 @@ def upload_dir
|
|
11
11
|
id ? "#{files_base_dir}/#{id}" : tmp_upload_dir
|
12
12
|
end
|
13
13
|
|
14
|
-
def files_base_dir
|
15
|
-
dir = bucket ? bucket_config[:subdirectory] : Card.paths[
|
14
|
+
def files_base_dir type="files"
|
15
|
+
dir = bucket ? bucket_config[:subdirectory] : Card.paths[type].existent.first
|
16
16
|
dir || files_base_dir_configuration_error
|
17
17
|
end
|
18
18
|
|
@@ -24,7 +24,7 @@ end
|
|
24
24
|
# used in the identifier
|
25
25
|
def file_dir
|
26
26
|
if coded?
|
27
|
-
":#{
|
27
|
+
codename_parts.map { |c| ":#{c}" }.join Name.joint
|
28
28
|
elsif cloud?
|
29
29
|
"(#{bucket})/#{file_id}"
|
30
30
|
else
|
data/set/abstract/attachment.rb
CHANGED
@@ -12,10 +12,7 @@ end
|
|
12
12
|
|
13
13
|
# we need a card id for the path so we have to update db_content when we have
|
14
14
|
# an id
|
15
|
-
event :correct_identifier, :finalize, on: :save, when:
|
16
|
-
correct_id = attachment.db_content
|
17
|
-
return if db_content == correct_id
|
18
|
-
|
15
|
+
event :correct_identifier, :finalize, on: :save, when: :incorrect_identifier? do
|
19
16
|
update_column :db_content, attachment.db_content
|
20
17
|
expire
|
21
18
|
end
|
@@ -36,10 +33,21 @@ event :validate_file_exist, :validate, on: :create, skip: :allowed do
|
|
36
33
|
end
|
37
34
|
end
|
38
35
|
|
39
|
-
event :write_identifier, after: :save_original_filename, when:
|
36
|
+
event :write_identifier, after: :save_original_filename, when: :write_identifier? do
|
40
37
|
self.content = attachment.db_content
|
41
38
|
end
|
42
39
|
|
40
|
+
def incorrect_identifier?
|
41
|
+
return false if web?
|
42
|
+
|
43
|
+
correct_id = attachment.db_content
|
44
|
+
correct_id.present? && db_content != correct_id
|
45
|
+
end
|
46
|
+
|
47
|
+
def write_identifier?
|
48
|
+
!web?
|
49
|
+
end
|
50
|
+
|
43
51
|
def file_ready_to_save?
|
44
52
|
attachment.file.present? &&
|
45
53
|
!preliminary_upload? &&
|
@@ -112,7 +120,7 @@ def delete_files_for_action action
|
|
112
120
|
end
|
113
121
|
end
|
114
122
|
|
115
|
-
def revision action, before_action
|
123
|
+
def revision action, before_action: false
|
116
124
|
return unless (result = super)
|
117
125
|
|
118
126
|
result[:empty_ok] = true
|
@@ -127,6 +135,10 @@ def attachment_format ext
|
|
127
135
|
end
|
128
136
|
end
|
129
137
|
|
138
|
+
def original_extension
|
139
|
+
@original_extension ||= attachment&.extension&.sub(/^\./, "")
|
140
|
+
end
|
141
|
+
|
130
142
|
def rescuing_extension_issues
|
131
143
|
yield
|
132
144
|
rescue StandardError => e
|
@@ -134,6 +146,12 @@ rescue StandardError => e
|
|
134
146
|
nil
|
135
147
|
end
|
136
148
|
|
149
|
+
def confirm_original_extension ext
|
150
|
+
return unless ["file", original_extension].member? ext
|
151
|
+
|
152
|
+
original_extension
|
153
|
+
end
|
154
|
+
|
137
155
|
def detect_extension ext
|
138
156
|
return unless (mime_types = MIME::Types[attachment.content_type])
|
139
157
|
|
@@ -143,13 +161,3 @@ end
|
|
143
161
|
def recognized_extension? mime_types, ext
|
144
162
|
mime_types.find { |mt| mt.extensions.member? ext }
|
145
163
|
end
|
146
|
-
|
147
|
-
def confirm_original_extension ext
|
148
|
-
return unless ["file", original_extension].member? ext
|
149
|
-
|
150
|
-
original_extension
|
151
|
-
end
|
152
|
-
|
153
|
-
def original_extension
|
154
|
-
@original_extension ||= attachment&.extension&.sub(/^\./, "")
|
155
|
-
end
|
data/set/all/file_utils.rb
CHANGED
@@ -30,10 +30,10 @@ module ClassMethods
|
|
30
30
|
|
31
31
|
def draft_actions_with_attachment
|
32
32
|
Card::Action.find_by_sql(
|
33
|
-
"SELECT * FROM card_actions "\
|
34
|
-
|
35
|
-
|
36
|
-
|
33
|
+
"SELECT * FROM card_actions " \
|
34
|
+
"INNER JOIN cards ON card_actions.card_id = cards.id " \
|
35
|
+
"WHERE cards.type_id IN (#{Card::FileID}, #{Card::ImageID}) " \
|
36
|
+
"AND card_actions.draft = true"
|
37
37
|
)
|
38
38
|
end
|
39
39
|
|
data/set/self/favicon.rb
CHANGED
@@ -11,7 +11,7 @@ format :html do
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def raw_help_text
|
14
|
-
"A favicon (or shortcut icon) is a small image used by browsers to help identify "\
|
15
|
-
|
14
|
+
"A favicon (or shortcut icon) is a small image used by browsers to help identify " \
|
15
|
+
"your website. [[http://www.decko.org/favicon|How to customize your favicon]]"
|
16
16
|
end
|
17
17
|
end
|
data/set/type/file.rb
CHANGED
metadata
CHANGED
@@ -1,16 +1,15 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: card-mod-carrierwave
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.19.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ethan McCutchen
|
8
8
|
- Philipp Kühl
|
9
9
|
- Gerry Gleason
|
10
|
-
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date:
|
12
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: card
|
@@ -18,14 +17,14 @@ dependencies:
|
|
18
17
|
requirements:
|
19
18
|
- - '='
|
20
19
|
- !ruby/object:Gem::Version
|
21
|
-
version: 1.
|
20
|
+
version: 1.109.0
|
22
21
|
type: :runtime
|
23
22
|
prerelease: false
|
24
23
|
version_requirements: !ruby/object:Gem::Requirement
|
25
24
|
requirements:
|
26
25
|
- - '='
|
27
26
|
- !ruby/object:Gem::Version
|
28
|
-
version: 1.
|
27
|
+
version: 1.109.0
|
29
28
|
- !ruby/object:Gem::Dependency
|
30
29
|
name: carrierwave
|
31
30
|
requirement: !ruby/object:Gem::Requirement
|
@@ -88,28 +87,28 @@ dependencies:
|
|
88
87
|
requirements:
|
89
88
|
- - '='
|
90
89
|
- !ruby/object:Gem::Version
|
91
|
-
version: 0.
|
90
|
+
version: 0.19.0
|
92
91
|
type: :runtime
|
93
92
|
prerelease: false
|
94
93
|
version_requirements: !ruby/object:Gem::Requirement
|
95
94
|
requirements:
|
96
95
|
- - '='
|
97
96
|
- !ruby/object:Gem::Version
|
98
|
-
version: 0.
|
97
|
+
version: 0.19.0
|
99
98
|
- !ruby/object:Gem::Dependency
|
100
99
|
name: card-mod-permissions
|
101
100
|
requirement: !ruby/object:Gem::Requirement
|
102
101
|
requirements:
|
103
102
|
- - '='
|
104
103
|
- !ruby/object:Gem::Version
|
105
|
-
version: 0.
|
104
|
+
version: 0.19.0
|
106
105
|
type: :runtime
|
107
106
|
prerelease: false
|
108
107
|
version_requirements: !ruby/object:Gem::Requirement
|
109
108
|
requirements:
|
110
109
|
- - '='
|
111
110
|
- !ruby/object:Gem::Version
|
112
|
-
version: 0.
|
111
|
+
version: 0.19.0
|
113
112
|
description: ''
|
114
113
|
email:
|
115
114
|
- info@decko.org
|
@@ -139,12 +138,14 @@ files:
|
|
139
138
|
- data/files/logo.svg
|
140
139
|
- data/files/logo/image-original.svg
|
141
140
|
- data/files/mao2.jpg
|
142
|
-
- data/files/
|
141
|
+
- data/files/mod_carrierwave/script/asset_output/file.js
|
143
142
|
- data/files/rails.gif
|
144
143
|
- data/real.yml
|
145
144
|
- data/transform/20230130141025_move_favicon.rb
|
145
|
+
- data/transform/20250204175412_fix_compound_self_sets.rb
|
146
146
|
- lib/card/mod/carrierwave.rb
|
147
147
|
- lib/carrier_wave/card_mount.rb
|
148
|
+
- lib/carrier_wave/card_mount/helper.rb
|
148
149
|
- lib/carrier_wave/file_card_uploader.rb
|
149
150
|
- lib/carrier_wave/file_card_uploader/path.rb
|
150
151
|
- lib/carrier_wave/image_card_uploader.rb
|
@@ -180,7 +181,6 @@ metadata:
|
|
180
181
|
documentation_url: http://docs.decko.org/
|
181
182
|
card-mod: carrierwave
|
182
183
|
card-mod-group: gem-defaults
|
183
|
-
post_install_message:
|
184
184
|
rdoc_options: []
|
185
185
|
require_paths:
|
186
186
|
- lib
|
@@ -188,15 +188,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
188
188
|
requirements:
|
189
189
|
- - ">="
|
190
190
|
- !ruby/object:Gem::Version
|
191
|
-
version: '3.
|
191
|
+
version: '3.2'
|
192
192
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
193
193
|
requirements:
|
194
194
|
- - ">="
|
195
195
|
- !ruby/object:Gem::Version
|
196
196
|
version: '0'
|
197
197
|
requirements: []
|
198
|
-
rubygems_version: 3.
|
199
|
-
signing_key:
|
198
|
+
rubygems_version: 3.6.8
|
200
199
|
specification_version: 4
|
201
200
|
summary: File and Image handling
|
202
201
|
test_files: []
|
/data/data/files/{mod_carrierwave_script_asset_output → mod_carrierwave/script/asset_output}/file.js
RENAMED
File without changes
|