class Locomotive::Steam::Middlewares::TemplatizedPage
Public Instance Methods
_call()
click to toggle source
# File lib/locomotive/steam/middlewares/templatized_page.rb, line 8 def _call if page && page.templatized? set_content_entry! end end
Protected Instance Methods
content_entry_repository()
click to toggle source
# File lib/locomotive/steam/middlewares/templatized_page.rb, line 51 def content_entry_repository services.repositories.content_entry end
content_type_repository()
click to toggle source
# File lib/locomotive/steam/middlewares/templatized_page.rb, line 47 def content_type_repository services.repositories.content_type end
fetch_content_entry(slug)
click to toggle source
# File lib/locomotive/steam/middlewares/templatized_page.rb, line 36 def fetch_content_entry(slug) if type = content_type_repository.find(page.content_type_id) # don't accept a non localized entry in a locale other than the default one return nil if type.localized_names.count == 0 && locale.to_s != default_locale.to_s decorate_entry(content_entry_repository.with(type).by_slug(slug)) else nil end end
page_not_found()
click to toggle source
# File lib/locomotive/steam/middlewares/templatized_page.rb, line 55 def page_not_found services.page_finder.find('404') end
set_content_entry!()
click to toggle source
# File lib/locomotive/steam/middlewares/templatized_page.rb, line 16 def set_content_entry! # extract the slug of the content entry %r(^#{page.fullpath.gsub(Locomotive::Steam::WILDCARD, '([^\/]+)')}$) =~ path if entry = fetch_content_entry($1 || params['id']) # the entry will be available in the template under different keys ['content_entry', 'entry', entry.content_type.slug.singularize].each do |key| liquid_assigns[key] = entry end env['steam.content_entry'] = page.content_entry = entry # log it log "Found content entry: #{entry._label}" else url = services.url_builder.url_for(page_not_found, locale) redirect_to url, 302 end end