trusty-cms 4.1.1 → 4.1.6

Sign up to get free protection for your applications and to get access to all the features.
Files changed (162) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +107 -107
  4. data/README.md +1 -1
  5. data/Rakefile +7 -7
  6. data/app/assets/javascripts/admin/assets.js +1 -1
  7. data/app/assets/javascripts/rad_social/rad_ajax_form.js +3 -0
  8. data/app/assets/javascripts/rad_social/rad_email.js +0 -1
  9. data/app/assets/javascripts/rad_social/rad_email_form.js +2 -7
  10. data/app/assets/stylesheets/admin/partials/_forms.scss +1 -1
  11. data/app/assets/stylesheets/rad_social/rad_screen.scss +0 -4
  12. data/app/controllers/admin/assets_controller.rb +21 -31
  13. data/app/controllers/admin/configuration_controller.rb +9 -11
  14. data/app/controllers/admin/extensions_controller.rb +3 -3
  15. data/app/controllers/admin/layouts_controller.rb +3 -4
  16. data/app/controllers/admin/page_attachments_controller.rb +5 -5
  17. data/app/controllers/admin/page_fields_controller.rb +3 -4
  18. data/app/controllers/admin/page_parts_controller.rb +4 -5
  19. data/app/controllers/admin/pages_controller.rb +55 -56
  20. data/app/controllers/admin/references_controller.rb +1 -1
  21. data/app/controllers/admin/resource_controller.rb +132 -130
  22. data/app/controllers/admin/sites_controller.rb +4 -4
  23. data/app/controllers/admin/snippets_controller.rb +3 -4
  24. data/app/controllers/admin/users_controller.rb +16 -16
  25. data/app/controllers/application_controller.rb +47 -48
  26. data/app/controllers/site_controller.rb +51 -48
  27. data/app/controllers/social_mailer_controller.rb +12 -22
  28. data/app/helpers/admin/configuration_helper.rb +19 -20
  29. data/app/helpers/admin/layouts_helper.rb +0 -1
  30. data/app/helpers/admin/node_helper.rb +27 -24
  31. data/app/helpers/admin/pages_helper.rb +2 -2
  32. data/app/helpers/admin/preferences_helper.rb +0 -1
  33. data/app/helpers/admin/references_helper.rb +9 -10
  34. data/app/helpers/admin/regions_helper.rb +3 -3
  35. data/app/helpers/application_helper.rb +32 -33
  36. data/app/helpers/rad_social_helper.rb +8 -11
  37. data/app/helpers/scoped_helper.rb +1 -3
  38. data/app/helpers/sites_helper.rb +4 -4
  39. data/app/mailers/devise_mailer.rb +3 -4
  40. data/app/mailers/rad_social_mailer.rb +8 -8
  41. data/app/models/asset.rb +62 -63
  42. data/app/models/asset_type.rb +38 -39
  43. data/app/models/deprecated_tags.rb +3 -4
  44. data/app/models/file_not_found_page.rb +1 -3
  45. data/app/models/haml_filter.rb +1 -1
  46. data/app/models/layout.rb +4 -5
  47. data/app/models/legacy_user.rb +2 -2
  48. data/app/models/menu_renderer.rb +16 -18
  49. data/app/models/page.rb +96 -93
  50. data/app/models/page_attachment.rb +1 -2
  51. data/app/models/page_context.rb +11 -12
  52. data/app/models/page_part.rb +3 -4
  53. data/app/models/rails_page.rb +10 -12
  54. data/app/models/site.rb +22 -21
  55. data/app/models/snippet.rb +6 -8
  56. data/app/models/snippet_finder.rb +3 -3
  57. data/app/models/snippet_tags.rb +4 -4
  58. data/app/models/standard_tags.rb +258 -252
  59. data/app/models/status.rb +8 -8
  60. data/app/models/trusty_cms/config.rb +25 -25
  61. data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
  62. data/app/models/user.rb +15 -14
  63. data/app/models/user_action_observer.rb +3 -3
  64. data/app/views/admin/assets/edit.html.haml +3 -9
  65. data/app/views/admin/assets/new.html.haml +0 -3
  66. data/app/views/admin/assets/remove.html.haml +1 -1
  67. data/app/views/admin/layouts/remove.html.haml +3 -2
  68. data/app/views/admin/page_parts/_page_part.html.haml +1 -1
  69. data/app/views/admin/snippets/remove.html.haml +3 -2
  70. data/app/views/rad_social_mailer/social_mail_form.html.haml +1 -3
  71. data/app/views/widget/_email_form.html.haml +0 -5
  72. data/bin/rails +4 -4
  73. data/bin/trusty_cms +3 -5
  74. data/config.ru +1 -1
  75. data/config/application.rb +14 -15
  76. data/config/boot.rb +1 -2
  77. data/config/environment.rb +1 -1
  78. data/config/environments/production.rb +0 -1
  79. data/config/environments/test.rb +1 -2
  80. data/config/initializers/devise.rb +1 -1
  81. data/config/initializers/kraken.rb +2 -2
  82. data/config/initializers/tmp.rb +1 -1
  83. data/config/initializers/trusty_cms_config.rb +48 -48
  84. data/config/locales/en.yml +5 -4
  85. data/config/routes.rb +6 -7
  86. data/lib/active_record_extensions/active_record_extensions.rb +1 -2
  87. data/lib/annotatable.rb +3 -5
  88. data/lib/configuration_extensions/configuration_extensions.rb +1 -1
  89. data/lib/inheritable_class_attributes.rb +13 -9
  90. data/lib/login_system.rb +73 -73
  91. data/lib/method_observer.rb +13 -12
  92. data/lib/ostruct.rb +7 -10
  93. data/lib/simpleton.rb +0 -4
  94. data/lib/string_extensions/string_extensions.rb +3 -3
  95. data/lib/symbol_extensions/symbol_extensions.rb +1 -1
  96. data/lib/tasks/database.rake +28 -28
  97. data/lib/tasks/extensions.rake +18 -18
  98. data/lib/tasks/framework.rake +68 -68
  99. data/lib/tasks/radiant_config.rake +4 -4
  100. data/lib/tasks/snippets_extension_tasks.rake +11 -11
  101. data/lib/tasks/translate.rake +14 -14
  102. data/lib/tasks/upgrade_to_devise.rake +1 -1
  103. data/lib/translation_support.rb +22 -22
  104. data/lib/trusty_cms.rb +2 -2
  105. data/lib/trusty_cms/admin_ui.rb +19 -16
  106. data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
  107. data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
  108. data/lib/trusty_cms/available_locales.rb +2 -4
  109. data/lib/trusty_cms/config/definition.rb +11 -8
  110. data/lib/trusty_cms/engine.rb +13 -14
  111. data/lib/trusty_cms/extension.rb +14 -16
  112. data/lib/trusty_cms/extension_loader.rb +6 -6
  113. data/lib/trusty_cms/extension_migrator.rb +42 -41
  114. data/lib/trusty_cms/extension_path.rb +20 -19
  115. data/lib/trusty_cms/initializer.rb +5 -8
  116. data/lib/trusty_cms/pagination/controller.rb +7 -10
  117. data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
  118. data/lib/trusty_cms/resource_responses.rb +3 -3
  119. data/lib/trusty_cms/setup.rb +130 -132
  120. data/lib/trusty_cms/taggable.rb +19 -22
  121. data/lib/trusty_cms/task_support.rb +9 -6
  122. data/package.json +1 -1
  123. data/public/dispatch.fcgi +1 -1
  124. data/public/dispatch.rb +2 -2
  125. data/script/extension +1 -1
  126. data/script/rails +2 -2
  127. data/spec/dummy/package.json +1 -1
  128. data/spec/dummy/yarn.lock +3 -3
  129. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/core.js +126 -0
  130. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/index.js +4 -0
  131. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/map.js +56 -0
  132. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/seq.js +43 -0
  133. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/failsafe/string.js +28 -0
  134. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/index.js +36 -0
  135. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/json.js +76 -0
  136. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/options.js +23 -0
  137. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/binary.js +87 -0
  138. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/index.js +157 -0
  139. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/omap.js +142 -0
  140. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/pairs.js +81 -0
  141. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/set.js +114 -0
  142. data/spec/spec/dummy/node_modules/yaml/browser/dist/tags/yaml-1.1/timestamp.js +97 -0
  143. data/spec/spec/dummy/node_modules/yaml/dist/tags/core.js +114 -0
  144. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/index.js +17 -0
  145. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/map.js +37 -0
  146. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/seq.js +34 -0
  147. data/spec/spec/dummy/node_modules/yaml/dist/tags/failsafe/string.js +40 -0
  148. data/spec/spec/dummy/node_modules/yaml/dist/tags/index.js +62 -0
  149. data/spec/spec/dummy/node_modules/yaml/dist/tags/json.js +60 -0
  150. data/spec/spec/dummy/node_modules/yaml/dist/tags/options.js +35 -0
  151. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/binary.js +97 -0
  152. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/index.js +131 -0
  153. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/omap.js +105 -0
  154. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/pairs.js +80 -0
  155. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/set.js +91 -0
  156. data/spec/spec/dummy/node_modules/yaml/dist/tags/yaml-1.1/timestamp.js +93 -0
  157. data/trusty_cms.gemspec +25 -25
  158. data/vendor/extensions/clipped-extension/lib/clipped_admin_ui.rb +1 -1
  159. data/yarn.lock +7 -7
  160. metadata +7609 -105
  161. data/app/assets/javascripts/rad_social/captcha.js +0 -42
  162. data/app/views/admin/assets/refresh.html.haml +0 -14
@@ -22,26 +22,26 @@ module ApplicationHelper
22
22
  end
23
23
 
24
24
  def onsubmit_status(model)
25
- model.new_record? ? t('creating_status', :model => t(model.class.name.downcase)) : "#{I18n.t('saving_changes')}…"
25
+ model.new_record? ? t('creating_status', model: t(model.class.name.downcase)) : "#{I18n.t('saving_changes')}…"
26
26
  end
27
27
 
28
28
  def save_model_button(model, options = {})
29
29
  model_name = model.class.name.underscore
30
30
  human_model_name = model_name.humanize.titlecase
31
31
  options[:label] ||= model.new_record? ?
32
- t('buttons.create', :name => t(model_name, :default => human_model_name), :default => 'Create ' + human_model_name) :
33
- t('buttons.save_changes', :default => 'Save Changes')
34
- options[:class] ||= "button"
32
+ t('buttons.create', name: t(model_name, default: human_model_name), default: 'Create ' + human_model_name) :
33
+ t('buttons.save_changes', default: 'Save Changes')
34
+ options[:class] ||= 'button'
35
35
  options[:accesskey] ||= 'S'
36
36
  submit_tag options.delete(:label), options
37
37
  end
38
38
 
39
- def save_model_and_continue_editing_button(model)
40
- submit_tag t('buttons.save_and_continue'), :name => 'continue', :class => 'button', :accesskey => "s"
39
+ def save_model_and_continue_editing_button(_model)
40
+ submit_tag t('buttons.save_and_continue'), name: 'continue', class: 'button', accesskey: 's'
41
41
  end
42
42
 
43
43
  def current_item?(item)
44
- if item.tab && item.tab.many? {|i| current_url?(i.relative_url) }
44
+ if item.tab&.many? { |i| current_url?(i.relative_url) }
45
45
  # Accept only stricter URL matches if more than one matches
46
46
  current_page?(item.url)
47
47
  else
@@ -50,7 +50,7 @@ module ApplicationHelper
50
50
  end
51
51
 
52
52
  def current_tab?(tab)
53
- @current_tab ||= tab if tab.any? {|item| current_url?(item.relative_url) }
53
+ @current_tab ||= tab if tab.any? { |item| current_url?(item.relative_url) }
54
54
  @current_tab == tab
55
55
  end
56
56
 
@@ -70,7 +70,7 @@ module ApplicationHelper
70
70
  end
71
71
 
72
72
  def admin?
73
- current_user and current_user.admin?
73
+ current_user&.admin?
74
74
  end
75
75
 
76
76
  def designer?
@@ -82,7 +82,7 @@ module ApplicationHelper
82
82
  updated_by = (model.updated_by || model.created_by)
83
83
  name = updated_by ? updated_by.name : nil
84
84
  time = (model.updated_at || model.created_at)
85
- if name or time
85
+ if name || time
86
86
  html = %{<div class="updated_line">#{t('timestamp.last_updated')} }
87
87
  html << %{#{t('timestamp.by')} <strong>#{name}</strong> } if name
88
88
  html << %{#{t('timestamp.at')} #{timestamp(time)}} if time
@@ -94,7 +94,7 @@ module ApplicationHelper
94
94
 
95
95
  def timestamp(time)
96
96
  # time.strftime("%I:%M %p on %B %e, %Y").sub("AM", 'am').sub("PM", 'pm')
97
- I18n.localize(time, :format => :timestamp)
97
+ I18n.localize(time, format: :timestamp)
98
98
  end
99
99
 
100
100
  def meta_errors?
@@ -122,11 +122,11 @@ module ApplicationHelper
122
122
  end
123
123
 
124
124
  def translate_with_default(name)
125
- t(name.underscore.downcase, :default => name)
125
+ t(name.underscore.downcase, default: name)
126
126
  end
127
127
 
128
128
  def available_locales_select
129
- [[t('select.default'),'']] + TrustyCms::AvailableLocales.locales
129
+ [[t('select.default'), '']] + TrustyCms::AvailableLocales.locales
130
130
  end
131
131
 
132
132
  def stylesheet_overrides
@@ -147,12 +147,12 @@ module ApplicationHelper
147
147
 
148
148
  # Returns a Gravatar URL associated with the email parameter.
149
149
  # See: http://douglasfshearer.com/blog/gravatar-for-ruby-and-ruby-on-rails
150
- def gravatar_url(email, options={})
150
+ def gravatar_url(email, options = {})
151
151
  # Default to highest rating. Rating can be one of G, PG, R X.
152
- options[:rating] ||= "G"
152
+ options[:rating] ||= 'G'
153
153
 
154
154
  # Default size of the image.
155
- options[:size] ||= "32px"
155
+ options[:size] ||= '32px'
156
156
 
157
157
  # Default image url to be used when no gravatar is found
158
158
  # or when an image exceeds the rating parameter.
@@ -160,7 +160,9 @@ module ApplicationHelper
160
160
  default_avatar_url = "#{request.protocol}#{request.host_with_port}#{ActionController::Base.relative_url_root}#{local_avatar_url}"
161
161
  options[:default] ||= default_avatar_url
162
162
 
163
- unless email.blank?
163
+ if email.blank?
164
+ local_avatar_url
165
+ else
164
166
  # Build the Gravatar url.
165
167
  url = '//gravatar.com/avatar/'
166
168
  url << "#{Digest::MD5.new.update(email)}?"
@@ -169,31 +171,29 @@ module ApplicationHelper
169
171
  url << "&default=#{options[:default]}" if options[:default]
170
172
  # Test the Gravatar url
171
173
  require 'open-uri'
172
- begin; open "http:#{url}", :proxy => true
173
- rescue; local_avatar_url
174
+ begin; open "http:#{url}", proxy: true
175
+ rescue StandardError; local_avatar_url
174
176
  else; url
175
177
  end
176
- else
177
- local_avatar_url
178
178
  end
179
179
  end
180
180
 
181
181
  # returns the usual set of pagination links.
182
182
  # options are passed through to will_paginate
183
183
  # and a 'show all' depagination link is added if relevant.
184
- def pagination_for(list, options={})
184
+ def pagination_for(list, options = {})
185
185
  if list.respond_to? :total_pages
186
186
  options = {
187
- :max_per_page => @trusty_config['pagination.max_per_page'] || 500,
188
- :depaginate => true
187
+ max_per_page: @trusty_config['pagination.max_per_page'] || 500,
188
+ depaginate: true,
189
189
  }.merge(options.symbolize_keys)
190
190
  depaginate = options.delete(:depaginate) # supply :depaginate => false to omit the 'show all' link
191
191
  depagination_limit = options.delete(:max_per_page) # supply :max_per_page => false to include the 'show all' link no matter how large the collection
192
192
  html = will_paginate(list, will_paginate_options.merge(options))
193
193
  if depaginate && list.total_pages > 1 && (!depagination_limit.blank? || list.total_entries <= depagination_limit.to_i)
194
- html << content_tag(:div, link_to(t('show_all'), :pp => 'all'), :class => 'depaginate')
194
+ html << content_tag(:div, link_to(t('show_all'), pp: 'all'), class: 'depaginate')
195
195
  elsif depaginate && list.total_entries > depagination_limit.to_i
196
- html = content_tag(:div, link_to("paginate", :p => 1), :class => 'pagination')
196
+ html = content_tag(:div, link_to('paginate', p: 1), class: 'pagination')
197
197
  end
198
198
  html
199
199
  end
@@ -201,12 +201,11 @@ module ApplicationHelper
201
201
 
202
202
  private
203
203
 
204
- def append_image_extension(name)
205
- unless name =~ /\.(.*?)$/
206
- name + '.png'
207
- else
208
- name
204
+ def append_image_extension(name)
205
+ if name =~ /\.(.*?)$/
206
+ name
207
+ else
208
+ name + '.png'
209
209
  end
210
- end
211
-
210
+ end
212
211
  end
@@ -1,7 +1,6 @@
1
1
  module RadSocialHelper
2
-
3
2
  def rad_test_method
4
- "SURPRISE SURPRISE SURPRISE"
3
+ 'SURPRISE SURPRISE SURPRISE'
5
4
  end
6
5
 
7
6
  def rad_share_widget(options)
@@ -9,15 +8,13 @@ module RadSocialHelper
9
8
  message = options[:message].nil? ? "Check out #{options[:title]}." : options[:message]
10
9
  email_subject = options[:email_subject].nil? ? options[:title] : options[:email_subject]
11
10
  email_message = options[:email_message].nil? ? "I thought you might be interested in this: #{url}" : "#{options[:email_message]} #{url}"
12
- email_action_url = options[:email_action_url].nil? ? "/rad_social/mail" : options[:email_action_url]
11
+ email_action_url = options[:email_action_url].nil? ? '/rad_social/mail' : options[:email_action_url]
13
12
 
14
- render :partial => "widget/horizontal_widget",
15
- :locals => { :url => url,
16
- :message => message,
17
- :email_subject => email_subject,
18
- :email_message => email_message,
19
- :email_action_url => email_action_url
20
- }
13
+ render partial: 'widget/horizontal_widget',
14
+ locals: { url: url,
15
+ message: message,
16
+ email_subject: email_subject,
17
+ email_message: email_message,
18
+ email_action_url: email_action_url }
21
19
  end
22
-
23
20
  end
@@ -1,9 +1,8 @@
1
1
  module ScopedHelper
2
2
  def self.included(base)
3
-
4
3
  base.module_eval do
5
4
  def title
6
- t = current_site.name
5
+ t = current_site.name
7
6
  t = TrustyCms::Config['admin.title'] || 'TrustyCMS' if t.blank?
8
7
  t
9
8
  end
@@ -13,7 +12,6 @@ module ScopedHelper
13
12
  st = TrustyCms::Config['admin.subtitle'] || 'publishing for small teams' if st.blank?
14
13
  st
15
14
  end
16
-
17
15
  end
18
16
  end
19
17
  end
@@ -1,10 +1,10 @@
1
1
  module SitesHelper
2
2
  def order_links(site)
3
3
  String.new.tap do |output|
4
- output << link_to(image("move_to_top.png", :alt => "Move to top"), move_to_top_admin_site_path(site), :method => :put)
5
- output << link_to(image("move_higher.png", :alt => "Move up"), move_higher_admin_site_path(site), :method => :post)
6
- output << link_to(image("move_lower.png", :alt => "Move down"), move_lower_admin_site_path(site), :method => :post)
7
- output << link_to(image("move_to_bottom.png", :alt => "Move to bottom"), move_to_bottom_admin_site_path(site), :method => :put)
4
+ output << link_to(image('move_to_top.png', alt: 'Move to top'), move_to_top_admin_site_path(site), method: :put)
5
+ output << link_to(image('move_higher.png', alt: 'Move up'), move_higher_admin_site_path(site), method: :post)
6
+ output << link_to(image('move_lower.png', alt: 'Move down'), move_lower_admin_site_path(site), method: :post)
7
+ output << link_to(image('move_to_bottom.png', alt: 'Move to bottom'), move_to_bottom_admin_site_path(site), method: :put)
8
8
  end
9
9
  end
10
10
  end
@@ -1,8 +1,7 @@
1
1
  class DeviseMailer < Devise::Mailer
2
-
3
- def reset_password_instructions(record, token, opts={})
2
+ def reset_password_instructions(record, token, opts = {})
4
3
  mail = super
5
- mail.subject = "Reset Password for TrustyCMS"
4
+ mail.subject = 'Reset Password for TrustyCMS'
6
5
  mail
7
- end
6
+ end
8
7
  end
@@ -3,7 +3,7 @@ require 'roadie-rails'
3
3
  class RadSocialMailer < ApplicationMailer
4
4
  include Roadie::Rails::Automatic
5
5
 
6
- def social_mail options
6
+ def social_mail(options)
7
7
  from_address = Mail::Address.new options[:from] # ex: "john@example.com"
8
8
  from_address.display_name = options[:from_name] # ex: "John Doe"
9
9
 
@@ -14,12 +14,12 @@ class RadSocialMailer < ApplicationMailer
14
14
  @actual_from = from_address if @actual_from.nil?
15
15
 
16
16
  mail({
17
- to: options[:to],
18
- from: @actual_from,
19
- reply_to: @from_email,
20
- subject: options[:subject],
21
- text: @message,
22
- content_type: "text/html"
23
- })
17
+ to: options[:to],
18
+ from: @actual_from,
19
+ reply_to: @from_email,
20
+ subject: options[:subject],
21
+ text: @message,
22
+ content_type: 'text/html',
23
+ })
24
24
  end
25
25
  end
@@ -1,17 +1,17 @@
1
1
  class Asset < ActiveRecord::Base
2
2
  include Paperclip::Glue
3
3
 
4
- has_many :page_attachments, :dependent => :destroy
5
- has_many :pages, :through => :page_attachments
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, :class_name => 'User'
9
- belongs_to :updated_by, :class_name => 'User'
8
+ belongs_to :created_by, class_name: 'User'
9
+ belongs_to :updated_by, class_name: 'User'
10
10
 
11
- default_scope {order("created_at DESC")}
11
+ default_scope { order('created_at DESC') }
12
12
 
13
13
  scope :latest, lambda { |limit|
14
- order("created_at DESC").limit(limit)
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(["LOWER(assets.asset_file_name) LIKE (:term) OR LOWER(title) LIKE (:term) OR LOWER(caption) LIKE (:term)", {:term => "%#{term.downcase}%" }])
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
- :styles => lambda { |attachment|
37
+ styles: lambda { |attachment|
38
38
  AssetType.for(attachment).paperclip_styles
39
39
  },
40
- :processors => lambda { |asset|
40
+ processors: lambda { |asset|
41
41
  asset.paperclip_processors
42
42
  },
43
- :whiny => false,
44
- :storage => TrustyCms.config["paperclip.storage"],
45
- :path => TrustyCms.config["paperclip.path"],
46
- :url => TrustyCms.config["paperclip.url"],
47
- :fog_credentials =>
48
- TrustyCmsClippedExtension::Cloud.credentials,
49
- :fog_directory => TrustyCms.config["paperclip.fog.directory"],
50
- :fog_public => TrustyCms.config["paperclip.fog.public?"] || true,
51
- :fog_host => TrustyCmsClippedExtension::Cloud.host,
52
- :fog_file => {
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, :content_type => ["application/zip", "image/jpg", "image/jpeg", "image/png", "image/gif", "application/pdf", "application/javascript", "text/javascript", "text/css"]
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, :message => "You must choose a file to upload!"
64
- if TrustyCms.config["paperclip.skip_filetype_validation"] != "true" && TrustyCms.config['paperclip.content_types']
65
- validates_attachment_content_type :asset, :content_type => TrustyCms.config["paperclip.content_types"].gsub(' ','').split(',')
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, :message => "Your uploaded file must have an extension in its name!"
66
+ validates_attachment_presence :asset, message: 'Your uploaded file must have an extension in its name!'
68
67
  end
69
- validates_attachment_size :asset, :less_than => ( TrustyCms.config["assets.max_asset_size"] || 5 ).to_i.megabytes
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, :to => :asset_type
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
- return asset_type.icon(style_name)
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, ".*") if 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
- if style_name == 'original'
92
- return original_extension
93
- elsif style = paperclip_styles[style_name.to_sym]
94
- return style.format
95
- else
96
- return original_extension
97
- end
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
- original_geometry
118
- else
119
- style = self.asset.styles[style_name.to_sym]
120
- 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
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 # returns a blank geometry if the real geometry cannot be calculated
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
- case
135
- when a == nil?
135
+ if a == nil?
136
136
  'unknown'
137
- when a < 1.0
137
+ elsif a < 1.0
138
138
  'vertical'
139
- when a > 1.0
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 = self.asset_file_name.downcase.sub(self.original_extension, "").sub(".", "")
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(:conditions => ["#{w_asset_types} = ?", block]))
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{|k,v|
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
- }.sort_by{|pair| pair.last.to_s}
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