37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
# File 'lib/fluentd_server/web_helper.rb', line 37
def url_for(url_fragment, mode=nil, options = nil)
if mode.is_a? Hash
options = mode
mode = nil
end
if mode.nil?
mode = :path_only
end
mode = mode.to_sym unless mode.is_a? Symbol
optstring = nil
if options.is_a? Hash
optstring = '?' + options.map { |k,v| "#{k}=#{URI.escape(v.to_s, /[^#{URI::PATTERN::UNRESERVED}]/)}" }.join('&')
end
case mode
when :path_only
base = request.script_name
when :full
scheme = request.scheme
if (scheme == 'http' && request.port == 80 ||
scheme == 'https' && request.port == 443)
port = ""
else
port = ":#{request.port}"
end
base = "#{scheme}://#{request.host}#{port}#{request.script_name}"
else
raise TypeError, "Unknown url_for mode #{mode.inspect}"
end
"#{base}#{url_fragment}#{optstring}"
end
|