Sha256: 7baafab61f96f4a1f4266d0efff72fca76c8fee6d8258387a3c3cea35ab3d41c

Contents?: true

Size: 1.39 KB

Versions: 11

Compression:

Stored size: 1.39 KB

Contents

module Locomotive::Wagon
  class Server

    class Middleware

      attr_accessor :app, :request, :path, :liquid_assigns

      attr_accessor :mounting_point, :page, :content_entry

      def initialize(app = nil)
        @app = app
      end

      def call(env)
        app.call(env)
      end

      protected

      def set_accessors(env)
        self.path           = env['wagon.path']
        self.request        = Rack::Request.new(env)
        self.mounting_point = env['wagon.mounting_point']
        self.page           = env['wagon.page']
        self.content_entry  = env['wagon.content_entry']

        env['wagon.liquid_assigns'] ||= {}
        self.liquid_assigns = env['wagon.liquid_assigns']
      end

      def site
        self.mounting_point.site
      end

      def params
        self.request.params.deep_symbolize_keys
      end

      def html?
        ['text/html', 'application/x-www-form-urlencoded'].include?(self.request.media_type) &&
        !self.request.xhr? &&
        !self.json?
      end

      def json?
        self.request.content_type == 'application/json' || File.extname(self.request.path) == '.json'
      end

      def redirect_to(location, type = 301)
        self.log "Redirected to #{location}"
        [type, { 'Content-Type' => 'text/html', 'Location' => location }, []]
      end

      def log(msg)
        Locomotive::Wagon::Logger.info msg
      end

    end

  end
end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
locomotivecms_wagon-1.4.0 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.3.3 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.3.2 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.3.1 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.3.0 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.2.2 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.2.1 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.2.0 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.1.0 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.0.2 lib/locomotive/wagon/server/middleware.rb
locomotivecms_wagon-1.0.1 lib/locomotive/wagon/server/middleware.rb