Sha256: 1ee5ff675d41be9bbb237d2a4a88f5a7239932f877beee8dad2e97505649d248

Contents?: true

Size: 1.69 KB

Versions: 12

Compression:

Stored size: 1.69 KB

Contents

module Locomotive::Steam
  module Middlewares

    module Helpers

      def html?
        ['text/html', 'application/x-www-form-urlencoded', 'multipart/form-data'].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 render_response(content, code = 200, type = nil)
        @next_response = [code, { 'Content-Type' => type || 'text/html' }, [content]]
      end

      def redirect_to(location, type = 301)
        _location = mounted_on && !location.starts_with?(mounted_on) && (location =~ Locomotive::Steam::IsHTTP).nil? ? "#{mounted_on}#{location}" : location

        self.log "Redirected to #{_location}".blue

        @next_response = [type, { 'Content-Type' => 'text/html', 'Location' => _location }, []]
      end

      def modify_path(path = nil, &block)
        path ||= env['steam.path']

        segments = path.split('/')
        yield(segments)
        path = segments.join('/')

        path = '/' if path.blank?
        path += "?#{request.query_string}" unless request.query_string.empty?
        path
      end

      # make sure the location passed in parameter doesn't
      # include the "mounted_on" parameter.
      # If so, returns the location without the "mounted_on" string.
      def make_local_path(location)
        return location if mounted_on.blank?
        location.gsub(Regexp.new('^' + mounted_on), '')
      end

      def mounted_on
        request.env['steam.mounted_on']
      end

      def log(msg, offset = 2)
        Locomotive::Common::Logger.info (' ' * offset) + msg
      end

    end

  end
end

Version data entries

12 entries across 12 versions & 1 rubygems

Version Path
locomotivecms_steam-1.4.0.rc2 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.4.0.rc1 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.4.0.pre.rc.1 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.3.0 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.3.0.rc2 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.2.1 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.3.0.rc1 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.2.0 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.2.0.rc3 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.2.0.rc2 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.2.0.rc1 lib/locomotive/steam/middlewares/helpers.rb
locomotivecms_steam-1.2.0.beta1 lib/locomotive/steam/middlewares/helpers.rb