Class: CamaleonCms::TermTaxonomyDecorator
- Inherits:
-
ApplicationDecorator
- Object
- 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
Same shape as PostDecorator#the_status: markup built by interpolation and rendered through
rawat admin/search.html.erb. -
#the_title(locale = nil) ⇒ Object
return the title for current locale The name is HTML-escaped here (like PostDecorator#the_title) because taxonomy names are plain text yet are rendered through
raw/html_safesinks such as the breadcrumb builder and the nav menu, so escaping at the source prevents stored XSS via category/tag/post_type/site names.
Methods included from CustomFieldsConcern
#render_fields, #the_field, #the_field_grouped, #the_fields, #the_fields_grouped, #the_json_field, #the_json_fields
Instance Method Details
#the_content ⇒ Object
return the content for current locale + shortcodes executed
27 28 29 30 31 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 27 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" }
107 108 109 110 111 112 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 107 def the_edit_link(title = nil, attrs = {}) return '' if h.cama_current_user.blank? attrs = { target: '_blank', style: 'font-size:11px !important;cursor:pointer;' }.merge(attrs) h.link_to(h.safe_join(['→ ', title || h.ct('edit', default: 'Edit')]), the_edit_url, attrs) end |
#the_edit_url ⇒ Object
return edit url for current taxonomy: PostType, PostTag, Category
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 88 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
50 51 52 53 54 55 56 57 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 50 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
116 117 118 119 120 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 116 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
124 125 126 127 128 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 124 def the_parent parent.decorate rescue StandardError nil end |
#the_post(slug_or_id) ⇒ Object
search a post with id (integer) or slug (string)
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 68 def the_post(slug_or_id) return nil if slug_or_id.blank? 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 # rubocop:disable Rails/DynamicFindBy 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: https://edgeguides.rubyonrails.org/active_record_querying.html
63 64 65 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 63 def the_posts h.verify_front_visibility(object.posts) end |
#the_slug ⇒ Object
return the slug for current locale
22 23 24 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 22 def the_slug object.slug.translate(get_locale) end |
#the_status ⇒ Object
Same shape as PostDecorator#the_status: markup built by interpolation and rendered through
raw at admin/search.html.erb. Only I18n strings reach it today, so there is nothing to
exploit here -- escaping at the source is what keeps that true if the interpolated value ever
changes.
37 38 39 40 41 42 43 44 45 46 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 37 def the_status color, label = if status.to_s.to_bool ['success', I18n.t('camaleon_cms.admin.button.actived')] else ['default', I18n.t('camaleon_cms.admin.button.not_actived')] end # rubocop:disable Rails/OutputSafety -- only the escaped label is interpolated into fixed markup "<span class='label label-#{color}'> #{h.h(label)} </span>".html_safe # rubocop:enable Rails/OutputSafety end |
#the_title(locale = nil) ⇒ Object
return the title for current locale
The name is HTML-escaped here (like PostDecorator#the_title) because taxonomy
names are plain text yet are rendered through raw/html_safe sinks such as
the breadcrumb builder and the nav menu, so escaping at the source prevents
stored XSS via category/tag/post_type/site names.
11 12 13 14 15 16 17 18 19 |
# File 'app/decorators/camaleon_cms/term_taxonomy_decorator.rb', line 11 def the_title(locale = nil) r = { title: h.h(object.name.to_s.translate(get_locale(locale))), object: object } begin h.hooks_run('taxonomy_the_title', r) rescue StandardError nil end r[:title] end |