Class: CamaleonCms::Post
- Inherits:
-
PostDefault
- Object
- ActiveRecord::Base
- CamaleonRecord
- PostDefault
- CamaleonCms::Post
- Includes:
- CategoriesTagsForPosts
- Defined in:
- app/models/camaleon_cms/post.rb
Instance Attribute Summary collapse
-
#show_title_with_parent ⇒ Object
Returns the value of attribute show_title_with_parent.
Attributes inherited from PostDefault
Instance Method Summary collapse
-
#can_commented? ⇒ Boolean
check if the post can be commented sample: @post.can_commented? return Boolean (true/false) to enable comments for current post, use this: post.set_meta(‘has_comments’, ‘1’).
-
#decorator_class ⇒ Object
manage the custom decorators for posts sample: my_post_type.set_option(‘cama_post_decorator_class’, ‘ProductDecorator’) Sample: github.com/owen2345/camaleon-ecommerce/tree/master/app/decorators/.
-
#draft? ⇒ Boolean
check if this is in draft status.
- #draft_child? ⇒ Boolean
-
#full_children ⇒ Object
return all children elements for current post (page hierarchy).
-
#get_layout(posttype = nil) ⇒ Object
return the layout assigned to this post post_type: post type owner of this post.
-
#get_post_type_depre ⇒ Object
return the post type of this post (DEPRECATED).
-
#get_template(posttype = nil) ⇒ Object
return the template assigned to this post verify default template defined in post type post_type: post type owner of this post.
-
#increment_visits! ⇒ Object
increment the counter of visitors.
-
#is_required_picture? ⇒ Boolean
check if is required picture for current post.
-
#manage_comments?(posttype = nil) ⇒ Boolean
check if current post can manage comments return boolean.
-
#manage_content?(posttype = nil) ⇒ Boolean
check if current post can manage content return boolean.
-
#manage_layout?(posttype = nil) ⇒ Boolean
return boolean.
-
#manage_picture?(posttype = nil) ⇒ Boolean
check if current post can manage picture return boolean.
-
#manage_seo?(posttype = nil) ⇒ Boolean
(also: #manage_keywords?)
check if current post permit manage seo attrs has_keywords: used until next version (deprecated to use has_seo) return boolean.
-
#manage_summary?(posttype = nil) ⇒ Boolean
check if current post can manage summary return boolean.
-
#manage_template?(posttype = nil) ⇒ Boolean
check if current post can manage template return boolean.
-
#parents ⇒ Object
return all parents for current page hierarchy ordered bottom to top.
-
#pending? ⇒ Boolean
check if this is in pending status.
-
#published? ⇒ Boolean
check if this post was published.
-
#set_layout(layout_name) ⇒ Object
save the layout name to be used on render this post layout_name: String layout name: my_layout.html.erb => ‘my_layout’.
-
#set_position(new_order_position) ⇒ Object
put a new order position for this post new_order_position: (Integer) position number return nil.
-
#set_setting(key, val) ⇒ Object
define post configuration for current post possible key values (String): has_content, boolean (default true) has_summary, boolean (default true) has_seo, boolean (default true) has_picture, boolean (default true) has_template, boolean (default false) has_comments, boolean (default false) default_layout: (string) (default layout) # this is still used if post type was inactivated layout and overwritten by dropdown in post view default_template: (string) (default template) # this is still used if post type was inactivated template and overwritten by dropdown in post view has_layout: (boolean) (default false) skip_fields: (array) (default empty) array of custom field keys to avoid for this post, sample: [“subtitle”, “icon”] val: value for the setting.
-
#set_settings(settings = {}) ⇒ Object
assign multiple settings.
-
#set_summary(summary) ⇒ Object
save the summary for current post summary: Text String without html.
-
#set_thumb(thumb_url) ⇒ Object
save the thumbnail url for current post thumb_url: String url.
-
#total_comments ⇒ Object
return the quantity of comments for this post TODO comments count to move into cache counter.
-
#total_visits ⇒ Object
return the quantity of visits for this post.
-
#trash? ⇒ Boolean
check if this is in trash status.
Methods included from CategoriesTagsForPosts
#assign_category, #assign_tags, #manage_categories?, #manage_tags?, #unassign_category, #unassign_tags, #update_categories, #update_extra_data, #update_tags
Methods inherited from PostDefault
#author, find_by_slug, #in_nav_menu_items, inherited, #parent, #set_params
Methods included from CustomFieldsRead
#add_custom_field_group, #add_custom_field_to_default_group, #get_field_groups, #get_field_object, #get_field_value, #get_field_values, #get_field_values_hash, #get_fields_grouped, #get_fields_object, #get_user_field_groups, #save_field_value, #set_field_value, #set_field_values, #update_field_value
Methods included from Metas
#delete_meta, #delete_option, #fix_save_metas_options_no_changed, #get_meta, #get_option, #options, #save_metas_options, #save_metas_options_skip, #set_meta, #set_metas, #set_option, #set_options
Methods inherited from CamaleonRecord
#cama_build_cache_key, #cama_fetch_cache, #cama_get_cache, #cama_remove_cache, #cama_set_cache
Instance Attribute Details
#show_title_with_parent ⇒ Object
Returns the value of attribute show_title_with_parent.
43 44 45 |
# File 'app/models/camaleon_cms/post.rb', line 43 def show_title_with_parent @show_title_with_parent end |
Instance Method Details
#can_commented? ⇒ Boolean
check if the post can be commented sample: @post.can_commented? return Boolean (true/false) to enable comments for current post, use this: post.set_meta(‘has_comments’, ‘1’). Note: Parent PostType should be enabled for comments too: post_type.set_option(‘has_comments’, true)
137 138 139 |
# File 'app/models/camaleon_cms/post.rb', line 137 def can_commented? manage_comments? && ('has_comments').to_s == '1' end |
#decorator_class ⇒ Object
manage the custom decorators for posts sample: my_post_type.set_option(‘cama_post_decorator_class’, ‘ProductDecorator’) Sample: github.com/owen2345/camaleon-ecommerce/tree/master/app/decorators/
240 241 242 243 244 245 246 |
# File 'app/models/camaleon_cms/post.rb', line 240 def decorator_class begin post_type.get_option('cama_post_decorator_class', 'CamaleonCms::PostDecorator') rescue StandardError 'CamaleonCms::PostDecorator' end.constantize end |
#draft? ⇒ Boolean
check if this is in draft status
85 86 87 |
# File 'app/models/camaleon_cms/post.rb', line 85 def draft? status == 'draft' || status == 'draft_child' end |
#draft_child? ⇒ Boolean
89 90 91 |
# File 'app/models/camaleon_cms/post.rb', line 89 def draft_child? status == 'draft_child' end |
#full_children ⇒ Object
return all children elements for current post (page hierarchy)
61 62 63 64 65 66 67 |
# File 'app/models/camaleon_cms/post.rb', line 61 def full_children cama_fetch_cache("full_children_#{id}") do res = children.to_a res.each { |c| res += c.full_children } res end end |
#get_layout(posttype = nil) ⇒ Object
return the layout assigned to this post post_type: post type owner of this post
205 206 207 208 209 |
# File 'app/models/camaleon_cms/post.rb', line 205 def get_layout(posttype = nil) return get_option('default_layout') unless manage_layout?(posttype) ('layout', get_option('default_layout') || (posttype || post_type).get_option('default_layout', nil)) end |
#get_post_type_depre ⇒ Object
return the post type of this post (DEPRECATED)
70 71 72 |
# File 'app/models/camaleon_cms/post.rb', line 70 def get_post_type_depre post_types.reorder(nil).first end |
#get_template(posttype = nil) ⇒ Object
return the template assigned to this post verify default template defined in post type post_type: post type owner of this post
214 215 216 217 218 219 |
# File 'app/models/camaleon_cms/post.rb', line 214 def get_template(posttype = nil) return get_option('default_template') unless manage_template?(posttype) ('template', get_option('default_template') || (posttype || post_type).get_option('default_template', nil)) end |
#increment_visits! ⇒ Object
increment the counter of visitors
222 223 224 |
# File 'app/models/camaleon_cms/post.rb', line 222 def increment_visits! ('visits', total_visits + 1) end |
#is_required_picture? ⇒ Boolean
check if is required picture for current post
142 143 144 |
# File 'app/models/camaleon_cms/post.rb', line 142 def is_required_picture? post_type.get_option('is_required_picture', false) end |
#manage_comments?(posttype = nil) ⇒ Boolean
check if current post can manage comments return boolean
129 130 131 |
# File 'app/models/camaleon_cms/post.rb', line 129 def manage_comments?(posttype = nil) get_option('has_comments', (posttype || post_type).get_option('has_comments', false)) end |
#manage_content?(posttype = nil) ⇒ Boolean
check if current post can manage content return boolean
100 101 102 |
# File 'app/models/camaleon_cms/post.rb', line 100 def manage_content?(posttype = nil) get_option('has_content', (posttype || post_type).get_option('has_content', true)) end |
#manage_layout?(posttype = nil) ⇒ Boolean
return boolean
105 106 107 |
# File 'app/models/camaleon_cms/post.rb', line 105 def manage_layout?(posttype = nil) get_option('has_layout', (posttype || post_type).get_option('has_layout', false)) end |
#manage_picture?(posttype = nil) ⇒ Boolean
check if current post can manage picture return boolean
123 124 125 |
# File 'app/models/camaleon_cms/post.rb', line 123 def manage_picture?(posttype = nil) get_option('has_picture', (posttype || post_type).get_option('has_picture', true)) end |
#manage_seo?(posttype = nil) ⇒ Boolean Also known as: manage_keywords?
check if current post permit manage seo attrs has_keywords: used until next version (deprecated to use has_seo) return boolean
186 187 188 |
# File 'app/models/camaleon_cms/post.rb', line 186 def manage_seo?(posttype = nil) get_option('has_seo', get_option('has_keywords', false)) || (posttype || post_type).manage_seo? end |
#manage_summary?(posttype = nil) ⇒ Boolean
check if current post can manage summary return boolean
117 118 119 |
# File 'app/models/camaleon_cms/post.rb', line 117 def manage_summary?(posttype = nil) get_option('has_summary', (posttype || post_type).get_option('has_summary', true)) end |
#manage_template?(posttype = nil) ⇒ Boolean
check if current post can manage template return boolean
111 112 113 |
# File 'app/models/camaleon_cms/post.rb', line 111 def manage_template?(posttype = nil) get_option('has_template', (posttype || post_type).get_option('has_template', true)) end |
#parents ⇒ Object
return all parents for current page hierarchy ordered bottom to top
48 49 50 51 52 53 54 55 56 57 58 |
# File 'app/models/camaleon_cms/post.rb', line 48 def parents cama_fetch_cache("parents_#{id}") do res = [] p = parent while p res << p p = p.parent end res end end |
#pending? ⇒ Boolean
check if this is in pending status
80 81 82 |
# File 'app/models/camaleon_cms/post.rb', line 80 def pending? status == 'pending' end |
#published? ⇒ Boolean
check if this post was published
75 76 77 |
# File 'app/models/camaleon_cms/post.rb', line 75 def published? status == 'published' end |
#set_layout(layout_name) ⇒ Object
save the layout name to be used on render this post layout_name: String layout name: my_layout.html.erb => ‘my_layout’
199 200 201 |
# File 'app/models/camaleon_cms/post.rb', line 199 def set_layout(layout_name) ('layout', layout_name) end |
#set_position(new_order_position) ⇒ Object
put a new order position for this post new_order_position: (Integer) position number return nil
173 174 175 |
# File 'app/models/camaleon_cms/post.rb', line 173 def set_position(new_order_position) update_column('post_order', new_order_position) end |
#set_setting(key, val) ⇒ Object
define post configuration for current post possible key values (String):
has_content, boolean (default true)
has_summary, boolean (default true)
has_seo, boolean (default true)
has_picture, boolean (default true)
has_template, boolean (default false)
has_comments, boolean (default false)
default_layout: (string) (default layout) # this is still used if post type was inactivated layout and overwritten by dropdown in post view
default_template: (string) (default template) # this is still used if post type was inactivated template and overwritten by dropdown in post view
has_layout: (boolean) (default false)
skip_fields: (array) (default empty) array of custom field keys to avoid for this post, sample: ["subtitle", "icon"]
val: value for the setting
159 160 161 |
# File 'app/models/camaleon_cms/post.rb', line 159 def set_setting(key, val) set_option(key, val) end |
#set_settings(settings = {}) ⇒ Object
assign multiple settings
164 165 166 167 168 |
# File 'app/models/camaleon_cms/post.rb', line 164 def set_settings(settings = {}) settings.each do |key, val| set_setting(key, val) end end |
#set_summary(summary) ⇒ Object
save the summary for current post summary: Text String without html
179 180 181 |
# File 'app/models/camaleon_cms/post.rb', line 179 def set_summary(summary) ('summary', summary) end |
#set_thumb(thumb_url) ⇒ Object
save the thumbnail url for current post thumb_url: String url
193 194 195 |
# File 'app/models/camaleon_cms/post.rb', line 193 def set_thumb(thumb_url) ('thumb', thumb_url) end |
#total_comments ⇒ Object
return the quantity of comments for this post TODO comments count to move into cache counter
233 234 235 |
# File 'app/models/camaleon_cms/post.rb', line 233 def total_comments ('comments_count', 0).to_i end |
#total_visits ⇒ Object
return the quantity of visits for this post
227 228 229 |
# File 'app/models/camaleon_cms/post.rb', line 227 def total_visits ('visits', 0).to_i end |
#trash? ⇒ Boolean
check if this is in trash status
94 95 96 |
# File 'app/models/camaleon_cms/post.rb', line 94 def trash? status == 'trash' end |