Class: CamaleonCms::PostType
- Inherits:
-
TermTaxonomy
- Object
- ActiveRecord::Base
- CamaleonRecord
- TermTaxonomy
- CamaleonCms::PostType
- Defined in:
- app/models/camaleon_cms/post_type.rb
Constant Summary
Constants inherited from TermTaxonomy
TermTaxonomy::TRANSLATION_TAG_HIDE_MAP, TermTaxonomy::TRANSLATION_TAG_HIDE_REGEX, TermTaxonomy::TRANSLATION_TAG_RESTORE_MAP, TermTaxonomy::TRANSLATION_TAG_RESTORE_REGEX
Instance Method Summary collapse
-
#add_post(args) ⇒ Object
add a post for current model title: title for post, => required content: html text content, => required thumb: image url, => default (empty).
-
#contents_route_format ⇒ Object
return the configuration of routes for post contents.
-
#contents_route_formats ⇒ Object
return all available route formats of this post type for content posts.
-
#default_category ⇒ Object
return default category for this post type only return a category for post types that manage categories.
-
#full_categories ⇒ Object
select full_categories for the post type, include all children categories.
-
#manage_categories? ⇒ Boolean
check if current post type manage categories.
-
#manage_hierarchy? ⇒ Boolean
verify if this post_type support for page hierarchy (parents).
-
#manage_seo? ⇒ Boolean
check if this post type permit to manage seo attrs in posts.
-
#manage_tags? ⇒ Boolean
check if this post type manage post tags.
-
#set_setting(key, value) ⇒ Object
set or update a setting for this post type.
-
#set_settings(settings = {}) ⇒ Object
assign settings for this post type default values: { has_category: false, has_tags: false, has_summary: true, has_content: true, has_comments: false, has_picture: true, has_template: true, has_seo: true, not_deleted: false, has_layout: false, default_layout: ”, contents_route_format: ‘post’ }.
-
#show_for_admin_menu? ⇒ Boolean
check if this post type is shown on admin -> contents -> menu.
-
#toggle_show_for_admin_menu(flag) ⇒ Object
hide or show this post type on admin -> contents -> menu true => enable, false => disable.
Methods inherited from TermTaxonomy
#children, #in_nav_menu_items, inherited, #skip_slug_validation?
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, #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 Method Details
#add_post(args) ⇒ Object
add a post for current model
title: title for post, => required
content: html text content, => required
thumb: image url, => default (empty). check https://camaleon.website/api-methods.html#section_fileuploads
categories: [1,3,4,5], => default (empty)
tags: String comma separated, => default (empty)
slug: string key for post, => default (empty)
summary: String resume (optional) => default (empty)
post_order: Integer to define the order position in the list (optional)
fields: Hash of values for custom fields, sample => fields: {subtitle: 'abc', icon: 'test' } (optional)
settings: Hash of post settings, sample => settings:
{has_content: false, has_summary: true, default_layout: 'my_layout', default_template: 'my_template' } (optional, see more in post.set_setting(...))
data_metas: {template: "", layout: ""}
sample: my_posttype.add_post(title: “My Title”, post_order: 5, content: ‘lorem_ipsum’, settings: “home/counters”, has_content: false, has_seo: false, skip_fields: [“sub_tite”, ‘banner’], fields: true, bg: ‘’)
More samples here: https://gist.github.com/owen2345/eba9691585ed78ad6f7b52e9591357bf
return created post if it was created, else return errors
117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
# File 'app/models/camaleon_cms/post_type.rb', line 117 def add_post(args) _fields = args.delete(:fields) _settings = args.delete(:settings) _summary = args.delete(:summary) _order_position = args.delete(:order_position) args[:data_categories] = _categories = args.delete(:categories) args[:data_tags] = args.delete(:tags) _thumb = args.delete(:thumb) p = posts.new(args) p.slug = site.get_valid_post_slug(p.title.parameterize) unless p.slug.present? if p.save! _settings.each { |k, v| p.set_setting(k, v) } if _settings.present? p.set_position(_order_position) if _order_position.present? p.set_summary(_summary) if _summary.present? p.set_thumb(_thumb) if _thumb.present? _fields.each { |k, v| p.save_field_value(k, v) } if _fields.present? p.decorate else p.errors end end |
#contents_route_format ⇒ Object
return the configuration of routes for post contents
152 153 154 |
# File 'app/models/camaleon_cms/post_type.rb', line 152 def contents_route_format get_option('contents_route_format', 'post') end |
#contents_route_formats ⇒ Object
return all available route formats of this post type for content posts
140 141 142 143 144 145 146 147 148 149 |
# File 'app/models/camaleon_cms/post_type.rb', line 140 def contents_route_formats { 'post_of_post_type' => '<code>/group/:post_type_id-:title/:slug</code><br> (Sample: https://localhost.com/group/17-services/myservice.html)', 'post_of_category' => '<code>/category/:category_id-:title/:slug</code><br> (Sample: https://localhost.com/category/17-services/myservice.html)', 'post_of_category_post_type' => '<code>/:post_type_title/category/:category_id-:title/:slug</code><br> (Sample: https://localhost.com/services/category/17-services/myservice.html)', 'post_of_posttype' => '<code>/:post_type_title/:slug</code><br> (Sample: https://localhost.com/services/myservice.html)', 'post' => '<code>/:slug</code><br> (Sample: https://localhost.com/myservice.html)', 'hierarchy_post' => '<code>/:parent1_slug/:parent2_slug/.../:slug</code><br> (Sample: https://localhost.com/item-1/item-1-1/item-111.html)' } end |
#default_category ⇒ Object
return default category for this post type only return a category for post types that manage categories
90 91 92 93 94 95 96 97 98 99 |
# File 'app/models/camaleon_cms/post_type.rb', line 90 def default_category return unless manage_categories? cat = categories.find_by_slug('uncategorized') unless cat cat = categories.create({ name: 'Uncategorized', slug: 'uncategorized', parent_id: id }) cat.set_option('not_deleted', true) end cat end |
#full_categories ⇒ Object
select full_categories for the post type, include all children categories
84 85 86 |
# File 'app/models/camaleon_cms/post_type.rb', line 84 def full_categories CamaleonCms::Category.where(site_id: site_id, post_type_id: id) end |
#manage_categories? ⇒ Boolean
check if current post type manage categories
32 33 34 |
# File 'app/models/camaleon_cms/post_type.rb', line 32 def manage_categories? [:has_category] || [:has_single_category] end |
#manage_hierarchy? ⇒ Boolean
verify if this post_type support for page hierarchy (parents)
157 158 159 |
# File 'app/models/camaleon_cms/post_type.rb', line 157 def manage_hierarchy? get_option('has_parent_structure', false) end |
#manage_seo? ⇒ Boolean
check if this post type permit to manage seo attrs in posts
53 54 55 |
# File 'app/models/camaleon_cms/post_type.rb', line 53 def manage_seo? get_option('has_seo', get_option('has_keywords', true)) end |
#manage_tags? ⇒ Boolean
check if this post type manage post tags
48 49 50 |
# File 'app/models/camaleon_cms/post_type.rb', line 48 def [:has_tags] end |
#set_setting(key, value) ⇒ Object
set or update a setting for this post type
79 80 81 |
# File 'app/models/camaleon_cms/post_type.rb', line 79 def set_setting(key, value) set_option(key, value) end |
#set_settings(settings = {}) ⇒ Object
assign settings for this post type default values:
has_category: false,
has_tags: false,
has_summary: true,
has_content: true,
has_comments: false,
has_picture: true,
has_template: true,
has_seo: true,
not_deleted: false,
has_layout: false,
default_layout: '',
contents_route_format: 'post'
72 73 74 75 76 |
# File 'app/models/camaleon_cms/post_type.rb', line 72 def set_settings(settings = {}) settings.each do |key, val| set_option(key, val) end end |
#show_for_admin_menu? ⇒ Boolean
check if this post type is shown on admin -> contents -> menu
43 44 45 |
# File 'app/models/camaleon_cms/post_type.rb', line 43 def term_group.nil? end |
#toggle_show_for_admin_menu(flag) ⇒ Object
hide or show this post type on admin -> contents -> menu true => enable, false => disable
38 39 40 |
# File 'app/models/camaleon_cms/post_type.rb', line 38 def (flag) update(term_group: flag == true ? nil : -1) end |