Class: Gluttonberg::Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Gluttonberg::Page
- Includes:
- Content::PageComponents
- Defined in:
- app/models/gluttonberg/page.rb
Overview
One of the most important model of Gluttonberg. It stores basic meta data about page and have associations with its related models
Instance Attribute Summary collapse
-
#current_localization ⇒ PageLocalization
Returns current localization of page if its not loaded yet then loads default localization.
-
#current_user_id ⇒ Object
Returns the value of attribute current_user_id.
-
#locale_id ⇒ Object
Returns the value of attribute locale_id.
-
#paths_need_recaching ⇒ Object
Returns the value of attribute paths_need_recaching.
Class Method Summary collapse
-
.repair_pages_structure ⇒ Object
Repair Page tree by optimizing ‘position’ column.
Instance Method Summary collapse
-
#collapsed?(current_user) ⇒ Boolean
check if current page is collapsed for current user?.
-
#duplicate ⇒ Object
Duplicate current page and draft it.
-
#easy_contents(section_name, opts = {}) ⇒ String
Html safe text content or image path depending on content type.
-
#is_public? ⇒ Boolean
if page does not belongs to group (membership) then its a public page.
-
#load_default_localizations ⇒ Object
Load the default localization and set it as current_localization.
-
#load_localization(locale = nil) ⇒ Object
Load the matching localization as specified in the options TODO Write spec for it.
-
#localized_contents ⇒ Object
Just palms off the request for the contents to the current localization.
-
#nav_label ⇒ Object
Returns the localized navigation label, or falls back to the localized page name.
-
#path ⇒ Object
Delegates to the current_localization path.
-
#paths_need_recaching? ⇒ Boolean
this method returns true if page path needs to be recalculated.
-
#public_path ⇒ Object
returns public path of current localization.
-
#title ⇒ Object
Returns the localized title for the page or a default.
Instance Attribute Details
#current_localization ⇒ PageLocalization
Returns current localization of page if its not loaded yet then loads default localization
63 64 65 |
# File 'app/models/gluttonberg/page.rb', line 63 def current_localization @current_localization end |
#current_user_id ⇒ Object
Returns the value of attribute current_user_id.
38 39 40 |
# File 'app/models/gluttonberg/page.rb', line 38 def current_user_id @current_user_id end |
#locale_id ⇒ Object
Returns the value of attribute locale_id.
38 39 40 |
# File 'app/models/gluttonberg/page.rb', line 38 def locale_id @locale_id end |
#paths_need_recaching ⇒ Object
Returns the value of attribute paths_need_recaching.
38 39 40 |
# File 'app/models/gluttonberg/page.rb', line 38 def paths_need_recaching @paths_need_recaching end |
Class Method Details
.repair_pages_structure ⇒ Object
Repair Page tree by optimizing ‘position’ column
126 127 128 |
# File 'app/models/gluttonberg/page.rb', line 126 def self.repair_pages_structure PageRepairer.repair_pages_structure end |
Instance Method Details
#collapsed?(current_user) ⇒ Boolean
check if current page is collapsed for current user?
141 142 143 |
# File 'app/models/gluttonberg/page.rb', line 141 def collapsed?(current_user) !self.collapsed_pages.find_all{|page| page.user_id == current_user.id}.blank? end |
#duplicate ⇒ Object
Duplicate current page and draft it.
136 137 138 |
# File 'app/models/gluttonberg/page.rb', line 136 def duplicate PageDuplicate.duplicate(self) end |
#easy_contents(section_name, opts = {}) ⇒ String
Returns Html safe text content or image path depending on content type.
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/gluttonberg/page.rb', line 48 def easy_contents(section_name, opts = {}) begin prepared_content = nil section_name = section_name.to_sym load_localization(opts[:locale]) if current_localization.blank? content = current_localization.contents.pluck {|c| (c.respond_to?(:parent) && c.parent.section[:name] == section_name ) || (c.respond_to?(:section) && c.section[:name] == section_name ) } prepared_content = _prepare_content(content, opts) rescue end prepared_content end |
#is_public? ⇒ Boolean
if page does not belongs to group (membership) then its a public page
131 132 133 |
# File 'app/models/gluttonberg/page.rb', line 131 def is_public? groups.blank? end |
#load_default_localizations ⇒ Object
Load the default localization and set it as current_localization
120 121 122 123 |
# File 'app/models/gluttonberg/page.rb', line 120 def load_default_localizations Gluttonberg::Locale.first_default.id self.current_localization = Gluttonberg::PageLocalization.where(:page_id => id , :locale_id => Gluttonberg::Locale.first_default.id).first end |
#load_localization(locale = nil) ⇒ Object
Load the matching localization as specified in the options TODO Write spec for it
111 112 113 114 115 116 117 |
# File 'app/models/gluttonberg/page.rb', line 111 def load_localization(locale = nil) if locale.blank? @current_localization = load_default_localizations else @current_localization = localizations.where("locale_id = ? AND path LIKE ?", locale.id, "#{path}%").first end end |
#localized_contents ⇒ Object
Just palms off the request for the contents to the current localization
100 101 102 103 104 105 106 |
# File 'app/models/gluttonberg/page.rb', line 100 def localized_contents @contents ||= begin Content.content_associations.inject([]) do |memo, assoc| memo += send(assoc).all_with_localization(:page_localization_id => current_localization.id) end end end |
#nav_label ⇒ Object
Returns the localized navigation label, or falls back to the localized page name
71 72 73 74 75 76 77 |
# File 'app/models/gluttonberg/page.rb', line 71 def nav_label if current_localization..blank? current_localization.name else current_localization. end end |
#path ⇒ Object
Delegates to the current_localization path
85 86 87 |
# File 'app/models/gluttonberg/page.rb', line 85 def path current_localization.path end |
#paths_need_recaching? ⇒ Boolean
this method returns true if page path needs to be recalculated.
95 96 97 |
# File 'app/models/gluttonberg/page.rb', line 95 def paths_need_recaching? self.paths_need_recaching end |
#public_path ⇒ Object
returns public path of current localization
90 91 92 |
# File 'app/models/gluttonberg/page.rb', line 90 def public_path current_localization.public_path end |
#title ⇒ Object
Returns the localized title for the page or a default
80 81 82 |
# File 'app/models/gluttonberg/page.rb', line 80 def title current_localization.name end |