Module: CamaleonCms::CustomFieldsConcern
- Included in:
- NavMenuItemDecorator, PostDecorator, TermTaxonomyDecorator, UserDecorator, UserRoleDecorator, WidgetDecorator
- Defined in:
- app/decorators/camaleon_cms/custom_fields_concern.rb
Instance Method Summary collapse
-
#render_fields ⇒ Object
CUSTOM FIELDS===================================== render as html the custom fields marked for frontend.
-
#the_field(field_key, default_val = '') ⇒ Object
(also: #the_field!)
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_grouped(field_key, is_json_format = false, is_multiple = false) ⇒ Object
the same function as get_fields_grouped(..) but this returns translated and shortcodes evaluated.
-
#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, is_json_format = false, single_value = false) ⇒ Object
the same function as get_fields_grouped(..) but this returns translated and shortcodes evaluated.
-
#the_json_field(field_key, default_val = '') ⇒ Object
(also: #the_attribute_field)
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_json_fields(field_key) ⇒ Object
(also: #the_attribute_fields)
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.
Instance Method Details
#render_fields ⇒ Object
CUSTOM FIELDS=====================================
render as html the custom fields marked for frontend
4 5 6 7 8 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 4 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_field(field_key, default_val = '') ⇒ Object Also known as: the_field!
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
13 14 15 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 13 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_grouped(field_key, is_json_format = false, is_multiple = false) ⇒ Object
the same function as get_fields_grouped(..) but this returns translated and shortcodes evaluated
48 49 50 51 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 48 def the_field_grouped(field_key, is_json_format = false, is_multiple = false) the_fields_grouped([field_key], is_json_format).map{|v| is_multiple ? v.values.first : v.values.try(:first).try(:first) } # the_fields_grouped([field_key], is_json_format).map{|v| is_multiple ? v.values.first : v.values.first } 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
21 22 23 24 25 26 27 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 21 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, is_json_format = false, single_value = false) ⇒ Object
the same function as get_fields_grouped(..) but this returns translated and shortcodes evaluated
30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 30 def the_fields_grouped(field_keys, is_json_format = false, single_value = false) res = [] object.get_fields_grouped(field_keys).each do |_group| group = {}.with_indifferent_access _group.keys.each do |k| if is_json_format group[k] = _group[k].map{|v| parse_html_json(v) } else group[k] = _group[k].map{|v| h.do_shortcode(v.to_s.translate(@_deco_locale), object) } end group[k] = group[k].first if single_value end res << group end res end |
#the_json_field(field_key, default_val = '') ⇒ Object Also known as: the_attribute_field
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
68 69 70 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 68 def the_json_field(field_key, default_val = '') parse_html_json(object.get_field(field_key, default_val)) end |
#the_json_fields(field_key) ⇒ Object Also known as: the_attribute_fields
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
56 57 58 59 60 61 62 |
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 56 def the_json_fields(field_key) r = [] object.get_fields(field_key).each do |text| r << parse_html_json(text) end r end |