Sha256: 025bb372b0afb016f57349b501789fdd878714d6674a7e7f75384234d02d26a0
Contents?: true
Size: 1.26 KB
Versions: 115
Compression:
Stored size: 1.26 KB
Contents
class Lalala::ExtRack::PageLoader def initialize(app) @app = app end IGNORE = %r{^/(lalala|assets|404|422|500)(/|$)} def call(env) if IGNORE === env['PATH_INFO'] return @app.call(env) end env = env chain = find_chain(env) if chain.present? update_env(env, chain) end @app.call(env) end protected def find_chain(env) path_info = env['PATH_INFO'] path_components = path_info.split('/') path_components.unshift('') unless path_components.first == '' return ApplicationPage.find_chain_for_path(path_components) end def update_env(env, chain) pages = [] page_name = "/" path_info = env['PATH_INFO'].to_s chain.each do |(page, path_component)| page_name = File.join(page_name, path_component) path_info = path_info[(1 + path_component.size)..-1] pages.push page end if path_info.blank? path_info = "/" end unless path_info.starts_with?('/') path_info = "/" + path_info end if page_name == "/" page_name = "" end env['lalala.page_chain'] = pages env['lalala.page'] = pages.last env['PATH_INFO'] = path_info unless page_name.blank? env['PAGE_NAME'] = page_name end end end
Version data entries
115 entries across 115 versions & 1 rubygems