Class: Locomotive::ContentFieldPresenter
- Inherits:
-
BasePresenter
- Object
- BasePresenter
- Locomotive::ContentFieldPresenter
- Defined in:
- app/presenters/locomotive/content_field_presenter.rb
Instance Attribute Summary
Attributes inherited from BasePresenter
Instance Method Summary collapse
- #class_name=(value) ⇒ Object
- #class_slug ⇒ Object
-
#content_type ⇒ Object
other methods ##.
-
#name ⇒ Object
properties ##.
-
#raw_select_options ⇒ Object
other getters / setters ##.
- #raw_select_options=(values) ⇒ Object
- #site ⇒ Object
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_slug ⇒ Object
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_type ⇒ Object
other methods ##
62 63 64 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 62 def content_type self.source.content_type end |
#name ⇒ Object
properties ##
6 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 6 properties :name, :label, :type, :hint, :required, :localized, :position |
#raw_select_options ⇒ Object
other getters / setters ##
25 26 27 28 29 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 25 def self.source..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 (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..where(:name => name).first option ||= self.source..build option.attributes = attributes end end |
#site ⇒ Object
66 67 68 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 66 def site self.content_type.site end |