Sha256: b9a605dbcab688fd31aa615c9b5b71e0d0161e75f490a4ce269064816f5020fa

Contents?: true

Size: 1.11 KB

Versions: 59

Compression:

Stored size: 1.11 KB

Contents

class Lalala::ExtRack::PageLoader

  def initialize(app)
    @app = app
  end

  def call(env)
    if %r{^/(lalala|assets)(/|$)} === 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       = []
    script_name = env['SCRIPT_NAME'].to_s
    path_info   = env['PATH_INFO'].to_s

    chain.each do |(page, path_component)|
      script_name = File.join(script_name, path_component)
      path_info   = path_info[(1 + path_component.size)..-1]

      pages.push page
    end

    env['lalala.page_chain'] = pages
    env['lalala.page']       = pages.last
    env['PATH_INFO']         = path_info

    unless script_name == "/" or script_name.blank?
      env['SCRIPT_NAME'] = script_name
    end
  end

end

Version data entries

59 entries across 59 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.168 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.165 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.162 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.161 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.160 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.157 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.156 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.155 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.154 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.153 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.152 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.149 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.146 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.144 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.141 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.136 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.135 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.134 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.133 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.132 lib/lalala/ext_rack/page_loader.rb