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_field, #the_field_grouped, #the_fields, #the_fields_grouped, #the_json_field, #the_json_fields
Methods inherited from ApplicationDecorator
#_calc_locale, #get_locale, #marshal_dump, #marshal_load, #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
23 24 25 26 27 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 23 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” }
96 97 98 99 100 101 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 96 def the_edit_link(title = nil, attrs = {}) return '' unless h.cama_current_user.present? 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
77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 77 def the_edit_url args = h.cama_current_site_host_port({}) case object.class.name when 'CamaleonCms::PostType' h.edit_cama_admin_settings_post_type_url(object, args) when 'CamaleonCms::Category' h.edit_cama_admin_post_type_category_url(object.post_type.id, object, args) when 'CamaleonCms::PostTag' h.edit_cama_admin_post_type_post_tag_url(object.post_type.id, object, args) when 'CamaleonCms::Site' h.cama_admin_settings_site_url(args) else '' end end |
#the_excerpt(qty_chars = 200) ⇒ Object
return excerpt for this post type qty_chars: total or characters maximum
39 40 41 42 43 44 45 46 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 39 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
105 106 107 108 109 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 105 def the_owner owner.decorate rescue StandardError nil end |
#the_parent ⇒ Object
return the parent item of this item sample: my_item.the_parent.the_url
113 114 115 116 117 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 113 def the_parent parent.decorate rescue StandardError nil end |
#the_post(slug_or_id) ⇒ Object
search a post with id (integer) or slug (string)
57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 57 def the_post(slug_or_id) return nil unless slug_or_id.present? if slug_or_id.is_a?(Integer) begin return object.posts.where(id: slug_or_id).first.decorate rescue StandardError nil end end return unless slug_or_id.is_a?(String) begin object.posts.find_by_slug(slug_or_id).decorate rescue StandardError nil end 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
52 53 54 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 52 def the_posts h.verify_front_visibility(object.posts) end |
#the_slug ⇒ Object
return the slug for current locale
18 19 20 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 18 def the_slug object.slug.translate(get_locale) end |
#the_status ⇒ Object
29 30 31 32 33 34 35 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 29 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
7 8 9 10 11 12 13 14 15 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 7 def the_title(locale = nil) r = { title: object.name.translate(get_locale(locale)), object: object } begin h.hooks_run('taxonomy_the_title', r) rescue StandardError nil end r[:title] end |