trusty-cms 4.0.2 → 4.1.4

Sign up to get free protection for your applications and to get access to all the features.
Files changed (221) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +3 -3
  3. data/Gemfile.lock +89 -89
  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/javascripts/rad_social/rad_ajax_form.js +3 -0
  10. data/app/assets/javascripts/rad_social/rad_email.js +0 -1
  11. data/app/assets/javascripts/rad_social/rad_email_form.js +2 -7
  12. data/app/assets/stylesheets/admin/_base.scss +22 -6
  13. data/app/assets/stylesheets/admin/_multi_site_main.scss +28 -29
  14. data/app/assets/stylesheets/admin/_reset.scss +5 -4
  15. data/app/assets/stylesheets/admin/_site_chooser.scss +44 -69
  16. data/app/assets/stylesheets/admin/assets.scss +138 -141
  17. data/app/assets/stylesheets/admin/main.scss +10 -12
  18. data/app/assets/stylesheets/admin/modules/_boxes.scss +0 -3
  19. data/app/assets/stylesheets/admin/modules/_buttons.scss +30 -0
  20. data/app/assets/stylesheets/admin/modules/_links.scss +1 -1
  21. data/app/assets/stylesheets/admin/partials/_actions.scss +29 -46
  22. data/app/assets/stylesheets/admin/partials/_avatars.scss +3 -2
  23. data/app/assets/stylesheets/admin/partials/_content.scss +15 -38
  24. data/app/assets/stylesheets/admin/partials/_dateinput.scss +23 -14
  25. data/app/assets/stylesheets/admin/partials/_drawer.scss +78 -0
  26. data/app/assets/stylesheets/admin/partials/_dropdown.scss +9 -12
  27. data/app/assets/stylesheets/admin/partials/_footer.scss +4 -3
  28. data/app/assets/stylesheets/admin/partials/_forms.scss +64 -493
  29. data/app/assets/stylesheets/admin/partials/_header.scss +9 -118
  30. data/app/assets/stylesheets/admin/partials/_layout.scss +26 -2
  31. data/app/assets/stylesheets/admin/partials/_login_form.scss +28 -0
  32. data/app/assets/stylesheets/admin/partials/_messages.scss +10 -5
  33. data/app/assets/stylesheets/admin/partials/_popup.scss +61 -50
  34. data/app/assets/stylesheets/admin/partials/_preferences.scss +37 -0
  35. data/app/assets/stylesheets/admin/partials/_sidebar.scss +55 -0
  36. data/app/assets/stylesheets/admin/partials/_tabcontrol.scss +24 -36
  37. data/app/assets/stylesheets/admin/partials/{_index.scss → _table.scss} +53 -84
  38. data/app/assets/stylesheets/admin/partials/_toolbar.scss +11 -6
  39. data/app/assets/stylesheets/admin/partials/_treetable.scss +1 -71
  40. data/app/assets/stylesheets/admin/partials/_typography.scss +30 -55
  41. data/app/assets/stylesheets/admin/partials/_validations.scss +6 -5
  42. data/app/assets/stylesheets/rad_social/rad_screen.scss +64 -67
  43. data/app/controllers/admin/assets_controller.rb +21 -31
  44. data/app/controllers/admin/configuration_controller.rb +9 -11
  45. data/app/controllers/admin/extensions_controller.rb +3 -3
  46. data/app/controllers/admin/layouts_controller.rb +3 -4
  47. data/app/controllers/admin/page_attachments_controller.rb +5 -5
  48. data/app/controllers/admin/page_fields_controller.rb +3 -4
  49. data/app/controllers/admin/page_parts_controller.rb +4 -5
  50. data/app/controllers/admin/pages_controller.rb +55 -56
  51. data/app/controllers/admin/references_controller.rb +1 -1
  52. data/app/controllers/admin/resource_controller.rb +132 -130
  53. data/app/controllers/admin/sites_controller.rb +4 -4
  54. data/app/controllers/admin/snippets_controller.rb +3 -4
  55. data/app/controllers/admin/users_controller.rb +16 -16
  56. data/app/controllers/application_controller.rb +47 -48
  57. data/app/controllers/site_controller.rb +51 -48
  58. data/app/controllers/social_mailer_controller.rb +12 -22
  59. data/app/helpers/admin/configuration_helper.rb +19 -20
  60. data/app/helpers/admin/layouts_helper.rb +0 -1
  61. data/app/helpers/admin/node_helper.rb +27 -24
  62. data/app/helpers/admin/pages_helper.rb +2 -2
  63. data/app/helpers/admin/preferences_helper.rb +0 -1
  64. data/app/helpers/admin/references_helper.rb +9 -10
  65. data/app/helpers/admin/regions_helper.rb +3 -3
  66. data/app/helpers/application_helper.rb +34 -35
  67. data/app/helpers/rad_social_helper.rb +8 -11
  68. data/app/helpers/scoped_helper.rb +1 -3
  69. data/app/helpers/sites_helper.rb +4 -4
  70. data/app/mailers/devise_mailer.rb +3 -4
  71. data/app/mailers/rad_social_mailer.rb +8 -8
  72. data/app/models/asset.rb +62 -63
  73. data/app/models/asset_type.rb +38 -39
  74. data/app/models/deprecated_tags.rb +3 -4
  75. data/app/models/file_not_found_page.rb +1 -3
  76. data/app/models/haml_filter.rb +1 -1
  77. data/app/models/layout.rb +4 -5
  78. data/app/models/legacy_user.rb +2 -2
  79. data/app/models/menu_renderer.rb +16 -18
  80. data/app/models/page.rb +96 -93
  81. data/app/models/page_attachment.rb +1 -2
  82. data/app/models/page_context.rb +11 -12
  83. data/app/models/page_part.rb +3 -4
  84. data/app/models/rails_page.rb +10 -12
  85. data/app/models/site.rb +22 -21
  86. data/app/models/snippet.rb +6 -8
  87. data/app/models/snippet_finder.rb +3 -3
  88. data/app/models/snippet_tags.rb +4 -4
  89. data/app/models/standard_tags.rb +258 -252
  90. data/app/models/status.rb +8 -8
  91. data/app/models/trusty_cms/config.rb +25 -25
  92. data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
  93. data/app/models/user.rb +15 -14
  94. data/app/models/user_action_observer.rb +3 -3
  95. data/app/users/_choose_site.html.haml +3 -7
  96. data/app/views/admin/assets/_form.html.haml +2 -1
  97. data/app/views/admin/assets/_search.html.haml +2 -1
  98. data/app/views/admin/assets/edit.html.haml +2 -10
  99. data/app/views/admin/assets/index.html.haml +4 -2
  100. data/app/views/admin/assets/new.html.haml +4 -8
  101. data/app/views/admin/assets/remove.html.haml +2 -1
  102. data/app/views/admin/configuration/edit.html.haml +7 -7
  103. data/app/views/admin/configuration/show.html.haml +6 -8
  104. data/app/views/admin/layouts/_choose_site.html.haml +2 -3
  105. data/app/views/admin/layouts/_form.html.haml +13 -12
  106. data/app/views/admin/layouts/_site_chooser.html.haml +2 -2
  107. data/app/views/admin/layouts/index.html.haml +11 -4
  108. data/app/views/admin/layouts/remove.html.haml +6 -5
  109. data/app/views/admin/page_attachments/_attachment.html.haml +2 -2
  110. data/app/views/admin/page_fields/_page_field.html.haml +3 -3
  111. data/app/views/admin/page_parts/_page_part.html.haml +5 -6
  112. data/app/views/admin/pages/_asset_popups.html.haml +15 -16
  113. data/app/views/admin/pages/_assets.html.haml +8 -7
  114. data/app/views/admin/pages/_fields.html.haml +16 -13
  115. data/app/views/admin/pages/_node.html.haml +3 -3
  116. data/app/views/admin/pages/_popups.html.haml +11 -11
  117. data/app/views/admin/pages/edit.html.haml +2 -2
  118. data/app/views/admin/pages/index.html.haml +5 -2
  119. data/app/views/admin/pages/new.html.haml +3 -3
  120. data/app/views/admin/pages/remove.html.haml +4 -3
  121. data/app/views/admin/preferences/edit.html.haml +5 -5
  122. data/app/views/admin/references/filters.haml +1 -1
  123. data/app/views/admin/references/tags.haml +3 -3
  124. data/app/views/admin/removed/_assets_bucket.html.haml +3 -3
  125. data/app/views/admin/removed/_assets_container.html.haml +18 -18
  126. data/app/views/admin/removed/_bucket.html.haml +1 -1
  127. data/app/views/admin/removed/_bucket_asset.html.haml +3 -3
  128. data/app/views/admin/removed/_show_bucket_link.html.haml +1 -1
  129. data/app/views/admin/removed/_upload_to_page.html.haml +5 -5
  130. data/app/views/admin/sites/_form.haml +18 -18
  131. data/app/views/admin/sites/edit.haml +1 -1
  132. data/app/views/admin/sites/index.haml +8 -4
  133. data/app/views/admin/sites/new.haml +1 -1
  134. data/app/views/admin/snippets/_choose_site.html.haml +4 -5
  135. data/app/views/admin/snippets/_form.html.haml +8 -9
  136. data/app/views/admin/snippets/edit.html.haml +1 -1
  137. data/app/views/admin/snippets/index.html.haml +11 -4
  138. data/app/views/admin/snippets/new.html.haml +1 -1
  139. data/app/views/admin/snippets/remove.html.haml +7 -6
  140. data/app/views/admin/users/_avatar.html.haml +2 -2
  141. data/app/views/admin/users/_choose_site.html.haml +3 -7
  142. data/app/views/admin/users/_form.html.haml +18 -21
  143. data/app/views/admin/users/_password_fields.html.haml +6 -6
  144. data/app/views/admin/users/index.html.haml +13 -6
  145. data/app/views/admin/users/remove.html.haml +4 -4
  146. data/app/views/admin/welcome/login.html.haml +8 -8
  147. data/app/views/devise/passwords/edit.html.haml +6 -6
  148. data/app/views/devise/passwords/new.html.haml +3 -3
  149. data/app/views/devise/sessions/new.html.haml +8 -8
  150. data/app/views/devise/shared/_links.html.haml +2 -2
  151. data/app/views/layouts/application.html.haml +24 -19
  152. data/app/views/rad_social_mailer/social_mail_form.html.haml +15 -17
  153. data/app/views/widget/_email_form.html.haml +13 -18
  154. data/app/views/widget/_horizontal_widget.html.haml +5 -5
  155. data/bin/rails +4 -4
  156. data/bin/trusty_cms +3 -5
  157. data/config.ru +1 -1
  158. data/config/application.rb +14 -15
  159. data/config/boot.rb +1 -2
  160. data/config/environment.rb +1 -1
  161. data/config/environments/production.rb +0 -1
  162. data/config/environments/test.rb +1 -2
  163. data/config/initializers/devise.rb +1 -1
  164. data/config/initializers/kraken.rb +2 -2
  165. data/config/initializers/tmp.rb +1 -1
  166. data/config/initializers/trusty_cms_config.rb +48 -48
  167. data/config/locales/en.yml +8 -8
  168. data/config/routes.rb +6 -7
  169. data/lib/active_record_extensions/active_record_extensions.rb +1 -2
  170. data/lib/annotatable.rb +3 -5
  171. data/lib/configuration_extensions/configuration_extensions.rb +1 -1
  172. data/lib/inheritable_class_attributes.rb +13 -9
  173. data/lib/login_system.rb +73 -73
  174. data/lib/method_observer.rb +13 -12
  175. data/lib/ostruct.rb +7 -10
  176. data/lib/simpleton.rb +0 -4
  177. data/lib/string_extensions/string_extensions.rb +3 -3
  178. data/lib/symbol_extensions/symbol_extensions.rb +1 -1
  179. data/lib/tasks/database.rake +28 -28
  180. data/lib/tasks/extensions.rake +18 -18
  181. data/lib/tasks/framework.rake +68 -68
  182. data/lib/tasks/radiant_config.rake +4 -4
  183. data/lib/tasks/snippets_extension_tasks.rake +11 -11
  184. data/lib/tasks/translate.rake +14 -14
  185. data/lib/tasks/upgrade_to_devise.rake +1 -1
  186. data/lib/translation_support.rb +22 -22
  187. data/lib/trusty_cms.rb +2 -2
  188. data/lib/trusty_cms/admin_ui.rb +19 -16
  189. data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
  190. data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
  191. data/lib/trusty_cms/available_locales.rb +2 -4
  192. data/lib/trusty_cms/config/definition.rb +11 -8
  193. data/lib/trusty_cms/engine.rb +13 -14
  194. data/lib/trusty_cms/extension.rb +14 -16
  195. data/lib/trusty_cms/extension_loader.rb +6 -6
  196. data/lib/trusty_cms/extension_migrator.rb +42 -41
  197. data/lib/trusty_cms/extension_path.rb +20 -19
  198. data/lib/trusty_cms/initializer.rb +5 -8
  199. data/lib/trusty_cms/pagination/controller.rb +7 -10
  200. data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
  201. data/lib/trusty_cms/resource_responses.rb +3 -3
  202. data/lib/trusty_cms/setup.rb +130 -132
  203. data/lib/trusty_cms/taggable.rb +19 -22
  204. data/lib/trusty_cms/task_support.rb +9 -6
  205. data/package.json +10 -2
  206. data/public/dispatch.fcgi +1 -1
  207. data/public/dispatch.rb +2 -2
  208. data/script/extension +1 -1
  209. data/script/rails +2 -2
  210. data/spec/dummy/package.json +1 -1
  211. data/spec/dummy/yarn.lock +3 -3
  212. data/trusty_cms.gemspec +25 -25
  213. data/vendor/extensions/clipped-extension/lib/clipped_admin_ui.rb +1 -1
  214. data/yarn.lock +1992 -4
  215. metadata +54 -43
  216. data/app/assets/javascripts/rad_social/captcha.js +0 -42
  217. data/app/assets/stylesheets/admin/partials/_deprecated.scss +0 -65
  218. data/app/assets/stylesheets/admin/partials/_jquery-ui-structure.scss +0 -258
  219. data/app/assets/stylesheets/admin/partials/_jquery-ui-theme.scss +0 -410
  220. data/app/assets/stylesheets/admin/partials/_jquery-ui.scss +0 -650
  221. data/app/views/admin/assets/refresh.html.haml +0 -14
@@ -1,5 +1,4 @@
1
1
  class Admin::ConfigurationController < ApplicationController
2
-
3
2
  # Admin::ConfigurationController handles the batch-updating of TrustyCms::Config entries.
4
3
  # It accepts any set of config name-value pairs but is accessible only to administrators.
5
4
  # Note that configuration is routed as a singular resource so we only deal with show/edit/update
@@ -8,9 +7,9 @@ class Admin::ConfigurationController < ApplicationController
8
7
  before_action :initialize_config
9
8
 
10
9
  only_allow_access_to :edit, :update,
11
- :when => [:admin],
12
- :denied_url => { :controller => 'admin/configuration', :action => 'show' },
13
- :denied_message => 'You must have admin privileges to edit site configuration.'
10
+ when: [:admin],
11
+ denied_url: { controller: 'admin/configuration', action: 'show' },
12
+ denied_message: 'You must have admin privileges to edit site configuration.'
14
13
 
15
14
  def show
16
15
  @user = current_user
@@ -27,24 +26,23 @@ class Admin::ConfigurationController < ApplicationController
27
26
  TrustyCms.config.transaction do
28
27
  params[:trusty_config].each_pair do |key, value|
29
28
  @trusty_config[key] = TrustyCms::Config.find_or_initialize_by(key: key)
30
- @trusty_config[key].value = value # validation sets errors on @trusty_config['key'] that the helper methods will pick up
29
+ @trusty_config[key].value = value # validation sets errors on @trusty_config['key'] that the helper methods will pick up
31
30
  end
32
- redirect_to :action => :show
31
+ redirect_to action: :show
33
32
  end
34
33
  rescue ActiveRecord::RecordInvalid => e
35
- flash[:error] = "Configuration error: please check the form"
36
- render :action => :edit
34
+ flash[:error] = 'Configuration error: please check the form'
35
+ render action: :edit
37
36
  rescue TrustyCms::Config::ConfigError => e
38
37
  flash[:error] = "Configuration error: #{e}"
39
- render :action => :edit
38
+ render action: :edit
40
39
  end
41
40
  end
42
41
  end
43
42
 
44
- protected
43
+ protected
45
44
 
46
45
  def initialize_config
47
46
  @trusty_config = {}
48
47
  end
49
-
50
48
  end
@@ -1,8 +1,8 @@
1
1
  class Admin::ExtensionsController < ApplicationController
2
2
  only_allow_access_to :index,
3
- :when => :admin,
4
- :denied_url => { :controller => 'pages', :action => 'index' },
5
- :denied_message => 'You must have administrative privileges to perform this action.'
3
+ when: :admin,
4
+ denied_url: { controller: 'pages', action: 'index' },
5
+ denied_message: 'You must have administrative privileges to perform this action.'
6
6
 
7
7
  def index
8
8
  @template_name = 'index' # for Admin::RegionsHelper
@@ -1,8 +1,7 @@
1
1
  class Admin::LayoutsController < Admin::ResourceController
2
2
  paginate_models
3
3
  only_allow_access_to :index, :show, :new, :create, :edit, :update, :remove, :destroy,
4
- :when => [:designer, :admin],
5
- :denied_url => { :controller => 'admin/pages', :action => 'index' },
6
- :denied_message => 'You must have designer privileges to perform this action.'
7
-
4
+ when: %i[designer admin],
5
+ denied_url: { controller: 'admin/pages', action: 'index' },
6
+ denied_message: 'You must have designer privileges to perform this action.'
8
7
  end
@@ -2,7 +2,7 @@ class Admin::PageAttachmentsController < Admin::ResourceController
2
2
  helper 'admin/assets'
3
3
 
4
4
  def new
5
- render :partial => 'attachment', :object => model
5
+ render partial: 'attachment', object: model
6
6
  end
7
7
 
8
8
  def load_model
@@ -10,14 +10,14 @@ class Admin::PageAttachmentsController < Admin::ResourceController
10
10
  @asset = Asset.find(params[:asset_id])
11
11
  @page = page_attachment_params[:page_id].blank? ? Page.new : Page.find_by_id(page_attachment_params[:page_id])
12
12
  rescue ActiveRecord::RecordNotFound
13
- render :nothing => true, :layout => false
13
+ render nothing: true, layout: false
14
14
  end
15
- self.model = PageAttachment.new(:asset => @asset, :page => @page)
15
+ self.model = PageAttachment.new(asset: @asset, page: @page)
16
16
  end
17
17
 
18
- private
18
+ private
19
+
19
20
  def page_attachment_params
20
21
  params.permit(:asset_id, :page_id)
21
22
  end
22
-
23
23
  end
@@ -1,10 +1,10 @@
1
1
  class Admin::PageFieldsController < Admin::ResourceController
2
2
  def create
3
- self.model.attributes = page_fields_params
3
+ model.attributes = page_fields_params
4
4
  @controller_name = 'page'
5
5
  @template_name = 'edit'
6
- render :partial => "page_field", :object => model,
7
- :locals => { :page_field_counter => params[:page_field_counter].to_i}
6
+ render partial: 'page_field', object: model,
7
+ locals: { page_field_counter: params[:page_field_counter].to_i }
8
8
  end
9
9
 
10
10
  private
@@ -12,5 +12,4 @@ class Admin::PageFieldsController < Admin::ResourceController
12
12
  def page_fields_params
13
13
  params.require(:page_field).permit(:name, :content, :page_id)
14
14
  end
15
-
16
15
  end
@@ -1,16 +1,15 @@
1
1
  class Admin::PagePartsController < Admin::ResourceController
2
2
  def create
3
- self.model.attributes = page_parts_params
3
+ model.attributes = page_parts_params
4
4
  @controller_name = 'page'
5
5
  @template_name = 'edit'
6
- render :partial => "page_part", :object => model,
7
- :locals => {:page_part_counter => params[:index].to_i}
6
+ render partial: 'page_part', object: model,
7
+ locals: { page_part_counter: params[:index].to_i }
8
8
  end
9
9
 
10
- private
10
+ private
11
11
 
12
12
  def page_parts_params
13
13
  params.require(:page_part).permit(:name, :filter_id, :content)
14
14
  end
15
-
16
15
  end
@@ -1,7 +1,7 @@
1
1
  class Admin::PagesController < Admin::ResourceController
2
- before_action :initialize_meta_rows_and_buttons, :only => [:new, :edit, :create, :update]
3
- before_action :count_deleted_pages, :only => [:destroy]
4
- rescue_from ActiveRecord::RecordInvalid, :with => :validation_error
2
+ before_action :initialize_meta_rows_and_buttons, only: %i[new edit create update]
3
+ before_action :count_deleted_pages, only: [:destroy]
4
+ rescue_from ActiveRecord::RecordInvalid, with: :validation_error
5
5
 
6
6
  class PreviewStop < ActiveRecord::Rollback
7
7
  def message
@@ -13,11 +13,11 @@ class Admin::PagesController < Admin::ResourceController
13
13
  r.plural.js do
14
14
  @level = params[:level].to_i
15
15
  @index = params[:index].to_i
16
- @rendered_html = ""
16
+ @rendered_html = ''
17
17
  @template_name = 'index'
18
18
  self.models = Page.find(params[:page_id]).children.all
19
19
  response.headers['Content-Type'] = 'text/html;charset=utf-8'
20
- render :action => 'children.html.haml', :layout => false
20
+ render action: 'children.html.haml', layout: false
21
21
  end
22
22
  end
23
23
 
@@ -34,8 +34,8 @@ class Admin::PagesController < Admin::ResourceController
34
34
 
35
35
  def preview
36
36
  render_preview
37
- rescue PreviewStop => exception
38
- render :text => exception.message unless @performed_render
37
+ rescue PreviewStop => e
38
+ render text: e.message unless @performed_render
39
39
  end
40
40
 
41
41
  def save_table_position
@@ -44,67 +44,66 @@ class Admin::PagesController < Admin::ResourceController
44
44
  head :ok
45
45
  end
46
46
 
47
-
48
47
  private
49
48
 
50
- def validation_error(e)
51
- flash[:error] = e.message
52
- render :new
53
- end
49
+ def validation_error(e)
50
+ flash[:error] = e.message
51
+ render :new
52
+ end
54
53
 
55
- def assign_page_attributes
56
- if params[:page_id].blank?
57
- self.model.slug = '/'
58
- end
59
- self.model.parent_id = params[:page_id]
54
+ def assign_page_attributes
55
+ if params[:page_id].blank?
56
+ model.slug = '/'
60
57
  end
58
+ model.parent_id = params[:page_id]
59
+ end
61
60
 
62
- def model_class
63
- if Page.descendants.any? { |d| d.to_s == params[:page_class] }
64
- verify_page_class(params[:page_class])
65
- elsif params[:page_id]
66
- Page.find(params[:page_id]).children
67
- else
68
- Page
69
- end
61
+ def model_class
62
+ if Page.descendants.any? { |d| d.to_s == params[:page_class] }
63
+ verify_page_class(params[:page_class])
64
+ elsif params[:page_id]
65
+ Page.find(params[:page_id]).children
66
+ else
67
+ Page
70
68
  end
69
+ end
71
70
 
72
- def render_preview
73
- params.permit!
74
- Page.transaction do
75
- page_class = Page.descendants.include?(model_class) ? model_class : Page
76
- if request.referer =~ %r{/admin/pages/(\d+)/edit}
77
- page = Page.find($1).becomes(page_class)
78
- layout_id = page.layout_id
79
- page.update_attributes(params[:page])
80
- page.published_at ||= Time.now
81
- else
82
- page = page_class.new(params[:page])
83
- page.published_at = page.updated_at = page.created_at = Time.now
84
- page.parent = Page.find($1) if request.referer =~ %r{/admin/pages/(\d+)/children/new}
85
- end
86
- page.pagination_parameters = pagination_parameters
87
- process_with_exception(page)
71
+ def render_preview
72
+ params.permit!
73
+ Page.transaction do
74
+ page_class = Page.descendants.include?(model_class) ? model_class : Page
75
+ if request.referer =~ %r{/admin/pages/(\d+)/edit}
76
+ page = Page.find($1).becomes(page_class)
77
+ layout_id = page.layout_id
78
+ page.update_attributes(params[:page])
79
+ page.published_at ||= Time.now
80
+ else
81
+ page = page_class.new(params[:page])
82
+ page.published_at = page.updated_at = page.created_at = Time.now
83
+ page.parent = Page.find($1) if request.referer =~ %r{/admin/pages/(\d+)/children/new}
88
84
  end
85
+ page.pagination_parameters = pagination_parameters
86
+ process_with_exception(page)
89
87
  end
88
+ end
90
89
 
91
- def process_with_exception(page)
92
- page.process(request, response)
93
- @performed_render = true
94
- render template: 'site/show_page', layout: false
95
- raise PreviewStop
96
- end
90
+ def process_with_exception(page)
91
+ page.process(request, response)
92
+ @performed_render = true
93
+ render template: 'site/show_page', layout: false
94
+ raise PreviewStop
95
+ end
97
96
 
98
- def count_deleted_pages
99
- @count = model.children.count + 1
100
- end
97
+ def count_deleted_pages
98
+ @count = model.children.count + 1
99
+ end
101
100
 
102
- def initialize_meta_rows_and_buttons
103
- @buttons_partials ||= []
104
- @meta ||= []
105
- @meta << {:field => "slug", :type => "text_field", :args => [{:class => 'textbox', :maxlength => 100}]}
106
- @meta << {:field => "breadcrumb", :type => "text_field", :args => [{:class => 'textbox', :maxlength => 160}]}
107
- end
101
+ def initialize_meta_rows_and_buttons
102
+ @buttons_partials ||= []
103
+ @meta ||= []
104
+ @meta << { field: 'slug', type: 'text_field', args: [{ class: 'textbox' }] }
105
+ @meta << { field: 'breadcrumb', type: 'text_field', args: [{ class: 'textbox' }] }
106
+ end
108
107
 
109
108
  def verify_page_class(page_class)
110
109
  if page_class.constantize.ancestors.include?(Page)
@@ -2,7 +2,7 @@ class Admin::ReferencesController < ApplicationController
2
2
  def show
3
3
  respond_to do |format|
4
4
  render_allowed_type(params[:type])
5
- format.any { render :action => @type, :content_type => "text/html", :layout => false }
5
+ format.any { render action: @type, content_type: 'text/html', layout: false }
6
6
  end
7
7
  end
8
8
 
@@ -5,10 +5,10 @@ class Admin::ResourceController < ApplicationController
5
5
  helper_method :model, :current_object, :models, :current_objects, :model_symbol, :plural_model_symbol, :model_class, :model_name, :plural_model_name
6
6
  before_action :populate_format
7
7
  before_action :never_cache
8
- before_action :load_models, :only => :index
9
- before_action :load_model, :only => [:new, :create, :edit, :update, :remove, :destroy]
10
- before_action :set_owner_or_editor, :only => [:new, :create, :update]
11
- after_action :clear_model_cache, :only => [:create, :update, :destroy]
8
+ before_action :load_models, only: :index
9
+ before_action :load_model, only: %i[new create edit update remove destroy]
10
+ before_action :set_owner_or_editor, only: %i[new create update]
11
+ after_action :clear_model_cache, only: %i[create update destroy]
12
12
 
13
13
  cattr_reader :paginated
14
14
  cattr_accessor :default_per_page, :will_paginate_options
@@ -23,18 +23,18 @@ class Admin::ResourceController < ApplicationController
23
23
  r.plural.publish(:xml, :json) { render format_symbol => models }
24
24
 
25
25
  r.singular.publish(:xml, :json) { render format_symbol => model }
26
- r.singular.default { redirect_to edit_model_path if action_name == "show" }
26
+ r.singular.default { redirect_to edit_model_path if action_name == 'show' }
27
27
 
28
28
  r.not_found.publish(:xml, :json) { head :not_found }
29
- r.not_found.default { announce_not_found; redirect_to :action => "index" }
29
+ r.not_found.default { announce_not_found; redirect_to action: 'index' }
30
30
 
31
31
  r.invalid.publish(:xml, :json) { render format_symbol => model.errors, :status => :unprocessable_entity }
32
- r.invalid.default { announce_validation_errors; render :action => template_name }
32
+ r.invalid.default { announce_validation_errors; render action: template_name }
33
33
 
34
34
  r.stale.publish(:xml, :json) { head :conflict }
35
- r.stale.default { announce_update_conflict; render :action => template_name }
35
+ r.stale.default { announce_update_conflict; render action: template_name }
36
36
 
37
- r.create.publish(:xml, :json) { render format_symbol => model, :status => :created, :location => url_for(:format => format_symbol, :id => model) }
37
+ r.create.publish(:xml, :json) { render format_symbol => model, :status => :created, :location => url_for(format: format_symbol, id: model) }
38
38
  r.create.default { redirect_to continue_url(params) }
39
39
 
40
40
  r.update.publish(:xml, :json) { head :ok }
@@ -48,7 +48,7 @@ class Admin::ResourceController < ApplicationController
48
48
  response_for :plural
49
49
  end
50
50
 
51
- [:show, :new, :edit, :remove].each do |action|
51
+ %i[show new edit remove].each do |action|
52
52
  class_eval %{
53
53
  def #{action} # def show
54
54
  response_for :singular # response_for :singular
@@ -56,7 +56,7 @@ class Admin::ResourceController < ApplicationController
56
56
  }, __FILE__, __LINE__
57
57
  end
58
58
 
59
- [:create, :update].each do |action|
59
+ %i[create update].each do |action|
60
60
  class_eval %{
61
61
  def #{action} # def create
62
62
  model.update_attributes!(permitted_params[model_symbol]) # model.update_attributes!(params[model_symbol])
@@ -71,7 +71,7 @@ class Admin::ResourceController < ApplicationController
71
71
  end
72
72
 
73
73
  def self.model_class(model_class = nil)
74
- @model_class ||= (model_class || self.controller_name).to_s.singularize.camelize.constantize
74
+ @model_class ||= (model_class || controller_name).to_s.singularize.camelize.constantize
75
75
  end
76
76
 
77
77
  # call paginate_models to declare that will_paginate should be used in the index view
@@ -81,9 +81,9 @@ class Admin::ResourceController < ApplicationController
81
81
  # Class MyController < Admin::ResourceController
82
82
  # paginate_models :per_page => 100
83
83
 
84
- def self.paginate_models(options={})
84
+ def self.paginate_models(options = {})
85
85
  @@paginated = true
86
- @@will_paginate_options = options.slice(:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container).merge(:param_name => :p)
86
+ @@will_paginate_options = options.slice(:class, :previous_label, :next_label, :inner_window, :outer_window, :separator, :container).merge(param_name: :p)
87
87
  @@default_per_page = options[:per_page]
88
88
  end
89
89
 
@@ -111,151 +111,153 @@ class Admin::ResourceController < ApplicationController
111
111
  pp = params[:pp] || TrustyCms.config['admin.pagination.per_page']
112
112
  pp = (self.class.default_per_page || 50) if pp.blank?
113
113
  {
114
- :page => (params[:p] || 1).to_i,
115
- :per_page => pp.to_i
114
+ page: (params[:p] || 1).to_i,
115
+ per_page: pp.to_i,
116
116
  }
117
117
  end
118
118
 
119
119
  protected
120
120
 
121
- def rescue_action(exception)
122
- case exception
123
- when ActiveRecord::RecordInvalid
124
- response_for :invalid
125
- when ActiveRecord::StaleObjectError
126
- response_for :stale
127
- when ActiveRecord::RecordNotFound
128
- response_for :not_found
129
- else
130
- super
131
- end
121
+ def rescue_action(exception)
122
+ case exception
123
+ when ActiveRecord::RecordInvalid
124
+ response_for :invalid
125
+ when ActiveRecord::StaleObjectError
126
+ response_for :stale
127
+ when ActiveRecord::RecordNotFound
128
+ response_for :not_found
129
+ else
130
+ super
132
131
  end
132
+ end
133
133
 
134
- def model_class
135
- self.class.model_class
136
- end
134
+ def model_class
135
+ self.class.model_class
136
+ end
137
137
 
138
- def set_owner_or_editor
139
- if self.model.has_attribute? :created_by_id
140
- self.model.created_by_id = current_user.id if self.model.id == nil
141
- self.model.updated_by_id = current_user.id
142
- end
138
+ def set_owner_or_editor
139
+ if model.has_attribute? :created_by_id
140
+ model.created_by_id = current_user.id if model.id == nil
141
+ model.updated_by_id = current_user.id
143
142
  end
143
+ end
144
144
 
145
- def model
146
- instance_variable_get("@#{model_symbol}") || load_model
147
- end
148
- alias :current_object :model
149
- def model=(object)
150
- instance_variable_set("@#{model_symbol}", object)
151
- end
152
- def load_model
153
- self.model = if params[:id]
154
- model_class.find(params[:id])
155
- else
156
- model_class.new()
157
- end
158
- end
145
+ def model
146
+ instance_variable_get("@#{model_symbol}") || load_model
147
+ end
148
+ alias :current_object :model
149
+ def model=(object)
150
+ instance_variable_set("@#{model_symbol}", object)
151
+ end
159
152
 
160
- def models
161
- instance_variable_get("@#{plural_model_symbol}") || load_models
162
- end
163
- alias :current_objects :models
164
- def models=(objects)
165
- instance_variable_set("@#{plural_model_symbol}", objects)
166
- end
167
- def load_models
168
- self.models = paginated? ? model_class.paginate(pagination_parameters) : model_class.all
153
+ def load_model
154
+ self.model = if params[:id]
155
+ model_class.find(params[:id])
156
+ else
157
+ model_class.new
169
158
  end
159
+ end
170
160
 
171
- def model_name
172
- model_class.name
173
- end
174
- def plural_model_name
175
- model_name.pluralize
176
- end
177
- alias :models_name :plural_model_name
161
+ def models
162
+ instance_variable_get("@#{plural_model_symbol}") || load_models
163
+ end
164
+ alias :current_objects :models
165
+ def models=(objects)
166
+ instance_variable_set("@#{plural_model_symbol}", objects)
167
+ end
178
168
 
179
- def model_symbol
180
- model_name.underscore.intern
181
- end
182
- def plural_model_symbol
183
- model_name.pluralize.underscore.intern
184
- end
185
- alias :models_symbol :plural_model_symbol
169
+ def load_models
170
+ self.models = paginated? ? model_class.paginate(pagination_parameters) : model_class.all
171
+ end
186
172
 
187
- def humanized_model_name
188
- t(model_name.underscore.downcase)
189
- end
173
+ def model_name
174
+ model_class.name
175
+ end
190
176
 
191
- def continue_url(options)
192
- options[:redirect_to] || (params[:continue] ? {:action => 'edit', :id => model.id} : index_page_for_model)
193
- end
177
+ def plural_model_name
178
+ model_name.pluralize
179
+ end
180
+ alias :models_name :plural_model_name
194
181
 
195
- def index_page_for_model
196
- parts = {:action => "index"}
197
- if paginated? && model && i = model_class.all.index(model)
198
- p = (i / pagination_parameters[:per_page].to_i) + 1
199
- parts[:p] = p if p && p > 1
200
- end
201
- parts
202
- end
182
+ def model_symbol
183
+ model_name.underscore.intern
184
+ end
203
185
 
204
- def edit_model_path
205
- method = "edit_admin_#{model_name.underscore}_path"
206
- send method.to_sym, params[:id]
207
- end
186
+ def plural_model_symbol
187
+ model_name.pluralize.underscore.intern
188
+ end
189
+ alias :models_symbol :plural_model_symbol
208
190
 
209
- def announce_validation_errors
210
- flash.now[:error] = t("resource_controller.validation_errors")
211
- end
191
+ def humanized_model_name
192
+ t(model_name.underscore.downcase)
193
+ end
212
194
 
213
- def announce_removed
214
- ActiveSupport::Deprecation.warn("announce_removed is no longer encouraged in TrustyCms 0.9.x.", caller)
215
- flash[:notice] = t("resource_controller.removed", :humanized_model_name => humanized_model_name)
216
- end
195
+ def continue_url(options)
196
+ options[:redirect_to] || (params[:continue] ? { action: 'edit', id: model.id } : index_page_for_model)
197
+ end
217
198
 
218
- def announce_not_found
219
- flash[:notice] = t("resource_controller.not_found", :humanized_model_name => humanized_model_name)
199
+ def index_page_for_model
200
+ parts = { action: 'index' }
201
+ if paginated? && model && i = model_class.all.index(model)
202
+ p = (i / pagination_parameters[:per_page].to_i) + 1
203
+ parts[:p] = p if p && p > 1
220
204
  end
205
+ parts
206
+ end
221
207
 
222
- def announce_update_conflict
223
- flash.now[:error] = t("resource_controller.update_conflict", :humanized_model_name => humanized_model_name)
224
- end
208
+ def edit_model_path
209
+ method = "edit_admin_#{model_name.underscore}_path"
210
+ send method.to_sym, params[:id]
211
+ end
225
212
 
226
- def clear_model_cache
227
- Rails.cache.clear
228
- end
213
+ def announce_validation_errors
214
+ flash.now[:error] = t('resource_controller.validation_errors')
215
+ end
229
216
 
230
- def format_symbol
231
- format.to_sym
232
- end
217
+ def announce_removed
218
+ ActiveSupport::Deprecation.warn('announce_removed is no longer encouraged in TrustyCms 0.9.x.', caller)
219
+ flash[:notice] = t('resource_controller.removed', humanized_model_name: humanized_model_name)
220
+ end
233
221
 
234
- def format
235
- params[:format] || 'html'
236
- end
222
+ def announce_not_found
223
+ flash[:notice] = t('resource_controller.not_found', humanized_model_name: humanized_model_name)
224
+ end
237
225
 
226
+ def announce_update_conflict
227
+ flash.now[:error] = t('resource_controller.update_conflict', humanized_model_name: humanized_model_name)
228
+ end
238
229
 
239
- # I would like to set this to expires_in(1.minute, :private => true) to allow for more fluid navigation
240
- # but the annoyance for concurrent authors would be too great.
241
- def never_cache
242
- expires_now
243
- end
230
+ def clear_model_cache
231
+ Rails.cache.clear
232
+ end
244
233
 
245
- # Assist with user agents that cause improper content-negotiation
246
- # warn "Remove default HTML format, Accept header no longer used. (#{__FILE__}: #{__LINE__})" if Rails.version !~ /^2\.1/
247
- def populate_format
248
- params[:format] ||= 'html' unless request.xhr?
249
- end
234
+ def format_symbol
235
+ format.to_sym
236
+ end
250
237
 
251
- def permitted_params
252
- model_symbols = ActiveRecord::Base.descendants.map{|a| a.name.underscore.to_sym}
253
- keys = params.keys.map{|k| k.underscore.to_sym}
254
- valid_symbols = model_symbols & keys
255
- valid_symbols.each do |symbol|
256
- params[symbol].permit!
257
- end
258
- params
259
- end
238
+ def format
239
+ params[:format] || 'html'
240
+ end
260
241
 
242
+ # I would like to set this to expires_in(1.minute, :private => true) to allow for more fluid navigation
243
+ # but the annoyance for concurrent authors would be too great.
244
+ def never_cache
245
+ expires_now
246
+ end
247
+
248
+ # Assist with user agents that cause improper content-negotiation
249
+ # warn "Remove default HTML format, Accept header no longer used. (#{__FILE__}: #{__LINE__})" if Rails.version !~ /^2\.1/
250
+ def populate_format
251
+ params[:format] ||= 'html' unless request.xhr?
252
+ end
253
+
254
+ def permitted_params
255
+ model_symbols = ActiveRecord::Base.descendants.map { |a| a.name.underscore.to_sym }
256
+ keys = params.keys.map { |k| k.underscore.to_sym }
257
+ valid_symbols = model_symbols & keys
258
+ valid_symbols.each do |symbol|
259
+ params[symbol].permit!
260
+ end
261
+ params
262
+ end
261
263
  end