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.
Files changed (217) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +106 -106
  4. data/Rakefile +7 -7
  5. data/app/assets/images/admin/spinner.gif +0 -0
  6. data/app/assets/javascripts/admin.js +3 -0
  7. data/app/assets/javascripts/admin/more-or-less.js +2 -2
  8. data/app/assets/javascripts/admin/tabcontrol.js.erb +1 -2
  9. data/app/assets/stylesheets/admin/_base.scss +22 -6
  10. data/app/assets/stylesheets/admin/_multi_site_main.scss +28 -29
  11. data/app/assets/stylesheets/admin/_reset.scss +5 -4
  12. data/app/assets/stylesheets/admin/_site_chooser.scss +44 -69
  13. data/app/assets/stylesheets/admin/assets.scss +138 -141
  14. data/app/assets/stylesheets/admin/main.scss +10 -12
  15. data/app/assets/stylesheets/admin/modules/_boxes.scss +0 -3
  16. data/app/assets/stylesheets/admin/modules/_buttons.scss +30 -0
  17. data/app/assets/stylesheets/admin/modules/_links.scss +1 -1
  18. data/app/assets/stylesheets/admin/partials/_actions.scss +29 -46
  19. data/app/assets/stylesheets/admin/partials/_avatars.scss +3 -2
  20. data/app/assets/stylesheets/admin/partials/_content.scss +15 -38
  21. data/app/assets/stylesheets/admin/partials/_dateinput.scss +23 -14
  22. data/app/assets/stylesheets/admin/partials/_drawer.scss +78 -0
  23. data/app/assets/stylesheets/admin/partials/_dropdown.scss +9 -12
  24. data/app/assets/stylesheets/admin/partials/_footer.scss +4 -3
  25. data/app/assets/stylesheets/admin/partials/_forms.scss +64 -491
  26. data/app/assets/stylesheets/admin/partials/_header.scss +9 -118
  27. data/app/assets/stylesheets/admin/partials/_layout.scss +26 -2
  28. data/app/assets/stylesheets/admin/partials/_login_form.scss +28 -0
  29. data/app/assets/stylesheets/admin/partials/_messages.scss +10 -5
  30. data/app/assets/stylesheets/admin/partials/_popup.scss +61 -50
  31. data/app/assets/stylesheets/admin/partials/_preferences.scss +37 -0
  32. data/app/assets/stylesheets/admin/partials/_sidebar.scss +55 -0
  33. data/app/assets/stylesheets/admin/partials/_tabcontrol.scss +24 -36
  34. data/app/assets/stylesheets/admin/partials/{_index.scss → _table.scss} +53 -84
  35. data/app/assets/stylesheets/admin/partials/_toolbar.scss +11 -6
  36. data/app/assets/stylesheets/admin/partials/_treetable.scss +1 -71
  37. data/app/assets/stylesheets/admin/partials/_typography.scss +30 -55
  38. data/app/assets/stylesheets/admin/partials/_validations.scss +6 -5
  39. data/app/assets/stylesheets/rad_social/rad_screen.scss +65 -64
  40. data/app/controllers/admin/assets_controller.rb +21 -31
  41. data/app/controllers/admin/configuration_controller.rb +9 -11
  42. data/app/controllers/admin/extensions_controller.rb +3 -3
  43. data/app/controllers/admin/layouts_controller.rb +3 -4
  44. data/app/controllers/admin/page_attachments_controller.rb +5 -5
  45. data/app/controllers/admin/page_fields_controller.rb +3 -4
  46. data/app/controllers/admin/page_parts_controller.rb +4 -5
  47. data/app/controllers/admin/pages_controller.rb +55 -56
  48. data/app/controllers/admin/references_controller.rb +1 -1
  49. data/app/controllers/admin/resource_controller.rb +132 -128
  50. data/app/controllers/admin/sites_controller.rb +4 -4
  51. data/app/controllers/admin/snippets_controller.rb +3 -4
  52. data/app/controllers/admin/users_controller.rb +16 -16
  53. data/app/controllers/application_controller.rb +47 -48
  54. data/app/controllers/site_controller.rb +51 -48
  55. data/app/controllers/social_mailer_controller.rb +13 -16
  56. data/app/helpers/admin/configuration_helper.rb +19 -20
  57. data/app/helpers/admin/layouts_helper.rb +0 -1
  58. data/app/helpers/admin/node_helper.rb +27 -24
  59. data/app/helpers/admin/pages_helper.rb +2 -2
  60. data/app/helpers/admin/preferences_helper.rb +0 -1
  61. data/app/helpers/admin/references_helper.rb +9 -10
  62. data/app/helpers/admin/regions_helper.rb +3 -3
  63. data/app/helpers/application_helper.rb +34 -35
  64. data/app/helpers/rad_social_helper.rb +8 -11
  65. data/app/helpers/scoped_helper.rb +1 -3
  66. data/app/helpers/sites_helper.rb +4 -4
  67. data/app/mailers/devise_mailer.rb +3 -4
  68. data/app/mailers/rad_social_mailer.rb +8 -8
  69. data/app/models/asset.rb +62 -63
  70. data/app/models/asset_type.rb +38 -39
  71. data/app/models/deprecated_tags.rb +3 -4
  72. data/app/models/file_not_found_page.rb +1 -3
  73. data/app/models/haml_filter.rb +1 -1
  74. data/app/models/layout.rb +4 -5
  75. data/app/models/legacy_user.rb +2 -2
  76. data/app/models/menu_renderer.rb +16 -18
  77. data/app/models/page.rb +96 -93
  78. data/app/models/page_attachment.rb +1 -2
  79. data/app/models/page_context.rb +11 -12
  80. data/app/models/page_part.rb +3 -4
  81. data/app/models/rails_page.rb +10 -12
  82. data/app/models/site.rb +22 -21
  83. data/app/models/snippet.rb +6 -8
  84. data/app/models/snippet_finder.rb +3 -3
  85. data/app/models/snippet_tags.rb +4 -4
  86. data/app/models/standard_tags.rb +258 -252
  87. data/app/models/status.rb +8 -8
  88. data/app/models/trusty_cms/config.rb +25 -25
  89. data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
  90. data/app/models/user.rb +15 -14
  91. data/app/models/user_action_observer.rb +3 -3
  92. data/app/users/_choose_site.html.haml +3 -7
  93. data/app/views/admin/assets/_form.html.haml +2 -1
  94. data/app/views/admin/assets/_search.html.haml +2 -1
  95. data/app/views/admin/assets/edit.html.haml +2 -10
  96. data/app/views/admin/assets/index.html.haml +4 -2
  97. data/app/views/admin/assets/new.html.haml +4 -8
  98. data/app/views/admin/assets/remove.html.haml +2 -1
  99. data/app/views/admin/configuration/edit.html.haml +7 -7
  100. data/app/views/admin/configuration/show.html.haml +6 -8
  101. data/app/views/admin/layouts/_choose_site.html.haml +2 -3
  102. data/app/views/admin/layouts/_form.html.haml +13 -12
  103. data/app/views/admin/layouts/_site_chooser.html.haml +2 -2
  104. data/app/views/admin/layouts/index.html.haml +11 -4
  105. data/app/views/admin/layouts/remove.html.haml +6 -5
  106. data/app/views/admin/page_attachments/_attachment.html.haml +2 -2
  107. data/app/views/admin/page_fields/_page_field.html.haml +3 -3
  108. data/app/views/admin/page_parts/_page_part.html.haml +5 -6
  109. data/app/views/admin/pages/_asset_popups.html.haml +15 -16
  110. data/app/views/admin/pages/_assets.html.haml +8 -7
  111. data/app/views/admin/pages/_fields.html.haml +16 -13
  112. data/app/views/admin/pages/_node.html.haml +3 -3
  113. data/app/views/admin/pages/_popups.html.haml +11 -11
  114. data/app/views/admin/pages/edit.html.haml +2 -2
  115. data/app/views/admin/pages/index.html.haml +5 -2
  116. data/app/views/admin/pages/new.html.haml +3 -3
  117. data/app/views/admin/pages/remove.html.haml +4 -3
  118. data/app/views/admin/preferences/edit.html.haml +5 -5
  119. data/app/views/admin/references/filters.haml +1 -1
  120. data/app/views/admin/references/tags.haml +3 -3
  121. data/app/views/admin/removed/_assets_bucket.html.haml +3 -3
  122. data/app/views/admin/removed/_assets_container.html.haml +18 -18
  123. data/app/views/admin/removed/_bucket.html.haml +1 -1
  124. data/app/views/admin/removed/_bucket_asset.html.haml +3 -3
  125. data/app/views/admin/removed/_show_bucket_link.html.haml +1 -1
  126. data/app/views/admin/removed/_upload_to_page.html.haml +5 -5
  127. data/app/views/admin/sites/_form.haml +18 -18
  128. data/app/views/admin/sites/edit.haml +1 -1
  129. data/app/views/admin/sites/index.haml +8 -4
  130. data/app/views/admin/sites/new.haml +1 -1
  131. data/app/views/admin/snippets/_choose_site.html.haml +4 -5
  132. data/app/views/admin/snippets/_form.html.haml +8 -9
  133. data/app/views/admin/snippets/edit.html.haml +1 -1
  134. data/app/views/admin/snippets/index.html.haml +11 -4
  135. data/app/views/admin/snippets/new.html.haml +1 -1
  136. data/app/views/admin/snippets/remove.html.haml +7 -6
  137. data/app/views/admin/users/_avatar.html.haml +2 -2
  138. data/app/views/admin/users/_choose_site.html.haml +3 -7
  139. data/app/views/admin/users/_form.html.haml +18 -21
  140. data/app/views/admin/users/_password_fields.html.haml +6 -6
  141. data/app/views/admin/users/index.html.haml +13 -6
  142. data/app/views/admin/users/remove.html.haml +4 -4
  143. data/app/views/admin/welcome/login.html.haml +8 -8
  144. data/app/views/devise/passwords/edit.html.haml +6 -6
  145. data/app/views/devise/passwords/new.html.haml +3 -3
  146. data/app/views/devise/sessions/new.html.haml +8 -8
  147. data/app/views/devise/shared/_links.html.haml +2 -2
  148. data/app/views/layouts/application.html.haml +24 -19
  149. data/app/views/rad_social_mailer/social_mail_form.html.haml +15 -15
  150. data/app/views/widget/_email_form.html.haml +14 -14
  151. data/app/views/widget/_horizontal_widget.html.haml +5 -5
  152. data/bin/rails +4 -4
  153. data/bin/trusty_cms +3 -5
  154. data/config.ru +1 -1
  155. data/config/application.rb +14 -15
  156. data/config/boot.rb +1 -2
  157. data/config/environment.rb +1 -1
  158. data/config/environments/production.rb +0 -1
  159. data/config/environments/test.rb +1 -2
  160. data/config/initializers/devise.rb +1 -1
  161. data/config/initializers/kraken.rb +2 -2
  162. data/config/initializers/tmp.rb +1 -1
  163. data/config/initializers/trusty_cms_config.rb +48 -48
  164. data/config/locales/en.yml +8 -8
  165. data/config/routes.rb +6 -7
  166. data/lib/active_record_extensions/active_record_extensions.rb +1 -2
  167. data/lib/annotatable.rb +3 -5
  168. data/lib/configuration_extensions/configuration_extensions.rb +1 -1
  169. data/lib/inheritable_class_attributes.rb +13 -9
  170. data/lib/login_system.rb +73 -73
  171. data/lib/method_observer.rb +13 -12
  172. data/lib/ostruct.rb +7 -10
  173. data/lib/simpleton.rb +0 -4
  174. data/lib/string_extensions/string_extensions.rb +3 -3
  175. data/lib/symbol_extensions/symbol_extensions.rb +1 -1
  176. data/lib/tasks/database.rake +28 -28
  177. data/lib/tasks/extensions.rake +18 -18
  178. data/lib/tasks/framework.rake +68 -68
  179. data/lib/tasks/radiant_config.rake +4 -4
  180. data/lib/tasks/snippets_extension_tasks.rake +11 -11
  181. data/lib/tasks/translate.rake +14 -14
  182. data/lib/tasks/upgrade_to_devise.rake +1 -1
  183. data/lib/translation_support.rb +22 -22
  184. data/lib/trusty_cms.rb +2 -2
  185. data/lib/trusty_cms/admin_ui.rb +19 -16
  186. data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
  187. data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
  188. data/lib/trusty_cms/available_locales.rb +2 -4
  189. data/lib/trusty_cms/config/definition.rb +11 -8
  190. data/lib/trusty_cms/engine.rb +14 -14
  191. data/lib/trusty_cms/extension.rb +14 -16
  192. data/lib/trusty_cms/extension_loader.rb +6 -6
  193. data/lib/trusty_cms/extension_migrator.rb +42 -41
  194. data/lib/trusty_cms/extension_path.rb +20 -19
  195. data/lib/trusty_cms/initializer.rb +5 -8
  196. data/lib/trusty_cms/pagination/controller.rb +7 -10
  197. data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
  198. data/lib/trusty_cms/resource_responses.rb +3 -3
  199. data/lib/trusty_cms/setup.rb +130 -132
  200. data/lib/trusty_cms/taggable.rb +19 -22
  201. data/lib/trusty_cms/task_support.rb +9 -6
  202. data/package.json +10 -2
  203. data/public/dispatch.fcgi +1 -1
  204. data/public/dispatch.rb +2 -2
  205. data/script/extension +1 -1
  206. data/script/rails +2 -2
  207. data/spec/dummy/package.json +1 -1
  208. data/spec/dummy/yarn.lock +3 -3
  209. data/trusty_cms.gemspec +25 -25
  210. data/vendor/extensions/clipped-extension/lib/clipped_admin_ui.rb +1 -1
  211. data/yarn.lock +1992 -4
  212. metadata +54 -42
  213. data/app/assets/stylesheets/admin/partials/_deprecated.scss +0 -65
  214. data/app/assets/stylesheets/admin/partials/_jquery-ui-structure.scss +0 -258
  215. data/app/assets/stylesheets/admin/partials/_jquery-ui-theme.scss +0 -410
  216. data/app/assets/stylesheets/admin/partials/_jquery-ui.scss +0 -650
  217. data/app/views/admin/assets/refresh.html.haml +0 -14
@@ -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
@@ -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(:conditions => condition)}
38
- Asset.send :scope, "not_#{plural}".to_sym, -> {where(:conditions => non_condition)}
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
- self.define_radius_tags
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.to_s}.png")
51
- return "/assets/admin/#{icon_name}_#{style_name.to_s}.png"
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
- return "/assets/admin/#{icon_name}_icon.png"
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
- normalize_style_rules(configured_styles.merge(styles))
102
- else
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('=') } # array of pairs
115
- rule = Hash[parameters].symbolize_keys # into hash of :first => last
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 = {:geometry => rule} # simplest case: name:geom|name:geom
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
- :thumbnail => { :geometry => '100x100#', :format => :png }
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
- style_definitions.split('|').each_with_object({}) do |definition, styles|
144
- name, rule = definition.split(':')
145
- styles[name.strip.to_sym] = rule.to_s.strip
146
- end
147
- else
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["assets.additional_thumbnails"].to_s.gsub(' ','').split(',').collect{|s| s.split('=')}.inject({}) {|ha, (k, v)| ha[k.to_sym] = v; ha}
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 = self.name
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 ||= self.find(:other)
189
+ @@default_type ||= find(:other)
191
190
  end
192
191
 
193
192
  def self.known?(name)
194
- !self.find(name).nil?
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 # Hash#slice is provided by will_paginate
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| self.find(name).sanitized_condition }.join(' OR ')
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