Module: Locomotive::Extensions::Page::Templatized
- Extended by:
- ActiveSupport::Concern
- Included in:
- Page
- Defined in:
- app/models/locomotive/extensions/page/templatized.rb
Instance Method Summary collapse
-
#content_type ⇒ Object
Return the content type specified by the target_klass_name property.
-
#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.
36 37 38 39 40 41 42 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 36 def content_type if self.target_klass_name =~ /^Locomotive::ContentEntry([a-z0-9]+)$/ @content_type ||= self.site.content_types.find($1) rescue nil 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.
118 119 120 121 122 123 124 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 118 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
107 108 109 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 107 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.
93 94 95 96 97 98 99 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 93 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
53 54 55 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 53 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.
62 63 64 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 62 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
72 73 74 75 76 77 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 72 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 |