lib/roda/plugins/relative_path.rb
# Return a relative prefix to append to an absolute path to a relative path
# based on the current path of the request.
Return a relative prefix to append to an absolute path to a relative path
based on the current path of the request.
Return a relative prefix to append to an absolute path to a relative path based on the current path of the request .
def relative_prefix
          return @_relative_prefix if @_relative_prefix
          env = @_request.env
          script_name = env["SCRIPT_NAME"]
          path_info = env["PATH_INFO"]
          case script_name.getbyte(0)
          when nil 
            unless path_info.getbyte(0) == 47 
              return(@_relative_prefix = '')
            end
          when 47 
          else
            return(@_relative_prefix = '')
          end
          slash_count = script_name.count('/') + path_info.count('/')
          @_relative_prefix = if slash_count > 1
            ("../" * (slash_count - 2)) << ".."
          else
            "."
          end
        end
def relative_prefix return @_relative_prefix if @_relative_prefix env = @_request . env script_name = env [ "SCRIPT_NAME" ] path_info = env [ "PATH_INFO" ] case script_name . getbyte ( 0 ) when nil unless path_info . getbyte ( 0 ) == 47 return ( @_relative_prefix = '' ) end when 47 else return ( @_relative_prefix = '' ) end slash_count = script_name . count ( '/' ) + path_info . count ( '/' ) @_relative_prefix = if slash_count > 1 ( "../" * ( slash_count - 2 ) ) << ".." else "." end end
Return a relative prefix to append to an absolute path to a relative path
based on the current path of the request.
Return a relative prefix to append to an absolute path to a relative path based on the current path of the request .
# Check path begins with slash.  All valid paths should, but in case this # request is bad, just skip using a relative prefix. # SCRIPT_NAME empty # PATH_INFO starts with / # SCRIPT_NAME starts with / # nothing