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
#_id, #ability?, #after_initialize, #errors, #formatted_time, getters_or_setters_to_hash, getters_to_hash, #html_view?, #include_errors?, setters_to_hash, #true
Methods included from Presentable
#after_initialize, #as_json, #attributes=, #getters, #initialize, #property_options, #setters
Instance Method Details
#class_name=(value) ⇒ Object
55 56 57 58 59 60 61 62 63 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 55 def class_name=(value) if value =~ /^Locomotive::ContentEntry/ 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
51 52 53 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 51 def class_slug self.content_type.class_name_to_content_type(self.__source.class_name).try(:slug) rescue ::Mongoid::Errors::DocumentNotFound end |
#content_type ⇒ Object
other methods ##
67 68 69 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 67 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 |
#raw_select_options ⇒ Object
other getters / setters ##
30 31 32 33 34 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 30 def self.__source..collect do |option| { id: option._id, name: option.name_translations, position: position } end end |
#raw_select_options=(values) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 36 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
71 72 73 |
# File 'app/presenters/locomotive/content_field_presenter.rb', line 71 def site self.content_type.site end |