Sha256: c0c46ab5668ae09e6641b04842756dedaede3b480537a90a9ecd8a182d31c4a1

Contents?: true

Size: 1.01 KB

Versions: 9

Compression:

Stored size: 1.01 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
  end

end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
lalala-4.0.0.dev.184 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.183 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.181 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.180 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.179 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.178 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.177 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.176 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.170 lib/lalala/ext_rack/page_loader.rb