Class: Locomotive::ContentFieldPresenter

Inherits:
BasePresenter show all
Defined in:
app/presenters/locomotive/content_field_presenter.rb

Instance Attribute Summary

Attributes inherited from BasePresenter

#ability, #depth

Instance Method Summary collapse

Methods inherited from BasePresenter

#ability?, #after_initialize, getters_to_hash, #id, setters_to_hash

Methods included from Presentable

#after_initialize, #as_json, #attributes=, #getters, #initialize, #property_options, #setters

Instance Method Details

#class_name=(value) ⇒ Object



50
51
52
53
54
55
56
57
58
# File 'app/presenters/locomotive/content_field_presenter.rb', line 50

def class_name=(value)
  if value =~ /^Locomotive::Entry/
    self.source.class_name = value
  else
    if content_type = self.site.content_types.where(:slug => value).first
      self.source.class_name = content_type.entries_class_name
    end
  end
end

#class_slugObject



46
47
48
# File 'app/presenters/locomotive/content_field_presenter.rb', line 46

def class_slug
  self.content_type.class_name_to_content_type(self.source.class_name).try(:slug)
end

#content_typeObject

other methods ##



62
63
64
# File 'app/presenters/locomotive/content_field_presenter.rb', line 62

def content_type
  self.source.content_type
end

#nameObject

properties ##



6
# File 'app/presenters/locomotive/content_field_presenter.rb', line 6

properties  :name, :label, :type, :hint, :required, :localized, :position

#raw_select_optionsObject

other getters / setters ##



25
26
27
28
29
# File 'app/presenters/locomotive/content_field_presenter.rb', line 25

def raw_select_options
  self.source.select_options.collect do |option|
    { :id => option._id, :name => option.name_translations, :position => position }
  end
end

#raw_select_options=(values) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'app/presenters/locomotive/content_field_presenter.rb', line 31

def raw_select_options=(values)
  values.each do |attributes|
    # translations ?
    if (name = attributes['name']).is_a?(Hash)
      translations = attributes['name_translations'] = attributes.delete('name')
      name = translations[self.site.default_locale]
    end

    option = self.source.select_options.where(:name => name).first
    option ||= self.source.select_options.build

    option.attributes = attributes
  end
end

#siteObject



66
67
68
# File 'app/presenters/locomotive/content_field_presenter.rb', line 66

def site
  self.content_type.site
end