trusty-cms 4.0.1 → 4.1.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +3 -3
- data/Gemfile.lock +106 -106
- data/Rakefile +7 -7
- data/app/assets/images/admin/spinner.gif +0 -0
- data/app/assets/javascripts/admin.js +3 -0
- data/app/assets/javascripts/admin/more-or-less.js +2 -2
- data/app/assets/javascripts/admin/tabcontrol.js.erb +1 -2
- data/app/assets/stylesheets/admin/_base.scss +22 -6
- data/app/assets/stylesheets/admin/_multi_site_main.scss +28 -29
- data/app/assets/stylesheets/admin/_reset.scss +5 -4
- data/app/assets/stylesheets/admin/_site_chooser.scss +44 -69
- data/app/assets/stylesheets/admin/assets.scss +138 -141
- data/app/assets/stylesheets/admin/main.scss +10 -12
- data/app/assets/stylesheets/admin/modules/_boxes.scss +0 -3
- data/app/assets/stylesheets/admin/modules/_buttons.scss +30 -0
- data/app/assets/stylesheets/admin/modules/_links.scss +1 -1
- data/app/assets/stylesheets/admin/partials/_actions.scss +29 -46
- data/app/assets/stylesheets/admin/partials/_avatars.scss +3 -2
- data/app/assets/stylesheets/admin/partials/_content.scss +15 -38
- data/app/assets/stylesheets/admin/partials/_dateinput.scss +23 -14
- data/app/assets/stylesheets/admin/partials/_drawer.scss +78 -0
- data/app/assets/stylesheets/admin/partials/_dropdown.scss +9 -12
- data/app/assets/stylesheets/admin/partials/_footer.scss +4 -3
- data/app/assets/stylesheets/admin/partials/_forms.scss +64 -491
- data/app/assets/stylesheets/admin/partials/_header.scss +9 -118
- data/app/assets/stylesheets/admin/partials/_layout.scss +26 -2
- data/app/assets/stylesheets/admin/partials/_login_form.scss +28 -0
- data/app/assets/stylesheets/admin/partials/_messages.scss +10 -5
- data/app/assets/stylesheets/admin/partials/_popup.scss +61 -50
- data/app/assets/stylesheets/admin/partials/_preferences.scss +37 -0
- data/app/assets/stylesheets/admin/partials/_sidebar.scss +55 -0
- data/app/assets/stylesheets/admin/partials/_tabcontrol.scss +24 -36
- data/app/assets/stylesheets/admin/partials/{_index.scss → _table.scss} +53 -84
- data/app/assets/stylesheets/admin/partials/_toolbar.scss +11 -6
- data/app/assets/stylesheets/admin/partials/_treetable.scss +1 -71
- data/app/assets/stylesheets/admin/partials/_typography.scss +30 -55
- data/app/assets/stylesheets/admin/partials/_validations.scss +6 -5
- data/app/assets/stylesheets/rad_social/rad_screen.scss +65 -64
- data/app/controllers/admin/assets_controller.rb +21 -31
- data/app/controllers/admin/configuration_controller.rb +9 -11
- data/app/controllers/admin/extensions_controller.rb +3 -3
- data/app/controllers/admin/layouts_controller.rb +3 -4
- data/app/controllers/admin/page_attachments_controller.rb +5 -5
- data/app/controllers/admin/page_fields_controller.rb +3 -4
- data/app/controllers/admin/page_parts_controller.rb +4 -5
- data/app/controllers/admin/pages_controller.rb +55 -56
- data/app/controllers/admin/references_controller.rb +1 -1
- data/app/controllers/admin/resource_controller.rb +132 -128
- data/app/controllers/admin/sites_controller.rb +4 -4
- data/app/controllers/admin/snippets_controller.rb +3 -4
- data/app/controllers/admin/users_controller.rb +16 -16
- data/app/controllers/application_controller.rb +47 -48
- data/app/controllers/site_controller.rb +51 -48
- data/app/controllers/social_mailer_controller.rb +13 -16
- data/app/helpers/admin/configuration_helper.rb +19 -20
- data/app/helpers/admin/layouts_helper.rb +0 -1
- data/app/helpers/admin/node_helper.rb +27 -24
- data/app/helpers/admin/pages_helper.rb +2 -2
- data/app/helpers/admin/preferences_helper.rb +0 -1
- data/app/helpers/admin/references_helper.rb +9 -10
- data/app/helpers/admin/regions_helper.rb +3 -3
- data/app/helpers/application_helper.rb +34 -35
- data/app/helpers/rad_social_helper.rb +8 -11
- data/app/helpers/scoped_helper.rb +1 -3
- data/app/helpers/sites_helper.rb +4 -4
- data/app/mailers/devise_mailer.rb +3 -4
- data/app/mailers/rad_social_mailer.rb +8 -8
- data/app/models/asset.rb +62 -63
- data/app/models/asset_type.rb +38 -39
- data/app/models/deprecated_tags.rb +3 -4
- data/app/models/file_not_found_page.rb +1 -3
- data/app/models/haml_filter.rb +1 -1
- data/app/models/layout.rb +4 -5
- data/app/models/legacy_user.rb +2 -2
- data/app/models/menu_renderer.rb +16 -18
- data/app/models/page.rb +96 -93
- data/app/models/page_attachment.rb +1 -2
- data/app/models/page_context.rb +11 -12
- data/app/models/page_part.rb +3 -4
- data/app/models/rails_page.rb +10 -12
- data/app/models/site.rb +22 -21
- data/app/models/snippet.rb +6 -8
- data/app/models/snippet_finder.rb +3 -3
- data/app/models/snippet_tags.rb +4 -4
- data/app/models/standard_tags.rb +258 -252
- data/app/models/status.rb +8 -8
- data/app/models/trusty_cms/config.rb +25 -25
- data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
- data/app/models/user.rb +15 -14
- data/app/models/user_action_observer.rb +3 -3
- data/app/users/_choose_site.html.haml +3 -7
- data/app/views/admin/assets/_form.html.haml +2 -1
- data/app/views/admin/assets/_search.html.haml +2 -1
- data/app/views/admin/assets/edit.html.haml +2 -10
- data/app/views/admin/assets/index.html.haml +4 -2
- data/app/views/admin/assets/new.html.haml +4 -8
- data/app/views/admin/assets/remove.html.haml +2 -1
- data/app/views/admin/configuration/edit.html.haml +7 -7
- data/app/views/admin/configuration/show.html.haml +6 -8
- data/app/views/admin/layouts/_choose_site.html.haml +2 -3
- data/app/views/admin/layouts/_form.html.haml +13 -12
- data/app/views/admin/layouts/_site_chooser.html.haml +2 -2
- data/app/views/admin/layouts/index.html.haml +11 -4
- data/app/views/admin/layouts/remove.html.haml +6 -5
- data/app/views/admin/page_attachments/_attachment.html.haml +2 -2
- data/app/views/admin/page_fields/_page_field.html.haml +3 -3
- data/app/views/admin/page_parts/_page_part.html.haml +5 -6
- data/app/views/admin/pages/_asset_popups.html.haml +15 -16
- data/app/views/admin/pages/_assets.html.haml +8 -7
- data/app/views/admin/pages/_fields.html.haml +16 -13
- data/app/views/admin/pages/_node.html.haml +3 -3
- data/app/views/admin/pages/_popups.html.haml +11 -11
- data/app/views/admin/pages/edit.html.haml +2 -2
- data/app/views/admin/pages/index.html.haml +5 -2
- data/app/views/admin/pages/new.html.haml +3 -3
- data/app/views/admin/pages/remove.html.haml +4 -3
- data/app/views/admin/preferences/edit.html.haml +5 -5
- data/app/views/admin/references/filters.haml +1 -1
- data/app/views/admin/references/tags.haml +3 -3
- data/app/views/admin/removed/_assets_bucket.html.haml +3 -3
- data/app/views/admin/removed/_assets_container.html.haml +18 -18
- data/app/views/admin/removed/_bucket.html.haml +1 -1
- data/app/views/admin/removed/_bucket_asset.html.haml +3 -3
- data/app/views/admin/removed/_show_bucket_link.html.haml +1 -1
- data/app/views/admin/removed/_upload_to_page.html.haml +5 -5
- data/app/views/admin/sites/_form.haml +18 -18
- data/app/views/admin/sites/edit.haml +1 -1
- data/app/views/admin/sites/index.haml +8 -4
- data/app/views/admin/sites/new.haml +1 -1
- data/app/views/admin/snippets/_choose_site.html.haml +4 -5
- data/app/views/admin/snippets/_form.html.haml +8 -9
- data/app/views/admin/snippets/edit.html.haml +1 -1
- data/app/views/admin/snippets/index.html.haml +11 -4
- data/app/views/admin/snippets/new.html.haml +1 -1
- data/app/views/admin/snippets/remove.html.haml +7 -6
- data/app/views/admin/users/_avatar.html.haml +2 -2
- data/app/views/admin/users/_choose_site.html.haml +3 -7
- data/app/views/admin/users/_form.html.haml +18 -21
- data/app/views/admin/users/_password_fields.html.haml +6 -6
- data/app/views/admin/users/index.html.haml +13 -6
- data/app/views/admin/users/remove.html.haml +4 -4
- data/app/views/admin/welcome/login.html.haml +8 -8
- data/app/views/devise/passwords/edit.html.haml +6 -6
- data/app/views/devise/passwords/new.html.haml +3 -3
- data/app/views/devise/sessions/new.html.haml +8 -8
- data/app/views/devise/shared/_links.html.haml +2 -2
- data/app/views/layouts/application.html.haml +24 -19
- data/app/views/rad_social_mailer/social_mail_form.html.haml +15 -15
- data/app/views/widget/_email_form.html.haml +14 -14
- data/app/views/widget/_horizontal_widget.html.haml +5 -5
- data/bin/rails +4 -4
- data/bin/trusty_cms +3 -5
- data/config.ru +1 -1
- data/config/application.rb +14 -15
- data/config/boot.rb +1 -2
- data/config/environment.rb +1 -1
- data/config/environments/production.rb +0 -1
- data/config/environments/test.rb +1 -2
- data/config/initializers/devise.rb +1 -1
- data/config/initializers/kraken.rb +2 -2
- data/config/initializers/tmp.rb +1 -1
- data/config/initializers/trusty_cms_config.rb +48 -48
- data/config/locales/en.yml +8 -8
- data/config/routes.rb +6 -7
- data/lib/active_record_extensions/active_record_extensions.rb +1 -2
- data/lib/annotatable.rb +3 -5
- data/lib/configuration_extensions/configuration_extensions.rb +1 -1
- data/lib/inheritable_class_attributes.rb +13 -9
- data/lib/login_system.rb +73 -73
- data/lib/method_observer.rb +13 -12
- data/lib/ostruct.rb +7 -10
- data/lib/simpleton.rb +0 -4
- data/lib/string_extensions/string_extensions.rb +3 -3
- data/lib/symbol_extensions/symbol_extensions.rb +1 -1
- data/lib/tasks/database.rake +28 -28
- data/lib/tasks/extensions.rake +18 -18
- data/lib/tasks/framework.rake +68 -68
- data/lib/tasks/radiant_config.rake +4 -4
- data/lib/tasks/snippets_extension_tasks.rake +11 -11
- data/lib/tasks/translate.rake +14 -14
- data/lib/tasks/upgrade_to_devise.rake +1 -1
- data/lib/translation_support.rb +22 -22
- data/lib/trusty_cms.rb +2 -2
- data/lib/trusty_cms/admin_ui.rb +19 -16
- data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
- data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
- data/lib/trusty_cms/available_locales.rb +2 -4
- data/lib/trusty_cms/config/definition.rb +11 -8
- data/lib/trusty_cms/engine.rb +14 -14
- data/lib/trusty_cms/extension.rb +14 -16
- data/lib/trusty_cms/extension_loader.rb +6 -6
- data/lib/trusty_cms/extension_migrator.rb +42 -41
- data/lib/trusty_cms/extension_path.rb +20 -19
- data/lib/trusty_cms/initializer.rb +5 -8
- data/lib/trusty_cms/pagination/controller.rb +7 -10
- data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
- data/lib/trusty_cms/resource_responses.rb +3 -3
- data/lib/trusty_cms/setup.rb +130 -132
- data/lib/trusty_cms/taggable.rb +19 -22
- data/lib/trusty_cms/task_support.rb +9 -6
- data/package.json +10 -2
- data/public/dispatch.fcgi +1 -1
- data/public/dispatch.rb +2 -2
- data/script/extension +1 -1
- data/script/rails +2 -2
- data/spec/dummy/package.json +1 -1
- data/spec/dummy/yarn.lock +3 -3
- data/trusty_cms.gemspec +25 -25
- data/vendor/extensions/clipped-extension/lib/clipped_admin_ui.rb +1 -1
- data/yarn.lock +1992 -4
- metadata +54 -42
- data/app/assets/stylesheets/admin/partials/_deprecated.scss +0 -65
- data/app/assets/stylesheets/admin/partials/_jquery-ui-structure.scss +0 -258
- data/app/assets/stylesheets/admin/partials/_jquery-ui-theme.scss +0 -410
- data/app/assets/stylesheets/admin/partials/_jquery-ui.scss +0 -650
- data/app/views/admin/assets/refresh.html.haml +0 -14
data/app/models/asset.rb
CHANGED
@@ -1,17 +1,17 @@
|
|
1
1
|
class Asset < ActiveRecord::Base
|
2
2
|
include Paperclip::Glue
|
3
3
|
|
4
|
-
has_many :page_attachments, :
|
5
|
-
has_many :pages, :
|
4
|
+
has_many :page_attachments, dependent: :destroy
|
5
|
+
has_many :pages, through: :page_attachments
|
6
6
|
has_site if respond_to? :has_site
|
7
7
|
|
8
|
-
belongs_to :created_by, :
|
9
|
-
belongs_to :updated_by, :
|
8
|
+
belongs_to :created_by, class_name: 'User'
|
9
|
+
belongs_to :updated_by, class_name: 'User'
|
10
10
|
|
11
|
-
default_scope {order(
|
11
|
+
default_scope { order('created_at DESC') }
|
12
12
|
|
13
13
|
scope :latest, lambda { |limit|
|
14
|
-
order(
|
14
|
+
order('created_at DESC').limit(limit)
|
15
15
|
}
|
16
16
|
|
17
17
|
scope :of_types, lambda { |types|
|
@@ -20,81 +20,81 @@ class Asset < ActiveRecord::Base
|
|
20
20
|
}
|
21
21
|
|
22
22
|
scope :matching, lambda { |term|
|
23
|
-
where([
|
23
|
+
where(['LOWER(assets.asset_file_name) LIKE (:term) OR LOWER(title) LIKE (:term) OR LOWER(caption) LIKE (:term)', { term: "%#{term.downcase}%" }])
|
24
24
|
}
|
25
25
|
|
26
26
|
scope :excepting, lambda { |assets|
|
27
27
|
if assets.any?
|
28
28
|
assets = assets.split(',') if assets.is_a?(String)
|
29
29
|
asset_ids = assets.first.is_a?(Asset) ? assets.map(&:id) : assets
|
30
|
-
where(["assets.id NOT IN(#{asset_ids.map{ '?' }.join(',')})", *asset_ids])
|
30
|
+
where(["assets.id NOT IN(#{asset_ids.map { '?' }.join(',')})", *asset_ids])
|
31
31
|
else
|
32
32
|
{}
|
33
33
|
end
|
34
34
|
}
|
35
35
|
|
36
36
|
has_attached_file :asset,
|
37
|
-
:
|
37
|
+
styles: lambda { |attachment|
|
38
38
|
AssetType.for(attachment).paperclip_styles
|
39
39
|
},
|
40
|
-
:
|
40
|
+
processors: lambda { |asset|
|
41
41
|
asset.paperclip_processors
|
42
42
|
},
|
43
|
-
:
|
44
|
-
:
|
45
|
-
:
|
46
|
-
:
|
47
|
-
:
|
48
|
-
|
49
|
-
:
|
50
|
-
:
|
51
|
-
:
|
52
|
-
|
53
|
-
'Cache-Control' => 'max-age=31536000'
|
43
|
+
whiny: false,
|
44
|
+
storage: TrustyCms.config['paperclip.storage'],
|
45
|
+
path: TrustyCms.config['paperclip.path'],
|
46
|
+
url: TrustyCms.config['paperclip.url'],
|
47
|
+
fog_credentials: TrustyCmsClippedExtension::Cloud.credentials,
|
48
|
+
fog_directory: TrustyCms.config['paperclip.fog.directory'],
|
49
|
+
fog_public: TrustyCms.config['paperclip.fog.public?'] || true,
|
50
|
+
fog_host: TrustyCmsClippedExtension::Cloud.host,
|
51
|
+
fog_file: {
|
52
|
+
'Cache-Control' => 'max-age=31536000',
|
54
53
|
}
|
55
54
|
|
56
|
-
validates_attachment_content_type :asset, :
|
55
|
+
validates_attachment_content_type :asset, content_type: ['application/zip', 'image/jpg', 'image/jpeg', 'image/png', 'image/gif', 'application/pdf', 'application/javascript', 'text/javascript', 'text/css']
|
57
56
|
|
58
57
|
before_save :assign_title
|
59
58
|
before_save :assign_uuid
|
60
59
|
|
61
60
|
after_post_process :read_dimensions
|
62
61
|
|
63
|
-
validates_attachment_presence :asset, :
|
64
|
-
if TrustyCms.config[
|
65
|
-
validates_attachment_content_type :asset, :
|
62
|
+
validates_attachment_presence :asset, message: 'You must choose a file to upload!'
|
63
|
+
if TrustyCms.config['paperclip.skip_filetype_validation'] != 'true' && TrustyCms.config['paperclip.content_types']
|
64
|
+
validates_attachment_content_type :asset, content_type: TrustyCms.config['paperclip.content_types'].gsub(' ', '').split(',')
|
66
65
|
else
|
67
|
-
validates_attachment_presence :asset, :
|
66
|
+
validates_attachment_presence :asset, message: 'Your uploaded file must have an extension in its name!'
|
68
67
|
end
|
69
|
-
validates_attachment_size :asset, :
|
68
|
+
validates_attachment_size :asset, less_than: (TrustyCms.config['assets.max_asset_size'] || 5).to_i.megabytes
|
70
69
|
|
71
70
|
def asset_type
|
72
71
|
AssetType.for(asset)
|
73
72
|
end
|
74
|
-
delegate :paperclip_processors, :paperclip_styles, :style_dimensions, :style_format, :
|
73
|
+
delegate :paperclip_processors, :paperclip_styles, :style_dimensions, :style_format, to: :asset_type
|
75
74
|
|
76
|
-
def thumbnail(style_name='original')
|
75
|
+
def thumbnail(style_name = 'original')
|
77
76
|
return asset.url if style_name.to_sym == :original
|
78
77
|
return asset.url(style_name.to_sym) if has_style?(style_name)
|
79
|
-
|
78
|
+
|
79
|
+
asset_type.icon(style_name)
|
80
80
|
end
|
81
81
|
|
82
|
-
def has_style?(style_name='original')
|
82
|
+
def has_style?(style_name = 'original')
|
83
83
|
style_name == 'original' || paperclip_styles.keys.include?(style_name.to_sym)
|
84
84
|
end
|
85
85
|
|
86
86
|
def basename
|
87
|
-
File.basename(asset_file_name,
|
87
|
+
File.basename(asset_file_name, '.*') if asset_file_name
|
88
88
|
end
|
89
89
|
|
90
|
-
def extension(style_name='original')
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
90
|
+
def extension(style_name = 'original')
|
91
|
+
if style_name == 'original'
|
92
|
+
original_extension
|
93
|
+
elsif style = paperclip_styles[style_name.to_sym]
|
94
|
+
style.format
|
95
|
+
else
|
96
|
+
original_extension
|
97
|
+
end
|
98
98
|
end
|
99
99
|
|
100
100
|
def original_extension
|
@@ -109,57 +109,57 @@ class Asset < ActiveRecord::Base
|
|
109
109
|
@original_geometry ||= Paperclip::Geometry.new(original_width, original_height)
|
110
110
|
end
|
111
111
|
|
112
|
-
def geometry(style_name='original')
|
112
|
+
def geometry(style_name = 'original')
|
113
113
|
raise Paperclip::StyleError, "Requested style #{style_name} is not defined for this asset." unless has_style?(style_name)
|
114
|
+
|
114
115
|
@geometry ||= {}
|
115
116
|
begin
|
116
117
|
@geometry[style_name] ||= if style_name.to_s == 'original'
|
117
|
-
|
118
|
-
|
119
|
-
|
120
|
-
|
118
|
+
original_geometry
|
119
|
+
else
|
120
|
+
style = asset.styles[style_name.to_sym]
|
121
|
+
original_geometry.transformed_by(style.geometry) # this can return dimensions for fully specified style sizes but not for relative sizes when there are no original dimensions
|
121
122
|
end
|
122
123
|
rescue Paperclip::TransformationError => e
|
123
124
|
Rails.logger.warn "geometry transformation error: #{e}"
|
124
|
-
original_geometry
|
125
|
+
original_geometry # returns a blank geometry if the real geometry cannot be calculated
|
125
126
|
end
|
126
127
|
end
|
127
128
|
|
128
|
-
def aspect(style_name='original')
|
129
|
+
def aspect(style_name = 'original')
|
129
130
|
geometry(style_name).aspect
|
130
131
|
end
|
131
132
|
|
132
|
-
def orientation(style_name='original')
|
133
|
+
def orientation(style_name = 'original')
|
133
134
|
a = aspect(style_name)
|
134
|
-
|
135
|
-
when a == nil?
|
135
|
+
if a == nil?
|
136
136
|
'unknown'
|
137
|
-
|
137
|
+
elsif a < 1.0
|
138
138
|
'vertical'
|
139
|
-
|
139
|
+
elsif a > 1.0
|
140
140
|
'horizontal'
|
141
141
|
else
|
142
142
|
'square'
|
143
143
|
end
|
144
144
|
end
|
145
145
|
|
146
|
-
def width(style_name='original')
|
146
|
+
def width(style_name = 'original')
|
147
147
|
geometry(style_name).width.to_i
|
148
148
|
end
|
149
149
|
|
150
|
-
def height(style_name='original')
|
150
|
+
def height(style_name = 'original')
|
151
151
|
geometry(style_name).height.to_i
|
152
152
|
end
|
153
153
|
|
154
|
-
def square?(style_name='original')
|
154
|
+
def square?(style_name = 'original')
|
155
155
|
geometry(style_name).square?
|
156
156
|
end
|
157
157
|
|
158
|
-
def vertical?(style_name='original')
|
158
|
+
def vertical?(style_name = 'original')
|
159
159
|
geometry(style_name).vertical?
|
160
160
|
end
|
161
161
|
|
162
|
-
def horizontal?(style_name='original')
|
162
|
+
def horizontal?(style_name = 'original')
|
163
163
|
geometry(style_name).horizontal?
|
164
164
|
end
|
165
165
|
|
@@ -167,7 +167,7 @@ class Asset < ActiveRecord::Base
|
|
167
167
|
original_width? && original_height?
|
168
168
|
end
|
169
169
|
|
170
|
-
private
|
170
|
+
private
|
171
171
|
|
172
172
|
# at this point the file queue will not have been written
|
173
173
|
# but the upload should be in place. We read dimensions from the
|
@@ -186,7 +186,7 @@ private
|
|
186
186
|
end
|
187
187
|
|
188
188
|
def assign_title
|
189
|
-
self.title =
|
189
|
+
self.title = asset_file_name.downcase.sub(original_extension, '').sub('.', '')
|
190
190
|
end
|
191
191
|
|
192
192
|
def assign_uuid
|
@@ -210,7 +210,7 @@ private
|
|
210
210
|
|
211
211
|
def with_asset_types(asset_types, &block)
|
212
212
|
w_asset_types = AssetType.conditions_for(asset_types)
|
213
|
-
with_scope(where(:
|
213
|
+
with_scope(where(conditions: ["#{w_asset_types} = ?", block]))
|
214
214
|
end
|
215
215
|
end
|
216
216
|
|
@@ -235,14 +235,13 @@ private
|
|
235
235
|
|
236
236
|
# this is a convenience for image-pickers
|
237
237
|
def self.thumbnail_options
|
238
|
-
asset_sizes = thumbnail_sizes.collect
|
238
|
+
asset_sizes = thumbnail_sizes.collect do |k, v|
|
239
239
|
size_id = k
|
240
240
|
size_description = "#{k}: "
|
241
241
|
size_description << (v.is_a?(Array) ? v.join(' as ') : v)
|
242
242
|
[size_description, size_id]
|
243
|
-
|
243
|
+
end.sort_by { |pair| pair.last.to_s }
|
244
244
|
asset_sizes.unshift ['Original (as uploaded)', 'original']
|
245
245
|
asset_sizes
|
246
246
|
end
|
247
|
-
|
248
247
|
end
|
data/app/models/asset_type.rb
CHANGED
@@ -1,5 +1,4 @@
|
|
1
1
|
class AssetType
|
2
|
-
|
3
2
|
# The Asset Type encapsulates a type of attachment.
|
4
3
|
# Conventionally this would a sensible category like 'image' or 'video'
|
5
4
|
# that should be processed and presented in a particular way.
|
@@ -34,10 +33,10 @@ class AssetType
|
|
34
33
|
Asset.send :define_method, "#{name}?".intern do this.mime_types.include?(asset_content_type) end
|
35
34
|
Asset.send :define_class_method, "#{name}_condition".intern do this.condition; end
|
36
35
|
Asset.send :define_class_method, "not_#{name}_condition".intern do this.non_condition; end
|
37
|
-
Asset.send :scope, plural.to_sym, -> {where(:
|
38
|
-
Asset.send :scope, "not_#{plural}".to_sym, -> {where(:
|
36
|
+
Asset.send :scope, plural.to_sym, -> { where(conditions: condition) }
|
37
|
+
Asset.send :scope, "not_#{plural}".to_sym, -> { where(conditions: non_condition) }
|
39
38
|
|
40
|
-
|
39
|
+
define_radius_tags
|
41
40
|
@@types.push self
|
42
41
|
@@type_lookup[@name] = self
|
43
42
|
end
|
@@ -46,21 +45,21 @@ class AssetType
|
|
46
45
|
name.to_s.pluralize
|
47
46
|
end
|
48
47
|
|
49
|
-
def icon(style_name='icon')
|
50
|
-
if File.exist?(Rails.root + "public/images/admin/assets/#{icon_name}_#{style_name
|
51
|
-
|
48
|
+
def icon(style_name = 'icon')
|
49
|
+
if File.exist?(Rails.root + "public/images/admin/assets/#{icon_name}_#{style_name}.png")
|
50
|
+
"/assets/admin/#{icon_name}_#{style_name}.png"
|
52
51
|
else
|
53
|
-
|
52
|
+
"/assets/admin/#{icon_name}_icon.png"
|
54
53
|
end
|
55
54
|
end
|
56
55
|
|
57
|
-
def icon_path(style_name='icon')
|
56
|
+
def icon_path(style_name = 'icon')
|
58
57
|
Rails.root + "public#{icon(style_name)}"
|
59
58
|
end
|
60
59
|
|
61
60
|
def condition
|
62
61
|
if @mimes.any?
|
63
|
-
["asset_content_type IN (#{@mimes.map{'?'}.join(',')})", *@mimes]
|
62
|
+
["asset_content_type IN (#{@mimes.map { '?' }.join(',')})", *@mimes]
|
64
63
|
else
|
65
64
|
self.class.other_condition
|
66
65
|
end
|
@@ -72,7 +71,7 @@ class AssetType
|
|
72
71
|
|
73
72
|
def non_condition
|
74
73
|
if @mimes.any?
|
75
|
-
["NOT asset_content_type IN (#{@mimes.map{'?'}.join(',')})", *@mimes]
|
74
|
+
["NOT asset_content_type IN (#{@mimes.map { '?' }.join(',')})", *@mimes]
|
76
75
|
else
|
77
76
|
self.class.non_other_condition
|
78
77
|
end
|
@@ -98,23 +97,23 @@ class AssetType
|
|
98
97
|
def paperclip_styles
|
99
98
|
# Styles are not relevant if processors are not defined.
|
100
99
|
@paperclip_styles ||= if paperclip_processors.any?
|
101
|
-
|
102
|
-
|
103
|
-
|
100
|
+
normalize_style_rules(configured_styles.merge(styles))
|
101
|
+
else
|
102
|
+
{}
|
104
103
|
end
|
105
104
|
@paperclip_styles
|
106
105
|
end
|
107
106
|
|
108
107
|
# Takes a motley collection of differently-defined styles and renders them into the standard hash-of-hashes format.
|
109
108
|
# Solitary strings are assumed to be #
|
110
|
-
def normalize_style_rules(styles={})
|
109
|
+
def normalize_style_rules(styles = {})
|
111
110
|
styles.each_pair do |name, rule|
|
112
111
|
unless rule.is_a? Hash
|
113
112
|
if rule =~ /\=/
|
114
|
-
parameters = rule.split(',').collect{ |parameter| parameter.split('=') }
|
115
|
-
rule = Hash[parameters].symbolize_keys
|
113
|
+
parameters = rule.split(',').collect { |parameter| parameter.split('=') } # array of pairs
|
114
|
+
rule = Hash[parameters].symbolize_keys # into hash of :first => last
|
116
115
|
else
|
117
|
-
rule = {:
|
116
|
+
rule = { geometry: rule } # simplest case: name:geom|name:geom
|
118
117
|
end
|
119
118
|
end
|
120
119
|
rule[:geometry] ||= rule.delete(:size)
|
@@ -122,10 +121,10 @@ class AssetType
|
|
122
121
|
end
|
123
122
|
styles
|
124
123
|
end
|
125
|
-
|
124
|
+
|
126
125
|
def standard_styles
|
127
126
|
{
|
128
|
-
:
|
127
|
+
thumbnail: { geometry: '100x100#', format: :png },
|
129
128
|
}
|
130
129
|
end
|
131
130
|
|
@@ -140,17 +139,17 @@ class AssetType
|
|
140
139
|
#
|
141
140
|
def configured_styles
|
142
141
|
@configured_styles ||= if style_definitions = TrustyCms.config["assets.thumbnails.#{name}"]
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
142
|
+
style_definitions.split('|').each_with_object({}) do |definition, styles|
|
143
|
+
name, rule = definition.split(':')
|
144
|
+
styles[name.strip.to_sym] = rule.to_s.strip
|
145
|
+
end
|
146
|
+
else
|
147
|
+
{}
|
149
148
|
end
|
150
149
|
end
|
151
150
|
|
152
151
|
def legacy_styles
|
153
|
-
TrustyCms::config[
|
152
|
+
TrustyCms::config['assets.additional_thumbnails'].to_s.gsub(' ', '').split(',').collect { |s| s.split('=') }.inject({}) { |ha, (k, v)| ha[k.to_sym] = v; ha }
|
154
153
|
end
|
155
154
|
|
156
155
|
def style_dimensions(style_name)
|
@@ -160,21 +159,21 @@ class AssetType
|
|
160
159
|
end
|
161
160
|
|
162
161
|
def define_radius_tags
|
163
|
-
type =
|
164
|
-
Page.class_eval
|
162
|
+
type = name
|
163
|
+
Page.class_eval do
|
165
164
|
tag "asset:if_#{type}" do |tag|
|
166
165
|
tag.expand if find_asset(tag, tag.attr.dup).send("#{type}?".to_sym)
|
167
166
|
end
|
168
167
|
tag "asset:unless_#{type}" do |tag|
|
169
168
|
tag.expand unless find_asset(tag, tag.attr.dup).send("#{type}?".to_sym)
|
170
169
|
end
|
171
|
-
|
170
|
+
end
|
172
171
|
end
|
173
172
|
|
174
173
|
# class methods
|
175
174
|
|
176
175
|
def self.for(attachment)
|
177
|
-
extension = File.extname(attachment.original_filename).sub(/^\.+/,
|
176
|
+
extension = File.extname(attachment.original_filename).sub(/^\.+/, '')
|
178
177
|
from_extension(extension) || from_mimetype(attachment.instance_read(:content_type)) || catchall
|
179
178
|
end
|
180
179
|
|
@@ -187,20 +186,21 @@ class AssetType
|
|
187
186
|
end
|
188
187
|
|
189
188
|
def self.catchall
|
190
|
-
@@default_type ||=
|
189
|
+
@@default_type ||= find(:other)
|
191
190
|
end
|
192
191
|
|
193
192
|
def self.known?(name)
|
194
|
-
!
|
193
|
+
!find(name).nil?
|
195
194
|
end
|
196
195
|
|
197
196
|
def self.slice(*types)
|
198
|
-
@@type_lookup.slice(*types.map(&:to_sym)).values if types
|
197
|
+
@@type_lookup.slice(*types.map(&:to_sym)).values if types # Hash#slice is provided by will_paginate
|
199
198
|
end
|
200
199
|
|
201
200
|
def self.find(type)
|
202
201
|
@@type_lookup[type] if type
|
203
202
|
end
|
203
|
+
|
204
204
|
def self.[](type)
|
205
205
|
find(type)
|
206
206
|
end
|
@@ -218,19 +218,18 @@ class AssetType
|
|
218
218
|
end
|
219
219
|
|
220
220
|
def self.mime_types_for(*names)
|
221
|
-
names.collect{ |name| find(name).mime_types }.flatten
|
221
|
+
names.collect { |name| find(name).mime_types }.flatten
|
222
222
|
end
|
223
223
|
|
224
224
|
def self.conditions_for(*names)
|
225
|
-
names.collect{ |name|
|
225
|
+
names.collect { |name| find(name).sanitized_condition }.join(' OR ')
|
226
226
|
end
|
227
227
|
|
228
228
|
def self.non_other_condition
|
229
|
-
["asset_content_type IN (#{known_mimetypes.map{'?'}.join(',')})", *known_mimetypes]
|
229
|
+
["asset_content_type IN (#{known_mimetypes.map { '?' }.join(',')})", *known_mimetypes]
|
230
230
|
end
|
231
231
|
|
232
232
|
def self.other_condition
|
233
|
-
["NOT asset_content_type IN (#{known_mimetypes.map{'?'}.join(',')})", *known_mimetypes]
|
233
|
+
["NOT asset_content_type IN (#{known_mimetypes.map { '?' }.join(',')})", *known_mimetypes]
|
234
234
|
end
|
235
|
-
|
236
235
|
end
|