Module: Locomotive::Concerns::Page::Templatized
- Extended by:
- ActiveSupport::Concern
- Included in:
- Page
- Defined in:
- app/models/locomotive/concerns/page/templatized.rb
Instance Method Summary collapse
-
#content_type ⇒ Object
Return the content type specified by the target_klass_name property.
-
#content_type_id ⇒ Object
Return the id of the content type specified by the target_klass_name property.
-
#content_type_with_main_attributes ⇒ Hash
Return the main information about the related content type.
-
#fetch_target_entries(conditions = {}) ⇒ Object
Find all the ordered entries of the target klass filtered or not by the conditions passed in parameter.
-
#fetch_target_entry(permalink) ⇒ Object
Find the entry both specified by the target klass and identified by the permalink.
-
#target_entry_name ⇒ String
Give the name which can be used in a liquid template in order to reference an entry.
-
#target_klass ⇒ Class
Return the class specified by the target_klass_name property.
-
#target_klass_slug ⇒ String
Return the slug related to the target_klass.
-
#target_klass_slug=(slug) ⇒ Object
Set the target klass from the slug of a content type.
Instance Method Details
#content_type ⇒ Object
Return the content type specified by the target_klass_name property.
48 49 50 51 52 53 54 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 48 def content_type if id = self.content_type_id @content_type ||= self.site.content_types.find(id) rescue nil else nil end end |
#content_type_id ⇒ Object
Return the id of the content type specified by the target_klass_name property.
36 37 38 39 40 41 42 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 36 def content_type_id if self.target_klass_name =~ /^Locomotive::ContentEntry([a-z0-9]+)$/ $1 else nil end end |
#content_type_with_main_attributes ⇒ Hash
Return the main information about the related content type
60 61 62 63 64 65 66 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 60 def content_type_with_main_attributes if id = self.content_type_id content_type = self.site.content_types.where(_id: id).only(:name, :slug).first else nil end end |
#fetch_target_entries(conditions = {}) ⇒ Object
Find all the ordered entries of the target klass filtered or not by the conditions passed in parameter.
142 143 144 145 146 147 148 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 142 def fetch_target_entries(conditions = {}) if self.content_type self.content_type.ordered_entries(where: conditions) else [] end end |
#fetch_target_entry(permalink) ⇒ Object
Find the entry both specified by the target klass and identified by the permalink
131 132 133 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 131 def fetch_target_entry(permalink) target_klass.find_by_permalink(permalink) end |
#target_entry_name ⇒ String
Give the name which can be used in a liquid template in order to reference an entry. It uses the slug property if the target klass is a Locomotive content type or the class name itself for the other classes.
117 118 119 120 121 122 123 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 117 def target_entry_name if self.content_type self.content_type.slug.singularize else self.target_klass_name.underscore end end |
#target_klass ⇒ Class
Return the class specified by the target_klass_name property
77 78 79 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 77 def target_klass target_klass_name.constantize end |
#target_klass_slug ⇒ String
Return the slug related to the target_klass. In other words, it returns the slug of the target content type.
86 87 88 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 86 def target_klass_slug self.content_type.try(:slug) end |
#target_klass_slug=(slug) ⇒ Object
Set the target klass from the slug of a content type
96 97 98 99 100 101 |
# File 'app/models/locomotive/concerns/page/templatized.rb', line 96 def target_klass_slug=(slug) if @content_type = self.site.content_types.where(slug: slug).first self.target_klass_name = @content_type.entries_class_name end @content_type end |