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.324 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.322 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.321 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.318 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.316 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.314 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.313 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.309 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.305 lib/lalala/ext_rack/page_loader.rb
lalala-4.1.0.dev.299 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.291 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.288 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.285 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.284 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.283 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.279 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.277 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.275 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.269 lib/lalala/ext_rack/page_loader.rb
lalala-4.0.0.dev.267 lib/lalala/ext_rack/page_loader.rb