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
-
#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
#fetch_target_entry(permalink) ⇒ Object
Find the entry both specified by the target klass and identified by the permalink
101 102 103 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 101 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.
86 87 88 89 90 91 92 93 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 86 def target_entry_name if self.target_klass_name =~ /^Locomotive::Entry([a-z0-9]+)$/ @content_type ||= self.site.content_types.find($1) @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
41 42 43 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 41 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.
50 51 52 53 54 55 56 57 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 50 def target_klass_slug if self.target_klass_name =~ /^Locomotive::Entry([a-z0-9]+)$/ @content_type ||= self.site.content_types.find($1) @content_type.slug else nil end end |
#target_klass_slug=(slug) ⇒ Object
Set the target klass from the slug of a content type
65 66 67 68 69 70 |
# File 'app/models/locomotive/extensions/page/templatized.rb', line 65 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 |