Module: CamaleonCms::CustomFieldsConcern

Included in:
NavMenuItemDecorator, PostDecorator, TermTaxonomyDecorator, UserDecorator, WidgetDecorator
Defined in:
app/decorators/camaleon_cms/custom_fields_concern.rb

Instance Method Summary collapse

Instance Method Details

#render_fieldsObject

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_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



64
65
66
67
68
69
70
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 64

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



36
37
38
39
40
41
42
43
44
45
46
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 36

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



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!(field_key, default_val = '') ⇒ Object

the same as the_field(..), but this return default value if there is not present



18
19
20
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 18

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



25
26
27
28
29
30
31
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 25

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



49
50
51
52
53
54
55
56
57
58
59
# File 'app/decorators/camaleon_cms/custom_fields_concern.rb', line 49

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