Module: CamaleonCms::CustomFieldsConcern
- Included in:
- NavMenuItemDecorator, PostDecorator, TermTaxonomyDecorator, UserDecorator, WidgetDecorator
- Defined in:
- app/decorators/camaleon_cms/custom_fields_concern.rb
Overview
Camaleon CMS is a content management system
Copyright (C) 2015 by Owen Peredo Diaz
Email: [email protected]
This program is free software: you can redistribute it and/or modify it under the terms of the GNU Affero General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
See the GNU Affero General Public License (GPLv3) for more details.
Instance Method Summary collapse
-
#render_fields ⇒ Object
CUSTOM FIELDS===================================== render as html the custom fields marked for frontend.
-
#the_attribute_field(field_key, default_val = '') ⇒ Object
return custom field content with key field_key (only for type attributes) translated and short codes evaluated like the content default_val: default value returned when this field was not registered.
-
#the_attribute_fields(field_key) ⇒ Object
return custom field contents with key field_key (only for type attributes) translated and short codes evaluated like the content this is for multiple values.
-
#the_field(field_key, default_val = '') ⇒ Object
return custom field content with key field_key translated and short codes evaluated like the content default_val: default value returned when this field was not registered.
-
#the_field!(field_key, default_val = '') ⇒ Object
the same as the_field(..), but this return default value if there is not present.
-
#the_fields(field_key) ⇒ Object
return custom field contents with key field_key translated and short codes evaluated like the content this is for multiple values.
-
#the_fields_grouped(field_keys) ⇒ Object
the same function as get_fields_grouped(..) but this returns translated and shortcodes evaluated.
Instance Method Details
#render_fields ⇒ Object
CUSTOM FIELDS=====================================
render as html the custom fields marked for frontend
12 13 14 15 16 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 12 def render_fields object.cama_fetch_cache("render_fields") do h.controller.render_to_string(partial: "partials/render_custom_field", :locals => {fields: object.get_fields_object(true)}) end end |
#the_attribute_field(field_key, default_val = '') ⇒ Object
return custom field content with key field_key (only for type attributes) translated and short codes evaluated like the content default_val: default value returned when this field was not registered
72 73 74 75 76 77 78 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 72 def the_attribute_field(field_key, default_val = '') r = JSON.parse(object.get_field(field_key, default_val) || '{}').with_indifferent_access r.keys.each do |k| r[k] = h.do_shortcode(r[k].to_s.translate(@_deco_locale), object) end r end |
#the_attribute_fields(field_key) ⇒ Object
return custom field contents with key field_key (only for type attributes) translated and short codes evaluated like the content this is for multiple values
44 45 46 47 48 49 50 51 52 53 54 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 44 def the_attribute_fields(field_key) r = [] object.get_fields(field_key).each do |text| _r = JSON.parse(text || '{}').with_indifferent_access _r.keys.each do |k| _r[k] = h.do_shortcode(_r[k].to_s.translate(@_deco_locale), object) end r << _r end r end |
#the_field(field_key, default_val = '') ⇒ Object
return custom field content with key field_key translated and short codes evaluated like the content default_val: default value returned when this field was not registered
21 22 23 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 21 def the_field(field_key, default_val = '') h.do_shortcode(object.get_field(field_key, default_val).to_s.translate(@_deco_locale), object) end |
#the_field!(field_key, default_val = '') ⇒ Object
the same as the_field(..), but this return default value if there is not present
26 27 28 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 26 def the_field!(field_key, default_val = '') h.do_shortcode(object.get_field!(field_key, default_val).to_s.translate(@_deco_locale), object) end |
#the_fields(field_key) ⇒ Object
return custom field contents with key field_key translated and short codes evaluated like the content this is for multiple values
33 34 35 36 37 38 39 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 33 def the_fields(field_key) r = [] object.get_fields(field_key).each do |text| r << h.do_shortcode(text.to_s.translate(@_deco_locale), object) end r end |
#the_fields_grouped(field_keys) ⇒ Object
the same function as get_fields_grouped(..) but this returns translated and shortcodes evaluated
57 58 59 60 61 62 63 64 65 66 67 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 57 def the_fields_grouped(field_keys) res = [] object.get_fields_grouped(field_keys).each do |_group| group = {}.with_indifferent_access _group.keys.each do |k| group[k] = _group[k].map{|v| h.do_shortcode(v.to_s.translate(@_deco_locale), object) } end res << group end res end |