Class: CamaleonCms::CategoryDecorator
- Inherits:
-
TermTaxonomyDecorator
- Object
- TermTaxonomyDecorator
- CamaleonCms::CategoryDecorator
- Defined in:
- app/decorators/camaleon_cms/category_decorator.rb
Instance Method Summary collapse
-
#generate_breadcrumb(add_post_type = true, is_parent = false) ⇒ Object
--------------------- add_post_type: true/false to include post type link is_parent: true/false (internal control).
-
#the_categories ⇒ Object
return all children categories for the current category (active_record) filtered by permissions + hidden posts + roles + etc...
-
#the_category(slug_or_id) ⇒ Object
return a child category from this category with id (integer) or by slug (string).
-
#the_edit_url ⇒ Object
return edit url for this category.
-
#the_post_type ⇒ Object
return the post type of this post tag.
-
#the_thumb_url(default = nil) ⇒ Object
return thumbnail for this post type default: if thumbnail is not present, will render default.
-
#the_url(*args) ⇒ Object
return the public url for this category.
Instance Method Details
#generate_breadcrumb(add_post_type = true, is_parent = false) ⇒ Object
add_post_type: true/false to include post type link is_parent: true/false (internal control)
40 41 42 43 44 45 46 47 48 |
# File 'app/decorators/camaleon_cms/category_decorator.rb', line 40 def (add_post_type = true, is_parent = false) _parent = object.parent if _parent.present? _parent.decorate.(add_post_type, true) else object.post_type_parent.decorate.(add_post_type, true) end h.(the_title, is_parent ? the_url : nil) end |
#the_categories ⇒ Object
return all children categories for the current category (active_record) filtered by permissions + hidden posts + roles + etc... in return object, you can add custom where's or pagination like here: https://edgeguides.rubyonrails.org/active_record_querying.html
26 27 28 |
# File 'app/decorators/camaleon_cms/category_decorator.rb', line 26 def the_categories object.children end |
#the_category(slug_or_id) ⇒ Object
return a child category from this category with id (integer) or by slug (string)
31 32 33 34 35 |
# File 'app/decorators/camaleon_cms/category_decorator.rb', line 31 def the_category(slug_or_id) return object.categories.where(id: slug_or_id).first if slug_or_id.is_a?(Integer) object.categories.find_by_slug(slug_or_id) if slug_or_id.is_a?(String) # rubocop:disable Rails/DynamicFindBy end |
#the_edit_url ⇒ Object
return edit url for this category
18 19 20 |
# File 'app/decorators/camaleon_cms/category_decorator.rb', line 18 def the_edit_url h.edit_cama_admin_post_type_category_url(object.post_type.id, object) end |
#the_post_type ⇒ Object
return the post type of this post tag
58 59 60 |
# File 'app/decorators/camaleon_cms/category_decorator.rb', line 58 def the_post_type object.post_type.decorate end |
#the_thumb_url(default = nil) ⇒ Object
return thumbnail for this post type default: if thumbnail is not present, will render default
52 53 54 55 |
# File 'app/decorators/camaleon_cms/category_decorator.rb', line 52 def the_thumb_url(default = nil) th = object.get_option('thumb') th.present? ? th : (default || h.asset_path('camaleon_cms/category-icon.png')) end |
#the_url(*args) ⇒ Object
return the public url for this category
6 7 8 9 10 11 12 13 14 15 |
# File 'app/decorators/camaleon_cms/category_decorator.rb', line 6 def the_url(*args) args = args. args[:category_id] = the_id args[:label] = I18n.t('routes.category', default: 'category') args[:title] = the_title.parameterize.presence || the_slug args[:locale] = @_deco_locale unless args.include?(:locale) args[:format] = args[:format] || 'html' as_path = args.delete(:as_path) h.cama_url_to_fixed("cama_category_#{as_path.present? ? 'path' : 'url'}", args) end |