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
@@ -2,9 +2,9 @@ require 'trusty_cms/taggable'
2
2
  module DeprecatedTags
3
3
  include TrustyCms::Taggable
4
4
 
5
- deprecated_tag "comment", :substitute => "hide", :deadline => '2.0'
5
+ deprecated_tag 'comment', substitute: 'hide', deadline: '2.0'
6
6
 
7
- deprecated_tag "meta", :deadline => '2.0' do |tag|
7
+ deprecated_tag 'meta', deadline: '2.0' do |tag|
8
8
  if tag.double?
9
9
  tag.expand
10
10
  else
@@ -12,11 +12,10 @@ module DeprecatedTags
12
12
  end
13
13
  end
14
14
 
15
- deprecated_tag "rfc1123_date", :deadline => '2.0' do |tag|
15
+ deprecated_tag 'rfc1123_date', deadline: '2.0' do |tag|
16
16
  page = tag.locals.page
17
17
  if date = page.published_at || page.created_at
18
18
  CGI.rfc1123_date(date.to_time)
19
19
  end
20
20
  end
21
-
22
21
  end
@@ -1,5 +1,4 @@
1
1
  class FileNotFoundPage < Page
2
-
3
2
  def allowed_children
4
3
  []
5
4
  end
@@ -13,7 +12,7 @@ class FileNotFoundPage < Page
13
12
  page type.
14
13
  }
15
14
 
16
- tag "attempted_url" do |tag|
15
+ tag 'attempted_url' do |_tag|
17
16
  CGI.escapeHTML(request.request_uri) unless request.nil?
18
17
  end
19
18
 
@@ -28,5 +27,4 @@ class FileNotFoundPage < Page
28
27
  def cache?
29
28
  false
30
29
  end
31
-
32
30
  end
@@ -1,5 +1,5 @@
1
1
  class HamlFilter < TextFilter
2
2
  def filter(text)
3
- Haml::Engine.new(text).render.gsub(/&lt;(\/)?r:(.+?)\s*(\/?\\?)&gt;/m,"<\\1r:\\2\\3>")
3
+ Haml::Engine.new(text).render.gsub(/&lt;(\/)?r:(.+?)\s*(\/?\\?)&gt;/m, '<\\1r:\\2\\3>')
4
4
  end
5
5
  end
@@ -1,15 +1,14 @@
1
1
  class Layout < ActiveRecord::Base
2
-
3
2
  # Default Order
4
- default_scope {order("name")}
3
+ default_scope { order('name') }
5
4
 
6
5
  # Associations
7
6
  has_many :pages
8
- belongs_to :created_by, :class_name => 'User'
9
- belongs_to :updated_by, :class_name => 'User'
7
+ belongs_to :created_by, class_name: 'User'
8
+ belongs_to :updated_by, class_name: 'User'
10
9
 
11
10
  # Validations
12
11
  validates_presence_of :name
13
12
  validates_uniqueness_of :name
14
- validates_length_of :name, :maximum => 100
13
+ validates_length_of :name, maximum: 100
15
14
  end
@@ -1,6 +1,6 @@
1
1
  class LegacyUser < ActiveRecord::Base
2
2
  self.table_name = 'users'
3
3
 
4
- # this is a legacy class
4
+ # this is a legacy class
5
5
  # this table formally held user information for when TrustyCMS had a handwritten authentication system
6
- end
6
+ end
@@ -1,5 +1,4 @@
1
1
  module MenuRenderer
2
-
3
2
  def exclude(*type_names)
4
3
  @excluded_class_names ||= []
5
4
  @excluded_class_names.concat(type_names).uniq!
@@ -26,7 +25,7 @@ module MenuRenderer
26
25
  end
27
26
 
28
27
  def menu_renderer_module_name
29
- simple_name = self.class_name.to_s.sub('Page','')
28
+ simple_name = class_name.to_s.sub('Page', '')
30
29
  "#{simple_name}MenuRenderer"
31
30
  end
32
31
 
@@ -38,19 +37,18 @@ module MenuRenderer
38
37
  (allowed_children_cache.to_s.split(',') - Array(excluded_class_names)).map do |name|
39
38
  begin
40
39
  name.constantize
41
- rescue LoadError, NameError => _
40
+ rescue LoadError, NameError => _e
42
41
  nil
43
42
  end
44
43
  end.compact
45
44
  end
46
45
 
47
-
48
46
  def default_child_item
49
47
  menu_item(default_child)
50
48
  end
51
49
 
52
50
  def separator_item
53
- view.content_tag :li, '', :class => 'separator'
51
+ view.content_tag :li, '', class: 'separator'
54
52
  end
55
53
 
56
54
  def child_items
@@ -64,11 +62,11 @@ module MenuRenderer
64
62
  end
65
63
 
66
64
  def menu_list
67
- view.content_tag :ul, menu_items.join.html_safe, :class => 'menu', :id => "allowed_children_#{id}"
65
+ view.content_tag :ul, menu_items.join.html_safe, class: 'menu', id: "allowed_children_#{id}"
68
66
  end
69
67
 
70
68
  def remove_link
71
- view.link_to view.image('minus') + ' ' + I18n.t('remove'), view.remove_admin_page_url(self), :class => "action"
69
+ view.link_to('<i class="fas fa-minus-circle"></i> '.html_safe + I18n.t('remove'), view.remove_admin_page_url(self), class: 'action')
72
70
  end
73
71
 
74
72
  def remove_option
@@ -80,15 +78,15 @@ module MenuRenderer
80
78
  end
81
79
 
82
80
  def disabled_add_child_link
83
- view.content_tag :span, view.image('plus_disabled') + ' Add Child', :class => 'action disabled'
81
+ view.content_tag :span, view.image('plus_disabled') + ' Add Child', class: 'action disabled'
84
82
  end
85
83
 
86
84
  def add_child_link
87
- view.link_to((view.image('plus') + ' Add Child'), view.new_admin_page_child_path(self, :page_class => default_child.name), :class => "action")
85
+ view.link_to('<i class="fas fa-plus-circle"></i> Add Child'.html_safe, view.new_admin_page_child_path(self, page_class: default_child.name), class: 'action')
88
86
  end
89
87
 
90
88
  def add_child_link_with_menu_hook
91
- view.link_to((view.image('plus') + ' Add Child'), "#allowed_children_#{id}", :class => "action dropdown")
89
+ view.link_to('<i class="fas fa-plus-circle"></i> Add Child'.html_safe, "#allowed_children_#{id}", class: 'action dropdown')
92
90
  end
93
91
 
94
92
  def add_child_menu
@@ -114,7 +112,7 @@ module MenuRenderer
114
112
  private
115
113
 
116
114
  def clean_page_description(page_class)
117
- page_class.description.to_s.strip.gsub(/\t/,'').gsub(/\s+/,' ')
115
+ page_class.description.to_s.strip.gsub(/\t/, '').gsub(/\s+/, ' ')
118
116
  end
119
117
 
120
118
  def menu_item(child_class)
@@ -123,18 +121,18 @@ module MenuRenderer
123
121
 
124
122
  def menu_link(child_class)
125
123
  title = clean_page_description(child_class)
126
- path = view.new_admin_page_child_path(self, :page_class => child_class.name)
124
+ path = view.new_admin_page_child_path(self, page_class: child_class.name)
127
125
  text = link_text_for_child_class(child_class.name)
128
- view.link_to(text, path, :title => title)
126
+ view.link_to(text, path, title: title)
129
127
  end
130
128
 
131
129
  def link_text_for_child_class(given_class_name)
132
130
  translation_key = if given_class_name == 'Page' || given_class_name.blank?
133
- 'normal_page'
134
- else
135
- given_class_name.sub('Page','').underscore
131
+ 'normal_page'
132
+ else
133
+ given_class_name.sub('Page', '').underscore
136
134
  end
137
- fallback = given_class_name == 'Page' ? 'Page' : given_class_name.sub('Page','').titleize
138
- I18n.t(translation_key, :default => fallback)
135
+ fallback = given_class_name == 'Page' ? 'Page' : given_class_name.sub('Page', '').titleize
136
+ I18n.t(translation_key, default: fallback)
139
137
  end
140
138
  end
@@ -1,5 +1,4 @@
1
1
  class Page < ActiveRecord::Base
2
-
3
2
  class MissingRootPageError < StandardError
4
3
  def initialize(message = 'Database missing root page'); super end
5
4
  end
@@ -8,24 +7,24 @@ class Page < ActiveRecord::Base
8
7
  before_save :update_virtual, :update_status, :set_allowed_children_cache
9
8
 
10
9
  # Associations
11
- acts_as_tree :order => 'position ASC'
12
- has_many :parts, -> {order(:id)}, :class_name => 'PagePart', :dependent => :destroy
13
- accepts_nested_attributes_for :parts, :allow_destroy => true
14
- has_many :fields, -> {order(:id)}, :class_name => 'PageField', :dependent => :destroy
15
- accepts_nested_attributes_for :fields, :allow_destroy => true
10
+ acts_as_tree order: 'position ASC'
11
+ has_many :parts, -> { order(:id) }, class_name: 'PagePart', dependent: :destroy
12
+ accepts_nested_attributes_for :parts, allow_destroy: true
13
+ has_many :fields, -> { order(:id) }, class_name: 'PageField', dependent: :destroy
14
+ accepts_nested_attributes_for :fields, allow_destroy: true
16
15
  belongs_to :layout
17
- belongs_to :created_by, :class_name => 'User'
18
- belongs_to :updated_by, :class_name => 'User'
16
+ belongs_to :created_by, class_name: 'User'
17
+ belongs_to :updated_by, class_name: 'User'
19
18
 
20
19
  # Validations
21
20
  validates_presence_of :title, :slug, :breadcrumb, :status_id
22
21
 
23
- validates_length_of :title, :maximum => 255
24
- validates_length_of :slug, :maximum => 100
25
- validates_length_of :breadcrumb, :maximum => 160
22
+ validates_length_of :title, maximum: 255
23
+ validates_length_of :slug, maximum: 100
24
+ validates_length_of :breadcrumb, maximum: 160
26
25
 
27
- validates_format_of :slug, :with => %r{\A([-_.A-Za-z0-9]*|/)\z}
28
- validates_uniqueness_of :slug, :scope => :parent_id
26
+ validates_format_of :slug, with: %r{\A([-_.A-Za-z0-9]*|/)\z}
27
+ validates_uniqueness_of :slug, scope: :parent_id
29
28
 
30
29
  validate :valid_class_name
31
30
 
@@ -42,10 +41,10 @@ class Page < ActiveRecord::Base
42
41
  self.inheritance_column = 'class_name'
43
42
 
44
43
  def layout_with_inheritance
45
- unless layout_without_inheritance
46
- parent.layout if parent?
47
- else
44
+ if layout_without_inheritance
48
45
  layout_without_inheritance
46
+ else
47
+ parent.layout if parent?
49
48
  end
50
49
  end
51
50
 
@@ -53,11 +52,11 @@ class Page < ActiveRecord::Base
53
52
  alias_method :layout, :layout_with_inheritance
54
53
 
55
54
  def description
56
- self["description"]
55
+ self['description']
57
56
  end
58
57
 
59
58
  def description=(value)
60
- self["description"] = value
59
+ self['description'] = value
61
60
  end
62
61
 
63
62
  def cache?
@@ -70,8 +69,8 @@ class Page < ActiveRecord::Base
70
69
  alias_method :child_url, :child_path
71
70
 
72
71
  def part(name)
73
- if new_record? or parts.to_a.any?(&:new_record?)
74
- parts.to_a.find {|p| p.name == name.to_s }
72
+ if new_record? || parts.to_a.any?(&:new_record?)
73
+ parts.to_a.find { |p| p.name == name.to_s }
75
74
  else
76
75
  parts.find_by_name name.to_s
77
76
  end
@@ -86,11 +85,11 @@ class Page < ActiveRecord::Base
86
85
  end
87
86
 
88
87
  def inherits_part?(name)
89
- !has_part?(name) && self.ancestors.any? { |page| page.has_part?(name) }
88
+ !has_part?(name) && ancestors.any? { |page| page.has_part?(name) }
90
89
  end
91
90
 
92
91
  def field(name)
93
- if new_record? or fields.any?(&:new_record?)
92
+ if new_record? || fields.any?(&:new_record?)
94
93
  fields.detect { |f| f.name.downcase == name.to_s.downcase }
95
94
  else
96
95
  fields.find_by_name name.to_s
@@ -106,7 +105,7 @@ class Page < ActiveRecord::Base
106
105
  end
107
106
 
108
107
  def status
109
- Status.find(self.status_id)
108
+ Status.find(status_id)
110
109
  end
111
110
 
112
111
  def status=(value)
@@ -123,7 +122,8 @@ class Page < ActiveRecord::Base
123
122
  alias_method :url, :path
124
123
 
125
124
  def process(request, response)
126
- @request, @response = request, response
125
+ @request = request
126
+ @response = response
127
127
  set_response_headers(@response)
128
128
  @response.body = render
129
129
  @response.status = response_code
@@ -131,12 +131,12 @@ class Page < ActiveRecord::Base
131
131
 
132
132
  def headers
133
133
  # Return a blank hash that child classes can override or merge
134
- { }
134
+ {}
135
135
  end
136
136
 
137
137
  def set_response_headers(response)
138
138
  set_content_type(response)
139
- headers.each { |k,v| response.headers[k] = v }
139
+ headers.each { |k, v| response.headers[k] = v }
140
140
  end
141
141
 
142
142
  def self.save_order(new_position)
@@ -187,11 +187,12 @@ class Page < ActiveRecord::Base
187
187
 
188
188
  def find_by_path(path, live = true, clean = true)
189
189
  return nil if virtual?
190
+
190
191
  path = clean_path(path) if clean
191
192
  my_path = self.path
192
- if (my_path == path) && (not live or published?)
193
+ if (my_path == path) && ((not live) || published?)
193
194
  return self
194
- elsif (path =~ /^#{Regexp.quote(my_path)}([^\/]*)/)
195
+ elsif path =~ /^#{Regexp.quote(my_path)}([^\/]*)/
195
196
  slug_child = children.find_by_slug($1)
196
197
  if slug_child
197
198
  found = slug_child.find_by_path(path, live, clean)
@@ -202,6 +203,7 @@ class Page < ActiveRecord::Base
202
203
  return found if found
203
204
  end
204
205
  end
206
+
205
207
  unless slug_child
206
208
  file_not_found_types = ([FileNotFoundPage] + FileNotFoundPage.descendants)
207
209
  file_not_found_names = file_not_found_types.collect { |x| x.name }
@@ -214,11 +216,11 @@ class Page < ActiveRecord::Base
214
216
  alias_method :find_by_url, :find_by_path
215
217
 
216
218
  def update_status
217
- self.published_at = Time.zone.now if published? && self.published_at == nil
219
+ self.published_at = Time.zone.now if published? && published_at == nil
218
220
 
219
- if self.published_at != nil && (published? || scheduled?)
220
- self[:status_id] = Status[:scheduled].id if self.published_at > Time.zone.now
221
- self[:status_id] = Status[:published].id if self.published_at <= Time.zone.now
221
+ if !published_at.nil? && (published? || scheduled?)
222
+ self[:status_id] = Status[:scheduled].id if published_at > Time.zone.now
223
+ self[:status_id] = Status[:published].id if published_at <= Time.zone.now
222
224
  end
223
225
 
224
226
  true
@@ -237,22 +239,23 @@ class Page < ActiveRecord::Base
237
239
  end
238
240
 
239
241
  class << self
240
-
241
242
  def root
242
243
  find_by_parent_id(nil)
243
244
  end
244
245
 
245
246
  def find_by_path(path, live = true)
246
247
  raise MissingRootPageError unless root
248
+
247
249
  root.find_by_path(path, live)
248
250
  end
251
+
249
252
  def find_by_url(*args)
250
253
  ActiveSupport::Deprecation.warn("`find_by_url' has been deprecated; use `find_by_path' instead.", caller)
251
254
  find_by_path(*args)
252
255
  end
253
256
 
254
257
  def date_column_names
255
- self.columns.collect{|c| c.name if c.sql_type =~ /(date|time)/}.compact
258
+ columns.collect { |c| c.name if c.sql_type =~ /(date|time)/ }.compact
256
259
  end
257
260
 
258
261
  def display_name(string = nil)
@@ -266,7 +269,7 @@ class Page < ActiveRecord::Base
266
269
  n.strip
267
270
  end
268
271
  end
269
- @display_name = @display_name + " - not installed" if missing? && @display_name !~ /not installed/
272
+ @display_name = @display_name + ' - not installed' if missing? && @display_name !~ /not installed/
270
273
  @display_name
271
274
  end
272
275
 
@@ -286,8 +289,8 @@ class Page < ActiveRecord::Base
286
289
  begin
287
290
  p.constantize
288
291
  rescue NameError, LoadError
289
- #Rubocop: The use of eval is a serious security risk.
290
- #eval(%Q{class #{p} < Page; acts_as_tree; def self.missing?; true end end}, TOPLEVEL_BINDING)
292
+ # Rubocop: The use of eval is a serious security risk.
293
+ # eval(%Q{class #{p} < Page; acts_as_tree; def self.missing?; true end end}, TOPLEVEL_BINDING)
291
294
  Rails.logger.error NameError
292
295
  end
293
296
  end
@@ -305,12 +308,13 @@ class Page < ActiveRecord::Base
305
308
  end
306
309
 
307
310
  def is_descendant_class_name?(class_name)
308
- (Page.descendants.map(&:to_s) + [nil, "", "Page"]).include?(class_name)
311
+ (Page.descendants.map(&:to_s) + [nil, '', 'Page']).include?(class_name)
309
312
  end
310
313
 
311
314
  def descendant_class(class_name)
312
- raise ArgumentError.new("argument must be a valid descendant of Page") unless is_descendant_class_name?(class_name)
313
- if ["", nil, "Page"].include?(class_name)
315
+ raise ArgumentError.new('argument must be a valid descendant of Page') unless is_descendant_class_name?(class_name)
316
+
317
+ if ['', nil, 'Page'].include?(class_name)
314
318
  Page
315
319
  else
316
320
  class_name.constantize
@@ -323,73 +327,72 @@ class Page < ActiveRecord::Base
323
327
 
324
328
  private
325
329
 
326
- def default_page_parts(config = TrustyCms::Config)
327
- default_parts = config['defaults.page.parts'].to_s.strip.split(/\s*,\s*/)
328
- default_parts.map do |name|
329
- PagePart.new(:name => name, :filter_id => config['defaults.page.filter'])
330
- end
330
+ def default_page_parts(config = TrustyCms::Config)
331
+ default_parts = config['defaults.page.parts'].to_s.strip.split(/\s*,\s*/)
332
+ default_parts.map do |name|
333
+ PagePart.new(name: name, filter_id: config['defaults.page.filter'])
331
334
  end
335
+ end
332
336
 
333
- def default_page_fields(config = TrustyCms::Config)
334
- default_fields = config['defaults.page.fields'].to_s.strip.split(/\s*,\s*/)
335
- default_fields.map do |name|
336
- PageField.new(:name => name)
337
- end
337
+ def default_page_fields(config = TrustyCms::Config)
338
+ default_fields = config['defaults.page.fields'].to_s.strip.split(/\s*,\s*/)
339
+ default_fields.map do |name|
340
+ PageField.new(name: name)
338
341
  end
342
+ end
339
343
  end
340
344
 
341
345
  private
342
346
 
343
- def valid_class_name
344
- unless Page.is_descendant_class_name?(class_name)
345
- errors.add :class_name, "must be set to a valid descendant of Page"
346
- end
347
- end
348
-
349
- def update_virtual
350
- unless self.class == Page.descendant_class(class_name)
351
- self.virtual = Page.descendant_class(class_name).new.virtual?
352
- else
353
- self.virtual = virtual?
354
- end
355
- true
347
+ def valid_class_name
348
+ unless Page.is_descendant_class_name?(class_name)
349
+ errors.add :class_name, 'must be set to a valid descendant of Page'
356
350
  end
351
+ end
357
352
 
358
- def clean_path(path)
359
- "/#{ path.to_s.strip }".gsub(%r{//+}, '/')
360
- end
361
- alias_method :clean_url, :clean_path
353
+ def update_virtual
354
+ self.virtual = if self.class == Page.descendant_class(class_name)
355
+ virtual?
356
+ else
357
+ Page.descendant_class(class_name).new.virtual?
358
+ end
359
+ true
360
+ end
362
361
 
363
- def parent?
364
- !parent.nil?
365
- end
362
+ def clean_path(path)
363
+ "/#{path.to_s.strip}".gsub(%r{//+}, '/')
364
+ end
365
+ alias_method :clean_url, :clean_path
366
366
 
367
- def database_exists?
368
- ActiveRecord::Base.connection
369
- rescue ActiveRecord::NoDatabaseError
370
- false
371
- else
372
- true
373
- end
367
+ def parent?
368
+ !parent.nil?
369
+ end
374
370
 
375
- def lazy_initialize_parser_and_context
376
- unless @parser and @context
377
- @context = PageContext.new(self)
378
- @parser = Radius::Parser.new(@context, :tag_prefix => 'r')
379
- end
380
- @parser
381
- end
371
+ def database_exists?
372
+ ActiveRecord::Base.connection
373
+ rescue ActiveRecord::NoDatabaseError
374
+ false
375
+ else
376
+ true
377
+ end
382
378
 
383
- def parse(text)
384
- text = "" if text.nil?
385
- lazy_initialize_parser_and_context.parse(text)
379
+ def lazy_initialize_parser_and_context
380
+ unless @parser && @context
381
+ @context = PageContext.new(self)
382
+ @parser = Radius::Parser.new(@context, tag_prefix: 'r')
386
383
  end
384
+ @parser
385
+ end
387
386
 
388
- def parse_object(object)
389
- text = object.content || ''
390
- text = parse(text)
391
- text = object.filter.filter(text) if object.respond_to? :filter_id
392
- text
393
- end
387
+ def parse(text)
388
+ text = '' if text.nil?
389
+ lazy_initialize_parser_and_context.parse(text)
390
+ end
394
391
 
392
+ def parse_object(object)
393
+ text = object.content || ''
394
+ text = parse(text)
395
+ text = object.filter.filter(text) if object.respond_to? :filter_id
396
+ text
397
+ end
395
398
  end