trusty-cms 4.1.2 → 4.1.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (112) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile +2 -2
  3. data/Gemfile.lock +25 -25
  4. data/Rakefile +7 -7
  5. data/app/assets/stylesheets/admin/partials/_content.scss +1 -2
  6. data/app/controllers/admin/assets_controller.rb +22 -21
  7. data/app/controllers/admin/configuration_controller.rb +9 -11
  8. data/app/controllers/admin/extensions_controller.rb +3 -3
  9. data/app/controllers/admin/layouts_controller.rb +3 -4
  10. data/app/controllers/admin/page_attachments_controller.rb +5 -5
  11. data/app/controllers/admin/page_fields_controller.rb +3 -4
  12. data/app/controllers/admin/page_parts_controller.rb +4 -5
  13. data/app/controllers/admin/pages_controller.rb +55 -56
  14. data/app/controllers/admin/references_controller.rb +1 -1
  15. data/app/controllers/admin/resource_controller.rb +132 -130
  16. data/app/controllers/admin/sites_controller.rb +4 -4
  17. data/app/controllers/admin/snippets_controller.rb +3 -4
  18. data/app/controllers/admin/users_controller.rb +16 -16
  19. data/app/controllers/application_controller.rb +47 -48
  20. data/app/controllers/site_controller.rb +51 -48
  21. data/app/controllers/social_mailer_controller.rb +13 -16
  22. data/app/helpers/admin/configuration_helper.rb +19 -20
  23. data/app/helpers/admin/layouts_helper.rb +0 -1
  24. data/app/helpers/admin/node_helper.rb +27 -24
  25. data/app/helpers/admin/pages_helper.rb +2 -2
  26. data/app/helpers/admin/preferences_helper.rb +0 -1
  27. data/app/helpers/admin/references_helper.rb +9 -10
  28. data/app/helpers/admin/regions_helper.rb +3 -3
  29. data/app/helpers/application_helper.rb +32 -33
  30. data/app/helpers/rad_social_helper.rb +8 -11
  31. data/app/helpers/scoped_helper.rb +1 -3
  32. data/app/helpers/sites_helper.rb +4 -4
  33. data/app/mailers/devise_mailer.rb +3 -4
  34. data/app/mailers/rad_social_mailer.rb +8 -8
  35. data/app/models/asset.rb +62 -63
  36. data/app/models/asset_type.rb +38 -39
  37. data/app/models/deprecated_tags.rb +3 -4
  38. data/app/models/file_not_found_page.rb +1 -3
  39. data/app/models/haml_filter.rb +1 -1
  40. data/app/models/layout.rb +4 -5
  41. data/app/models/legacy_user.rb +2 -2
  42. data/app/models/menu_renderer.rb +16 -18
  43. data/app/models/page.rb +96 -93
  44. data/app/models/page_attachment.rb +1 -2
  45. data/app/models/page_context.rb +11 -12
  46. data/app/models/page_part.rb +3 -4
  47. data/app/models/rails_page.rb +10 -12
  48. data/app/models/site.rb +22 -21
  49. data/app/models/snippet.rb +6 -8
  50. data/app/models/snippet_finder.rb +3 -3
  51. data/app/models/snippet_tags.rb +4 -4
  52. data/app/models/standard_tags.rb +258 -252
  53. data/app/models/status.rb +8 -8
  54. data/app/models/trusty_cms/config.rb +25 -25
  55. data/app/models/trusty_cms/page_response_cache_director.rb +2 -3
  56. data/app/models/user.rb +15 -14
  57. data/app/models/user_action_observer.rb +3 -3
  58. data/bin/rails +4 -4
  59. data/bin/trusty_cms +3 -5
  60. data/config.ru +1 -1
  61. data/config/application.rb +14 -15
  62. data/config/boot.rb +1 -2
  63. data/config/environment.rb +1 -1
  64. data/config/environments/production.rb +0 -1
  65. data/config/environments/test.rb +1 -2
  66. data/config/initializers/devise.rb +1 -1
  67. data/config/initializers/kraken.rb +2 -2
  68. data/config/initializers/tmp.rb +1 -1
  69. data/config/initializers/trusty_cms_config.rb +48 -48
  70. data/config/routes.rb +6 -6
  71. data/lib/active_record_extensions/active_record_extensions.rb +1 -2
  72. data/lib/annotatable.rb +3 -5
  73. data/lib/configuration_extensions/configuration_extensions.rb +1 -1
  74. data/lib/inheritable_class_attributes.rb +13 -9
  75. data/lib/login_system.rb +73 -73
  76. data/lib/method_observer.rb +13 -12
  77. data/lib/ostruct.rb +7 -10
  78. data/lib/simpleton.rb +0 -4
  79. data/lib/string_extensions/string_extensions.rb +3 -3
  80. data/lib/symbol_extensions/symbol_extensions.rb +1 -1
  81. data/lib/tasks/database.rake +28 -28
  82. data/lib/tasks/extensions.rake +18 -18
  83. data/lib/tasks/framework.rake +68 -68
  84. data/lib/tasks/radiant_config.rake +4 -4
  85. data/lib/tasks/snippets_extension_tasks.rake +11 -11
  86. data/lib/tasks/translate.rake +14 -14
  87. data/lib/tasks/upgrade_to_devise.rake +1 -1
  88. data/lib/translation_support.rb +22 -22
  89. data/lib/trusty_cms.rb +2 -2
  90. data/lib/trusty_cms/admin_ui.rb +19 -16
  91. data/lib/trusty_cms/admin_ui/region_partials.rb +4 -3
  92. data/lib/trusty_cms/admin_ui/region_set.rb +4 -5
  93. data/lib/trusty_cms/available_locales.rb +2 -4
  94. data/lib/trusty_cms/config/definition.rb +11 -8
  95. data/lib/trusty_cms/engine.rb +14 -14
  96. data/lib/trusty_cms/extension.rb +14 -16
  97. data/lib/trusty_cms/extension_loader.rb +6 -6
  98. data/lib/trusty_cms/extension_migrator.rb +42 -41
  99. data/lib/trusty_cms/extension_path.rb +20 -19
  100. data/lib/trusty_cms/initializer.rb +5 -8
  101. data/lib/trusty_cms/pagination/controller.rb +7 -10
  102. data/lib/trusty_cms/pagination/link_renderer.rb +2 -2
  103. data/lib/trusty_cms/resource_responses.rb +3 -3
  104. data/lib/trusty_cms/setup.rb +130 -132
  105. data/lib/trusty_cms/taggable.rb +19 -22
  106. data/lib/trusty_cms/task_support.rb +9 -6
  107. data/public/dispatch.fcgi +1 -1
  108. data/public/dispatch.rb +2 -2
  109. data/script/extension +1 -1
  110. data/script/rails +2 -2
  111. data/trusty_cms.gemspec +23 -23
  112. metadata +32 -32
@@ -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( '<i class="fas fa-minus-circle"></i> '.html_safe + 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( '<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")
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('<i class="fas fa-plus-circle"></i> Add Child'.html_safe, "#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