Class: CamaleonCms::TermTaxonomyDecorator
- Inherits:
-
ApplicationDecorator
- Object
- Draper::Decorator
- ApplicationDecorator
- CamaleonCms::TermTaxonomyDecorator
- Includes:
- CustomFieldsConcern
- Defined in:
- app/decorators/camaleon_cms/term_taxonomy_decorator.rb
Direct Known Subclasses
CategoryDecorator, PluginDecorator, PostTagDecorator, PostTypeDecorator, SiteDecorator, ThemeDecorator
Instance Method Summary collapse
-
#the_content ⇒ Object
return the content for current locale + shortcodes executed.
-
#the_edit_link(title = nil, attrs = { }) ⇒ Object
create the html link with edit link return html link attrs: Hash of link tag attributes, sample: {id: “myid”, class: “sss” }.
-
#the_edit_url ⇒ Object
return edit url for current taxonomy: PostType, PostTag, Category.
-
#the_excerpt(qty_chars = 200) ⇒ Object
return excerpt for this post type qty_chars: total or characters maximum.
-
#the_owner ⇒ Object
return the user owner of this item sample: my_item.the_owner.the_url.
-
#the_parent ⇒ Object
return the parent item of this item sample: my_item.the_parent.the_url.
-
#the_post(slug_or_id) ⇒ Object
search a post with id (integer) or slug (string).
-
#the_posts ⇒ Object
———————- filters return all posts for this model (active_record) filtered by permissions + hidden posts + roles + etc…
-
#the_slug ⇒ Object
return the slug for current locale.
- #the_status ⇒ Object
-
#the_title(locale = nil) ⇒ Object
return the title for current locale.
Methods included from CustomFieldsConcern
#render_fields, #the_attribute_field, #the_attribute_fields, #the_field, #the_field!, #the_fields, #the_fields_grouped
Methods inherited from ApplicationDecorator
#_calc_locale, #get_locale, #set_decoration_locale, #the_breadcrumb, #the_created_at, #the_id, #the_keywords, #the_updated_at
Methods included from MetasDecoratorMethods
Instance Method Details
#the_content ⇒ Object
return the content for current locale + shortcodes executed
18 19 20 21 22 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 18 def the_content r = {content: object.description.to_s.translate(get_locale), object: object} h.hooks_run("taxonomy_the_content", r) h.do_shortcode(r[:content], self) end |
#the_edit_link(title = nil, attrs = { }) ⇒ Object
create the html link with edit link return html link attrs: Hash of link tag attributes, sample: {id: “myid”, class: “sss” }
74 75 76 77 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 74 def the_edit_link(title = nil, attrs = { }) attrs = {target: "_blank", style: "font-size:11px !important;cursor:pointer;"}.merge(attrs) h.link_to("→ #{title || h.ct("edit", default: 'Edit')}".html_safe, the_edit_url, attrs) end |
#the_edit_url ⇒ Object
return edit url for current taxonomy: PostType, PostTag, Category
56 57 58 59 60 61 62 63 64 65 66 67 68 69 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 56 def the_edit_url link = "" case object.class.name when "CamaleonCms::PostType" link = h.edit_cama_admin_settings_post_type_url(object) when "CamaleonCms::Category" link = h.edit_cama_admin_post_type_category_url(object.post_type.id, object) when "CamaleonCms::PostTag" link = h.edit_cama_admin_post_type_post_tag_url(object.post_type.id, object) when "CamaleonCms::Site" link = h.cama_admin_settings_site_url end link end |
#the_excerpt(qty_chars = 200) ⇒ Object
return excerpt for this post type qty_chars: total or characters maximum
34 35 36 37 38 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 34 def the_excerpt(qty_chars = 200) r = {content: object.description.to_s.translate(get_locale)..gsub(/ |\n/, " ").truncate(qty_chars), object: object} h.hooks_run("taxonomy_the_excerpt", r) r[:content] end |
#the_owner ⇒ Object
return the user owner of this item sample: my_item.the_owner.the_url
81 82 83 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 81 def the_owner owner.decorate rescue nil end |
#the_parent ⇒ Object
return the parent item of this item sample: my_item.the_parent.the_url
87 88 89 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 87 def the_parent parent.decorate rescue nil end |
#the_post(slug_or_id) ⇒ Object
search a post with id (integer) or slug (string)
49 50 51 52 53 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 49 def the_post(slug_or_id) return nil unless slug_or_id.present? return object.posts.where(id: slug_or_id).first.decorate rescue nil if slug_or_id.is_a?(Integer) return object.posts.find_by_slug(slug_or_id).decorate rescue nil if slug_or_id.is_a?(String) end |
#the_posts ⇒ Object
———————- filters return all posts for this model (active_record) filtered by permissions + hidden posts + roles + etc… in return object, you can add custom where’s or pagination like here: edgeguides.rubyonrails.org/active_record_querying.html
44 45 46 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 44 def the_posts h.verify_front_visibility(object.posts) end |
#the_slug ⇒ Object
return the slug for current locale
13 14 15 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 13 def the_slug object.slug.translate(get_locale) end |
#the_status ⇒ Object
24 25 26 27 28 29 30 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 24 def the_status if status.to_s.to_bool "<span class='label label-success'> #{I18n.t('camaleon_cms.admin.button.actived')} </span>" else "<span class='label label-default'> #{I18n.t('camaleon_cms.admin.button.not_actived')} </span>" end end |
#the_title(locale = nil) ⇒ Object
return the title for current locale
6 7 8 9 10 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 6 def the_title(locale = nil) r = {title: object.name.translate(get_locale(locale)), object: object} h.hooks_run("taxonomy_the_title", r) rescue nil # avoid error for command the_url for categories r[:title] end |