Sha256: a85c4ec676a14df47733fe3d601bc0af7fd120ac37cc3c86e87881c80c4f4da6

Contents?: true

Size: 1.33 KB

Versions: 6

Compression:

Stored size: 1.33 KB

Contents

module Locomotive::Builder
  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['builder.path']
        self.request        = Rack::Request.new(env)
        self.mounting_point = env['builder.mounting_point']
        self.page           = env['builder.page']
        self.content_entry  = env['builder.content_entry']

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

      def site
        self.mounting_point.site
      end

      def params
        self.request.params.deep_symbolize_keys
      end

      def html?
        self.request.media_type == 'text/html' || !self.request.xhr?
      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::Builder::Logger.info msg
      end

    end

  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
locomotivecms_builder-1.0.0.alpha8 lib/locomotive/builder/server/middleware.rb
locomotivecms_builder-1.0.0.alpha7 lib/locomotive/builder/server/middleware.rb
locomotivecms_builder-1.0.0.alpha6 lib/locomotive/builder/server/middleware.rb
locomotivecms_builder-1.0.0.alpha5 lib/locomotive/builder/server/middleware.rb
locomotivecms_builder-1.0.0.alpha4 lib/locomotive/builder/server/middleware.rb
locomotivecms_builder-1.0.0.alpha3 lib/locomotive/builder/server/middleware.rb