Sha256: 96f7616bc4590ce64971caece9d1816e694368e6da50bd9ae41b67af3af5b683

Contents?: true

Size: 845 Bytes

Versions: 9

Compression:

Stored size: 845 Bytes

Contents

module Locomotive::Steam
  module Middlewares

    # Retrieve a page from the path and the locale previously
    # fetched from the request.
    #
    class Page < ThreadSafe

      include Helpers

      def _call
        return env['steam.page'] if env['steam.page']

        if page = fetch_page
          if !page.not_found?
            log "Found page \"#{page.title}\" [#{page.fullpath}]"
          else
            log "Page not found, rendering the 404 page.".magenta
          end
        end

        env['steam.page'] = page
      end

      protected

      def fetch_page
        services.page_finder.match(path).tap do |pages|
          if pages.size > 1
            self.log "Found multiple pages: #{pages.map(&:title).join(', ')}"
          end
        end.first || services.page_finder.find('404')
      end

    end

  end
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
locomotivecms_steam-1.0.0 lib/locomotive/steam/middlewares/page.rb
locomotivecms_steam-1.0.0.rc10 lib/locomotive/steam/middlewares/page.rb
locomotivecms_steam-1.0.0.rc9 lib/locomotive/steam/middlewares/page.rb
locomotivecms_steam-1.0.0.rc8 lib/locomotive/steam/middlewares/page.rb
locomotivecms_steam-1.0.0.rc6 lib/locomotive/steam/middlewares/page.rb
locomotivecms_steam-1.0.0.rc4 lib/locomotive/steam/middlewares/page.rb
locomotivecms_steam-1.0.0.rc3 lib/locomotive/steam/middlewares/page.rb
locomotivecms_steam-1.0.0.rc2 lib/locomotive/steam/middlewares/page.rb
locomotivecms_steam-1.0.0.rc1 lib/locomotive/steam/middlewares/page.rb