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

Version Path
lalala-4.1.0.dev.359 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.358 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.357 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.356 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.355 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.354 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.351 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.350 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.349 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.344 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.343 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.342 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.341 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.340 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.339 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.336 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.334 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.332 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.331 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.329 lib/lalala/ext_rack/page_loader.rb