Class: Page
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Page
- Defined in:
- app/models/page.rb
Class Attribute Summary collapse
-
.layouts ⇒ Object
Returns the value of attribute layouts.
Instance Attribute Summary collapse
-
#controller_action ⇒ Object
Returns the value of attribute controller_action.
-
#no_publish_window ⇒ Object
Returns the value of attribute no_publish_window.
Class Method Summary collapse
- .breadcrumbs_for(user, url) ⇒ Object
- .default_layout ⇒ Object
- .filters ⇒ Object
- .page_parts ⇒ Object
- .status_values ⇒ Object
-
.viewable_by(user) ⇒ Object
Scopes.
- .with_roles(roles) ⇒ Object
- .with_url(request, params) ⇒ Object
Instance Method Summary collapse
- #css_status ⇒ Object
- #duplicate ⇒ Object
- #is_child_of?(page) ⇒ Boolean
- #is_parent_of?(page) ⇒ Boolean
- #is_viewable_by?(user) ⇒ Boolean
-
#lft=(x) ⇒ Object
Override the protected methods of awesome_nested_set so lft and rgt can be set.
- #move_children_to_parent ⇒ Object
- #no_publish_window_set? ⇒ Boolean
- #number_of_children ⇒ Object
- #published? ⇒ Boolean
- #rgt=(x) ⇒ Object
- #to_param ⇒ Object
Class Attribute Details
.layouts ⇒ Object
Returns the value of attribute layouts.
154 155 156 |
# File 'app/models/page.rb', line 154 def layouts @layouts end |
Instance Attribute Details
#controller_action ⇒ Object
Returns the value of attribute controller_action.
46 47 48 |
# File 'app/models/page.rb', line 46 def controller_action @controller_action end |
#no_publish_window ⇒ Object
Returns the value of attribute no_publish_window.
46 47 48 |
# File 'app/models/page.rb', line 46 def no_publish_window @no_publish_window end |
Class Method Details
.breadcrumbs_for(user, url) ⇒ Object
156 157 158 159 |
# File 'app/models/page.rb', line 156 def user, url root = Page.published.viewable_by(user).find_by_url(url) root.nil? ? [] : root.self_and_ancestors end |
.default_layout ⇒ Object
165 166 167 |
# File 'app/models/page.rb', line 165 def default_layout Page.layouts.first end |
.filters ⇒ Object
169 170 171 |
# File 'app/models/page.rb', line 169 def filters %w{ none html textile markdown erb erb+textile } end |
.page_parts ⇒ Object
173 174 175 |
# File 'app/models/page.rb', line 173 def page_parts %w{ body left right header footer } end |
.status_values ⇒ Object
161 162 163 |
# File 'app/models/page.rb', line 161 def status_values ["Draft", "Published", "Review", "Hidden"] end |
.viewable_by(user) ⇒ Object
Scopes
179 180 181 182 183 184 185 186 187 188 189 190 |
# File 'app/models/page.rb', line 179 def viewable_by(user) if PageEngine.class_exists?('Role') && PageEngine.class_exists?('User') if user # This is a bit of a kludge until I can figure out how to get it to work properly in a single sql query includes(:page_roles).where("pages.id in (?) or (page_roles.required_role_id is null and page_roles.excluded_role_id is null)", PageRole.viewable_page_ids_for(user)) else includes(:page_roles).where({ 'page_roles.required_role_id' => nil }) end else scoped end end |
.with_roles(roles) ⇒ Object
192 193 194 195 196 197 198 |
# File 'app/models/page.rb', line 192 def with_roles roles if Extras.class_exists?('Role') includes(:roles).where([ "roles.id IN (?)", roles.join(',') ]) else scoped end end |
.with_url(request, params) ⇒ Object
200 201 202 203 204 205 |
# File 'app/models/page.rb', line 200 def with_url request, params url = request.fullpath url.gsub!(/\?.*/, '') # Strip away anything after the ? as it's not needed where(["pages.permalink = ? or url = ? or (controller = ? and action = ?)", params[:permalink], url, params[:controller], params[:action]]) end |
Instance Method Details
#css_status ⇒ Object
139 140 141 142 |
# File 'app/models/page.rb', line 139 def css_status return "live" if self.published? status.downcase end |
#duplicate ⇒ Object
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
# File 'app/models/page.rb', line 86 def duplicate page = Page.new(self.attributes) page.title += " (copy) #{Time.now.strftime('%Y%m%d_%H%M%S')}" page.permalink = page.permalink + "-copy-#{Time.now.strftime('%Y%m%d-%H%M%S')}" page.save page.move_to_right_of self # Duplicate each of the objects associated with the original # Page parts self.page_parts.each do |page_part| page.page_parts << page_part.duplicate end # Roles if PageEngine.class_exists?('Role') page.required_roles = self.required_roles page.excluded_roles = self.excluded_roles end # Assets if PageEngine.class_exists?('Asset') self.attachables.each do |attachable| page.attachables << attachable.duplicate end end page end |
#is_child_of?(page) ⇒ Boolean
74 75 76 |
# File 'app/models/page.rb', line 74 def is_child_of? page self.parent_id == page.id ? true : false end |
#is_parent_of?(page) ⇒ Boolean
78 79 80 |
# File 'app/models/page.rb', line 78 def is_parent_of? page self.id == page.parent_id ? true : false end |
#is_viewable_by?(user) ⇒ Boolean
115 116 117 118 119 120 121 122 123 124 125 126 |
# File 'app/models/page.rb', line 115 def is_viewable_by? user if PageEngine.class_exists?('Role') if PageEngine.class_exists?('User') && user return true if self.roles.length == 0 self.role_ids.length != (self.role_ids - user.role_ids.uniq).length else self.roles.length == 0 end else true end end |
#lft=(x) ⇒ Object
Override the protected methods of awesome_nested_set so lft and rgt can be set
145 146 147 |
# File 'app/models/page.rb', line 145 def lft=(x) self[:lft] = x end |
#move_children_to_parent ⇒ Object
128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/page.rb', line 128 def move_children_to_parent self.children.each do |child| if self.parent child.move_to_child_of self.parent else child.move_to_root end end self.reload end |
#no_publish_window_set? ⇒ Boolean
58 59 60 |
# File 'app/models/page.rb', line 58 def no_publish_window_set? self.publish_from.nil? && self.publish_to.nil? end |
#number_of_children ⇒ Object
82 83 84 |
# File 'app/models/page.rb', line 82 def number_of_children (self.rgt - self.lft - 1) / 2 end |
#published? ⇒ Boolean
62 63 64 65 66 67 68 |
# File 'app/models/page.rb', line 62 def published? if self.no_publish_window_set? self.status == "Published" else self.publish_from < DateTime.now && self.publish_to > DateTime.now && self.status == "Published" end end |
#rgt=(x) ⇒ Object
149 150 151 |
# File 'app/models/page.rb', line 149 def rgt=(x) self[:rgt] = x end |
#to_param ⇒ Object
70 71 72 |
# File 'app/models/page.rb', line 70 def to_param permalink end |