intesys_asset_manager 1.1.3 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.rdoc +4 -0
- data/lib/asset_manager.rb +37 -19
- data/lib/asset_manager/active_record.rb +155 -0
- data/lib/asset_manager/all.rb +5 -5
- data/lib/{custom_versions.rb → asset_manager/custom_versions.rb} +0 -0
- data/lib/asset_manager/deprecated.rb +69 -0
- data/lib/asset_manager/engine.rb +10 -14
- data/lib/{touch_translation.rb → asset_manager/touch_translation.rb} +0 -0
- data/lib/{translations.rb → asset_manager/translations.rb} +0 -0
- data/lib/formtastic/inputs/asset_manager_input.rb +2 -0
- data/lib/intesys_asset_manager/version.rb +1 -1
- data/lib/simple_form/inputs/asset_manager_input.rb +2 -2
- metadata +7 -8
- data/lib/asset_manager/extensions/active_record.rb +0 -152
- data/lib/asset_manager/extensions/all.rb +0 -1
- data/lib/deprecated.rb +0 -61
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 71646169a95914b4ca547945943d63e5fd078574
|
4
|
+
data.tar.gz: 7cb420debca52eaa80954233ec2c6bf3b4a7c83b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 329871fe066385bb3e0ba15b1bb0ea067609177cae3930b4245e6a21556bfea8d0551f48f6e86c83c5f0a530837daae4d35f41ad334f366b11f2d1be24bfce96
|
7
|
+
data.tar.gz: 84f999c9a92da482480712cb560dacb5594b6961de406ca17c06fd6ac40693882d23ae10dd0210352379f8a87b1660bd0cf4d8c8d66795c4a051c226213961f7
|
data/README.rdoc
CHANGED
@@ -112,6 +112,10 @@ Asset Manager relies on ImageMagick to process images (for thumbnails etc.). To
|
|
112
112
|
There is also a rake task to re-process already existing images when you add a new format:
|
113
113
|
rake asset_manager:recreate_versions
|
114
114
|
|
115
|
+
=== Default Image Formats
|
116
|
+
A list of file formats that will be accepted for has_image and has_images.
|
117
|
+
config.default_image_formats = %w(jpg jpeg gif png)
|
118
|
+
|
115
119
|
== Project Roadmap
|
116
120
|
|
117
121
|
- FCKEditor (Rich) integration
|
data/lib/asset_manager.rb
CHANGED
@@ -3,6 +3,7 @@ require 'asset_manager/engine'
|
|
3
3
|
require 'acts-as-taggable-on'
|
4
4
|
require 'bootstrap_kaminari'
|
5
5
|
require 'carrierwave'
|
6
|
+
require 'cocoon'
|
6
7
|
require 'fancybox2-rails'
|
7
8
|
require 'formtastic-bootstrap'
|
8
9
|
require 'globalize'
|
@@ -13,41 +14,58 @@ require 'kaminari'
|
|
13
14
|
require 'meta_search'
|
14
15
|
require 'mini_magick'
|
15
16
|
require 'sass-rails'
|
16
|
-
require 'cocoon'
|
17
17
|
|
18
18
|
module AssetManager
|
19
19
|
include ActiveSupport::Configurable
|
20
20
|
|
21
|
+
##
|
22
|
+
# Asset types
|
23
|
+
# Defines the visibility of your assets. You can specify:
|
24
|
+
# [:public] or [:private] or [:private, :public]
|
25
|
+
config.asset_types = :public
|
26
|
+
config_accessor :asset_types, instance_reader: false
|
27
|
+
|
28
|
+
##
|
29
|
+
# Default image formats
|
30
|
+
# A list of file formats that will be accepted for has_image and has_images.
|
31
|
+
config.default_image_formats = %w(jpg jpeg gif png)
|
32
|
+
config_accessor :default_image_formats
|
33
|
+
|
34
|
+
##
|
21
35
|
# With Categories
|
36
|
+
# Decides whether or not your assets are organized by categories.
|
22
37
|
config.with_categories = true
|
23
38
|
config_accessor :with_categories
|
24
39
|
|
25
|
-
|
26
|
-
config.with_tags = true
|
27
|
-
config_accessor :with_tags
|
28
|
-
|
40
|
+
##
|
29
41
|
# With Clippy
|
42
|
+
# Permits you to copy an asset's URL to the clip board directly from the
|
43
|
+
# assets list.
|
30
44
|
config.with_clippy = false
|
31
45
|
config_accessor :with_clippy
|
32
46
|
|
33
|
-
|
34
|
-
|
35
|
-
|
47
|
+
##
|
48
|
+
# With Tags
|
49
|
+
# Decides whether or not your assets are organized by tags.
|
50
|
+
config.with_tags = true
|
51
|
+
config_accessor :with_tags
|
36
52
|
|
37
|
-
|
38
|
-
|
39
|
-
|
53
|
+
class << self
|
54
|
+
def asset_types
|
55
|
+
Array(config.asset_types)
|
56
|
+
end
|
40
57
|
|
41
|
-
|
42
|
-
|
43
|
-
|
58
|
+
def public_asset_type?
|
59
|
+
asset_types.include?(:public)
|
60
|
+
end
|
44
61
|
|
45
|
-
|
46
|
-
|
47
|
-
|
62
|
+
def private_asset_type?
|
63
|
+
asset_types.include?(:private)
|
64
|
+
end
|
48
65
|
|
49
|
-
|
50
|
-
|
66
|
+
def unique_asset_type?
|
67
|
+
asset_types.length == 1
|
68
|
+
end
|
51
69
|
end
|
52
70
|
end
|
53
71
|
|
@@ -0,0 +1,155 @@
|
|
1
|
+
class ActiveRecord::Base
|
2
|
+
|
3
|
+
class << self
|
4
|
+
attr_reader :am_file, :am_file_options, :am_files, :am_files_options
|
5
|
+
|
6
|
+
def has_file(field, options = {})
|
7
|
+
options.assert_valid_keys(:accepted, :type, :mode)
|
8
|
+
options.reverse_merge!(type: :public, max: 1, mode: :file)
|
9
|
+
|
10
|
+
@am_file = [] if @am_file.nil?
|
11
|
+
@am_file.push(field) unless @am_file.include?(field)
|
12
|
+
@am_file_options = {} if @am_file_options.nil?
|
13
|
+
@am_file_options[field] = options
|
14
|
+
|
15
|
+
attr_accessible am_field_name(field, false)
|
16
|
+
attr_accessor am_field_name(field, false)
|
17
|
+
|
18
|
+
has_one "asset_association_#{field}".to_sym, as: :owner, class_name: 'AssetManager::AssetAssociation', conditions: { context: "#{field}" }
|
19
|
+
has_one "#{field}".to_sym, through: "asset_association_#{field}".to_sym, source: :asset, class_name: 'AssetManager::Asset'
|
20
|
+
|
21
|
+
after_save :save_file_associations
|
22
|
+
after_destroy :destroy_file_and_files_associations
|
23
|
+
end
|
24
|
+
|
25
|
+
def has_private_file(field, options = {})
|
26
|
+
has_file(field, options.merge(type: :private))
|
27
|
+
end
|
28
|
+
|
29
|
+
def has_image(field, options = {})
|
30
|
+
has_file(field, options.merge(accepted: AssetManager.default_image_formats, mode: :image))
|
31
|
+
end
|
32
|
+
|
33
|
+
def has_files(field, options = {})
|
34
|
+
options.assert_valid_keys(:accepted, :type, :mode, :max)
|
35
|
+
options.reverse_merge!(type: :public, mode: :files, max: 999)
|
36
|
+
|
37
|
+
@am_files = [] if @am_files.nil?
|
38
|
+
@am_files.push(field) unless @am_files.include?(field)
|
39
|
+
@am_files_options = {} if @am_files_options.nil?
|
40
|
+
@am_files_options[field] = options
|
41
|
+
|
42
|
+
attr_accessible am_field_name(field, true)
|
43
|
+
|
44
|
+
has_many "asset_association_#{field}".to_sym, as: :owner, class_name: 'AssetManager::AssetAssociation', conditions: { context: "#{field}" }
|
45
|
+
has_many "#{field}".to_sym, through: "asset_association_#{field}".to_sym, source: :asset, class_name: 'AssetManager::Asset'
|
46
|
+
|
47
|
+
after_save :save_files_associations
|
48
|
+
after_destroy :destroy_file_and_files_associations
|
49
|
+
end
|
50
|
+
|
51
|
+
def has_private_files(field, options = {})
|
52
|
+
has_files(field, options.merge(type: :private))
|
53
|
+
end
|
54
|
+
|
55
|
+
def has_images(field, options = {})
|
56
|
+
has_files(field, options.merge(accepted: AssetManager.default_image_formats, mode: :images))
|
57
|
+
end
|
58
|
+
|
59
|
+
def am_file_fields
|
60
|
+
@am_file.nil? ? [] : @am_file
|
61
|
+
end
|
62
|
+
|
63
|
+
def am_files_fields
|
64
|
+
@am_files.nil? ? [] : @am_files
|
65
|
+
end
|
66
|
+
|
67
|
+
def am_file_options
|
68
|
+
@am_file_options.nil? ? {} : @am_file_options
|
69
|
+
end
|
70
|
+
|
71
|
+
def am_files_options
|
72
|
+
@am_files_options.nil? ? {} : @am_files_options
|
73
|
+
end
|
74
|
+
|
75
|
+
def am_has_field?(field)
|
76
|
+
am_file_fields.include?(field.to_sym) || am_files_fields.include?(field.to_sym)
|
77
|
+
end
|
78
|
+
|
79
|
+
def am_field_option(field, key)
|
80
|
+
options = field_options(field)
|
81
|
+
options[field.to_sym][key] rescue nil
|
82
|
+
end
|
83
|
+
|
84
|
+
def am_field_name(field, multiple)
|
85
|
+
(multiple ? "#{field.to_s.singularize}_ids" : "#{field.to_s}_id").to_sym
|
86
|
+
end
|
87
|
+
|
88
|
+
private
|
89
|
+
|
90
|
+
def field_options(field)
|
91
|
+
am_file_fields.include?(field.to_sym) ? am_file_options : am_files_options
|
92
|
+
end
|
93
|
+
|
94
|
+
end
|
95
|
+
|
96
|
+
|
97
|
+
private
|
98
|
+
|
99
|
+
def save_file_associations
|
100
|
+
self.class.am_file_fields.each do |field|
|
101
|
+
value = send(self.class.am_field_name(field, false))
|
102
|
+
unless value.nil?
|
103
|
+
::AssetManager::AssetAssociation.destroy_all(
|
104
|
+
owner_type: self.class.name,
|
105
|
+
owner_id: id,
|
106
|
+
context: field
|
107
|
+
)
|
108
|
+
unless value.blank?
|
109
|
+
::AssetManager::AssetAssociation.create(
|
110
|
+
owner_type: self.class.name,
|
111
|
+
owner_id: id,
|
112
|
+
context: field,
|
113
|
+
asset_id: value.to_i,
|
114
|
+
position: 1
|
115
|
+
)
|
116
|
+
end
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
120
|
+
|
121
|
+
def save_files_associations
|
122
|
+
self.class.am_files_fields.each do |field|
|
123
|
+
values = send(self.class.am_field_name(field, true))
|
124
|
+
unless values.nil?
|
125
|
+
::AssetManager::AssetAssociation.destroy_all(
|
126
|
+
owner_type: self.class.name,
|
127
|
+
owner_id: id,
|
128
|
+
context: field
|
129
|
+
)
|
130
|
+
values.reject! { |a| a.to_s.strip.length == 0 }
|
131
|
+
unless values.empty?
|
132
|
+
values.each_with_index do |value, index|
|
133
|
+
::AssetManager::AssetAssociation.create(
|
134
|
+
owner_type: self.class.name,
|
135
|
+
owner_id: id,
|
136
|
+
context: field,
|
137
|
+
asset_id: value.to_i,
|
138
|
+
position: (index + 1)
|
139
|
+
)
|
140
|
+
end
|
141
|
+
end
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
145
|
+
|
146
|
+
def destroy_file_and_files_associations
|
147
|
+
(self.class.am_file_fields + self.class.am_files_fields).each do |field|
|
148
|
+
::AssetManager::AssetAssociation.destroy_all(
|
149
|
+
owner_type: self.class.name,
|
150
|
+
owner_id: id,
|
151
|
+
context: field
|
152
|
+
)
|
153
|
+
end
|
154
|
+
end
|
155
|
+
end
|
data/lib/asset_manager/all.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
|
-
require 'asset_manager/
|
2
|
-
require '
|
3
|
-
require '
|
4
|
-
require '
|
5
|
-
require '
|
1
|
+
require 'asset_manager/active_record'
|
2
|
+
require 'asset_manager/deprecated.rb'
|
3
|
+
require 'asset_manager/custom_versions.rb'
|
4
|
+
require 'asset_manager/touch_translation.rb'
|
5
|
+
require 'asset_manager/translations.rb'
|
File without changes
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module AssetManager
|
2
|
+
module Deprecated
|
3
|
+
|
4
|
+
module AssetsHelper
|
5
|
+
def asset_manager_select_link(resource, field, save = false)
|
6
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_select instead.")
|
7
|
+
am_select_link(resource, field, save)
|
8
|
+
end
|
9
|
+
|
10
|
+
def am_icon_url(type, size = 16, frontend = true)
|
11
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_ico_path instead.")
|
12
|
+
am_ico_path(type, size: size)
|
13
|
+
end
|
14
|
+
|
15
|
+
def render_attachments(assets, title = t('.downloads', default: 'Downloads'), size = nil, categorized = true)
|
16
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_render instead.")
|
17
|
+
nil
|
18
|
+
end
|
19
|
+
|
20
|
+
def categorized_asset_group(assets, size = nil)
|
21
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_render instead.")
|
22
|
+
nil
|
23
|
+
end
|
24
|
+
|
25
|
+
def asset_group(assets, size = nil)
|
26
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_render instead.")
|
27
|
+
nil
|
28
|
+
end
|
29
|
+
|
30
|
+
def assets(collection, version = nil, options = {}, container_class = '', linked = false)
|
31
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_render instead.")
|
32
|
+
nil
|
33
|
+
end
|
34
|
+
|
35
|
+
def asset(resource, version = nil, options = {}, container_asset_class = '', linked = false)
|
36
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_render instead.")
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def clippy(text, bgcolor = '#FFFFFF')
|
41
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_clippy instead.")
|
42
|
+
am_clippy(text, bg_color: bgcolor)
|
43
|
+
end
|
44
|
+
|
45
|
+
def asset_url(resource, version = nil)
|
46
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_asset_url instead.")
|
47
|
+
am_asset_url(resource, version: version)
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
module AssetInstancesHelper
|
52
|
+
def asset_instance(resource, version = nil, options = {}, linked = false)
|
53
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated.")
|
54
|
+
nil
|
55
|
+
end
|
56
|
+
|
57
|
+
def asset_instance_url(resource, options = {})
|
58
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_asset_instance_url instead.")
|
59
|
+
am_asset_instance_url(resource, options)
|
60
|
+
end
|
61
|
+
|
62
|
+
def display_instance_context(resource)
|
63
|
+
Rails.logger.warn ActiveSupport::Deprecation.warn("#{__callee__} is deprecated - use am_display_instance_context instead.")
|
64
|
+
am_display_instance_context(resource)
|
65
|
+
end
|
66
|
+
end
|
67
|
+
|
68
|
+
end
|
69
|
+
end
|
data/lib/asset_manager/engine.rb
CHANGED
@@ -9,25 +9,21 @@ module AssetManager
|
|
9
9
|
config.generators.stylesheets true
|
10
10
|
config.generators.form_builder :formtastic
|
11
11
|
|
12
|
-
|
13
|
-
|
12
|
+
initializer 'asset_manager' do |app|
|
13
|
+
app.config.assets.precompile += ['asset_manager.css', 'asset_manager.js']
|
14
|
+
|
15
|
+
# We include the engine's helpers
|
14
16
|
ActiveSupport.on_load :action_view do
|
15
17
|
include AssetManager::AssetsHelper
|
16
18
|
include AssetManager::AssetInstancesHelper
|
17
19
|
end
|
18
|
-
ActiveSupport.on_load :active_record do
|
19
|
-
Formtastic::Inputs.autoload(:AssetManagerInput, 'formtastic/inputs/asset_manager_input') if defined?(Formtastic)
|
20
|
-
SimpleForm::Inputs.autoload(:AssetManagerInput, 'simple_form/inputs/asset_manager_input') if defined?(SimpleForm)
|
21
|
-
end
|
22
|
-
end
|
23
20
|
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
]
|
30
|
-
end
|
21
|
+
# Formtastic input type
|
22
|
+
Formtastic::Inputs.autoload(:AssetManagerInput, 'formtastic/inputs/asset_manager_input') if defined?(Formtastic)
|
23
|
+
|
24
|
+
# SimpleForm input type
|
25
|
+
SimpleForm::Inputs.autoload(:AssetManagerInput, 'simple_form/inputs/asset_manager_input') if defined?(SimpleForm)
|
31
26
|
end
|
27
|
+
|
32
28
|
end
|
33
29
|
end
|
File without changes
|
File without changes
|
@@ -1,7 +1,7 @@
|
|
1
1
|
module SimpleForm
|
2
2
|
module Inputs
|
3
|
-
class AssetManagerInput < SimpleForm::Inputs::Base
|
4
3
|
|
4
|
+
class AssetManagerInput < SimpleForm::Inputs::Base
|
5
5
|
def input
|
6
6
|
template.content_tag(:div, class: 'asset_manager_container') do
|
7
7
|
template.concat select_link
|
@@ -28,7 +28,7 @@ module SimpleForm
|
|
28
28
|
end
|
29
29
|
end
|
30
30
|
end
|
31
|
-
|
32
31
|
end
|
32
|
+
|
33
33
|
end
|
34
34
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: intesys_asset_manager
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Intesys S.r.l.
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-05-
|
12
|
+
date: 2014-05-26 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: acts-as-taggable-on
|
@@ -416,19 +416,18 @@ files:
|
|
416
416
|
- db/migrate/20121005072255_acts_as_taggable_on_migration.rb
|
417
417
|
- db/migrate/20140512090937_add_taggings_counter_cache_to_tags.acts_as_taggable_on_engine.rb
|
418
418
|
- db/migrate/20130417082644_asset_manager_add_index_to_foreign_keys.rb
|
419
|
-
- lib/custom_versions.rb
|
420
|
-
- lib/deprecated.rb
|
421
|
-
- lib/translations.rb
|
422
419
|
- lib/formtastic/inputs/asset_manager_input.rb
|
423
420
|
- lib/tasks/asset_manager_tasks.rake
|
424
421
|
- lib/asset_manager.rb
|
425
422
|
- lib/simple_form/inputs/asset_manager_input.rb
|
426
423
|
- lib/intesys_asset_manager.rb
|
427
424
|
- lib/asset_manager/engine.rb
|
425
|
+
- lib/asset_manager/custom_versions.rb
|
426
|
+
- lib/asset_manager/deprecated.rb
|
427
|
+
- lib/asset_manager/translations.rb
|
428
428
|
- lib/asset_manager/all.rb
|
429
|
-
- lib/asset_manager/
|
430
|
-
- lib/asset_manager/
|
431
|
-
- lib/touch_translation.rb
|
429
|
+
- lib/asset_manager/active_record.rb
|
430
|
+
- lib/asset_manager/touch_translation.rb
|
432
431
|
- lib/assets/javascripts/bootstrap2/bootstrap.js
|
433
432
|
- lib/assets/stylesheets/bootstrap2/bootstrap.css.erb
|
434
433
|
- lib/assets/stylesheets/bootstrap2/bootstrap-responsive.css
|
@@ -1,152 +0,0 @@
|
|
1
|
-
class ActiveRecord::Base
|
2
|
-
class << self
|
3
|
-
attr_reader :am_file, :am_file_options, :am_files, :am_files_options
|
4
|
-
end
|
5
|
-
|
6
|
-
def self.has_file(field, options = {})
|
7
|
-
fail "has_file :#{field} for #{name} class is not a valid name. The name must be singular!" if field.to_s != field.to_s.singularize
|
8
|
-
options.assert_valid_keys(:accepted, :type, :mode)
|
9
|
-
options.reverse_merge!(type: :public, max: 1, mode: :file)
|
10
|
-
|
11
|
-
@am_file = [] if @am_file.nil?
|
12
|
-
@am_file.push(field) unless @am_file.include?(field)
|
13
|
-
@am_file_options = {} if @am_file_options.nil?
|
14
|
-
@am_file_options[field] = options
|
15
|
-
|
16
|
-
attr_accessible am_field_name(field, false)
|
17
|
-
attr_accessor am_field_name(field, false)
|
18
|
-
|
19
|
-
has_one "asset_association_#{field}".to_sym, as: :owner, class_name: 'AssetManager::AssetAssociation', conditions: { context: "#{field}" }
|
20
|
-
has_one "#{field}".to_sym, through: "asset_association_#{field}".to_sym, source: :asset, class_name: 'AssetManager::Asset'
|
21
|
-
|
22
|
-
after_save :save_file_associations
|
23
|
-
after_destroy :destroy_file_and_files_associations
|
24
|
-
end
|
25
|
-
|
26
|
-
def self.has_private_file(field, options = {})
|
27
|
-
has_file(field, options.merge(type: :private))
|
28
|
-
end
|
29
|
-
|
30
|
-
def self.has_image(field, options = {})
|
31
|
-
has_file(field, options.merge(accepted: %w(jpg gif png), mode: :image))
|
32
|
-
end
|
33
|
-
|
34
|
-
def self.has_files(field, options = {})
|
35
|
-
fail "has_files :#{field} for #{name} class is not a valid name. The name must be plural!" if field.to_s != field.to_s.pluralize
|
36
|
-
options.assert_valid_keys(:accepted, :type, :mode, :max)
|
37
|
-
options.reverse_merge!(type: :public, mode: :files, max: 999)
|
38
|
-
|
39
|
-
@am_files = [] if @am_files.nil?
|
40
|
-
@am_files.push(field) unless @am_files.include?(field)
|
41
|
-
@am_files_options = {} if @am_files_options.nil?
|
42
|
-
@am_files_options[field] = options
|
43
|
-
|
44
|
-
attr_accessible am_field_name(field, true)
|
45
|
-
|
46
|
-
has_many "asset_association_#{field}".to_sym, as: :owner, class_name: 'AssetManager::AssetAssociation', conditions: { context: "#{field}" }
|
47
|
-
has_many "#{field}".to_sym, through: "asset_association_#{field}".to_sym, source: :asset, class_name: 'AssetManager::Asset'
|
48
|
-
|
49
|
-
after_save :save_files_associations
|
50
|
-
after_destroy :destroy_file_and_files_associations
|
51
|
-
end
|
52
|
-
|
53
|
-
def self.has_private_files(field, options = {})
|
54
|
-
has_files(field, options.merge(type: :private))
|
55
|
-
end
|
56
|
-
|
57
|
-
def self.has_images(field, options = {})
|
58
|
-
has_files(field, options.merge(accepted: %w(jpg gif png), mode: :images))
|
59
|
-
end
|
60
|
-
|
61
|
-
def self.am_file_fields
|
62
|
-
@am_file.nil? ? [] : @am_file
|
63
|
-
end
|
64
|
-
|
65
|
-
def self.am_files_fields
|
66
|
-
@am_files.nil? ? [] : @am_files
|
67
|
-
end
|
68
|
-
|
69
|
-
def self.am_file_options
|
70
|
-
@am_file_options.nil? ? {} : @am_file_options
|
71
|
-
end
|
72
|
-
|
73
|
-
def self.am_files_options
|
74
|
-
@am_files_options.nil? ? {} : @am_files_options
|
75
|
-
end
|
76
|
-
|
77
|
-
def self.am_has_field?(field)
|
78
|
-
am_file_fields.include?(field.to_sym) || am_files_fields.include?(field.to_sym)
|
79
|
-
end
|
80
|
-
|
81
|
-
def self.am_field_option(field, key)
|
82
|
-
options = field_options(field)
|
83
|
-
options[field.to_sym][key] rescue nil
|
84
|
-
end
|
85
|
-
|
86
|
-
def self.am_field_name(field, multiple)
|
87
|
-
"#{field.to_s.singularize}_#{multiple ? 'ids' : 'id'}".to_sym
|
88
|
-
end
|
89
|
-
|
90
|
-
private
|
91
|
-
|
92
|
-
def self.field_options(field)
|
93
|
-
am_file_fields.include?(field.to_sym) ? am_file_options : am_files_options
|
94
|
-
end
|
95
|
-
|
96
|
-
def save_file_associations
|
97
|
-
self.class.am_file_fields.each do |field|
|
98
|
-
value = send(self.class.am_field_name(field, false))
|
99
|
-
unless value.nil?
|
100
|
-
::AssetManager::AssetAssociation.destroy_all(
|
101
|
-
owner_type: self.class.name,
|
102
|
-
owner_id: id,
|
103
|
-
context: field
|
104
|
-
)
|
105
|
-
unless value.blank?
|
106
|
-
::AssetManager::AssetAssociation.create(
|
107
|
-
owner_type: self.class.name,
|
108
|
-
owner_id: id,
|
109
|
-
context: field,
|
110
|
-
asset_id: value.to_i,
|
111
|
-
position: 1
|
112
|
-
)
|
113
|
-
end
|
114
|
-
end
|
115
|
-
end
|
116
|
-
end
|
117
|
-
|
118
|
-
def save_files_associations
|
119
|
-
self.class.am_files_fields.each do |field|
|
120
|
-
values = send(self.class.am_field_name(field, true))
|
121
|
-
unless values.nil?
|
122
|
-
::AssetManager::AssetAssociation.destroy_all(
|
123
|
-
owner_type: self.class.name,
|
124
|
-
owner_id: id,
|
125
|
-
context: field
|
126
|
-
)
|
127
|
-
values.reject! { |a| a.to_s.strip.length == 0 }
|
128
|
-
unless values.empty?
|
129
|
-
values.each_with_index do |value, index|
|
130
|
-
::AssetManager::AssetAssociation.create(
|
131
|
-
owner_type: self.class.name,
|
132
|
-
owner_id: id,
|
133
|
-
context: field,
|
134
|
-
asset_id: value.to_i,
|
135
|
-
position: (index + 1)
|
136
|
-
)
|
137
|
-
end
|
138
|
-
end
|
139
|
-
end
|
140
|
-
end
|
141
|
-
end
|
142
|
-
|
143
|
-
def destroy_file_and_files_associations
|
144
|
-
(self.class.am_file_fields + self.class.am_files_fields).each do |field|
|
145
|
-
::AssetManager::AssetAssociation.destroy_all(
|
146
|
-
owner_type: self.class.name,
|
147
|
-
owner_id: id,
|
148
|
-
context: field
|
149
|
-
)
|
150
|
-
end
|
151
|
-
end
|
152
|
-
end
|
@@ -1 +0,0 @@
|
|
1
|
-
require 'asset_manager/extensions/active_record'
|
data/lib/deprecated.rb
DELETED
@@ -1,61 +0,0 @@
|
|
1
|
-
module AssetManager
|
2
|
-
module Deprecated
|
3
|
-
module AssetsHelper
|
4
|
-
def asset_manager_select_link(resource, field, save = false)
|
5
|
-
ActiveSupport::Deprecation.warn('asset_manager_select_link will be deprecated; use am_select_link')
|
6
|
-
am_select_link(resource, field, save)
|
7
|
-
end
|
8
|
-
|
9
|
-
def am_icon_url(type, size = 16, frontend = true)
|
10
|
-
ActiveSupport::Deprecation.warn('am_icon_url will be deprecated; use am_ico_path')
|
11
|
-
am_ico_path(type, size: size)
|
12
|
-
end
|
13
|
-
|
14
|
-
def render_attachments(assets, title = t('.downloads', default: 'Downloads'), size = nil, categorized = true)
|
15
|
-
ActiveSupport::Deprecation.warn('render_attachments will be deprecated; use am_render')
|
16
|
-
end
|
17
|
-
|
18
|
-
def categorized_asset_group(assets, size = nil)
|
19
|
-
ActiveSupport::Deprecation.warn('categorized_asset_group will be deprecated; use am_render')
|
20
|
-
end
|
21
|
-
|
22
|
-
def asset_group(assets, size = nil)
|
23
|
-
ActiveSupport::Deprecation.warn('asset_group will be deprecated; use am_render')
|
24
|
-
end
|
25
|
-
|
26
|
-
def assets(collection, version = nil, options = {}, container_class = '', linked = false)
|
27
|
-
ActiveSupport::Deprecation.warn('assets will be deprecated; use am_render')
|
28
|
-
end
|
29
|
-
|
30
|
-
def asset(resource, version = nil, options = {}, container_asset_class = '', linked = false)
|
31
|
-
ActiveSupport::Deprecation.warn('asset will be deprecated; use am_render')
|
32
|
-
end
|
33
|
-
|
34
|
-
def clippy(text, bgcolor = '#FFFFFF')
|
35
|
-
ActiveSupport::Deprecation.warn('clippy will be deprecated; use am_clippy')
|
36
|
-
am_clippy(text, bg_color: bgcolor)
|
37
|
-
end
|
38
|
-
|
39
|
-
def asset_url(resource, version = nil)
|
40
|
-
ActiveSupport::Deprecation.warn('asset_url will be deprecated; use am_asset_url')
|
41
|
-
am_asset_url(resource, version: version)
|
42
|
-
end
|
43
|
-
end
|
44
|
-
|
45
|
-
module AssetInstancesHelper
|
46
|
-
def asset_instance(resource, version = nil, options = {}, linked = false)
|
47
|
-
ActiveSupport::Deprecation.warn('asset_instance will be deprecated')
|
48
|
-
end
|
49
|
-
|
50
|
-
def asset_instance_url(resource, options = {})
|
51
|
-
ActiveSupport::Deprecation.warn('asset_instance_url will be deprecated; use am_asset_instance_url')
|
52
|
-
am_asset_instance_url(resource, options)
|
53
|
-
end
|
54
|
-
|
55
|
-
def display_instance_context(resource)
|
56
|
-
ActiveSupport::Deprecation.warn('display_instance_context will be deprecated; use am_display_instance_context')
|
57
|
-
am_display_instance_context(resource)
|
58
|
-
end
|
59
|
-
end
|
60
|
-
end
|
61
|
-
end
|