Module: Sinatra::LinkToHelper

Defined in:
lib/visage-app/helpers.rb

Instance Method Summary collapse

Instance Method Details



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/visage-app/helpers.rb', line 8

def link_to(url_fragment, mode=:path_only)
  case mode
  when :path_only
    base = request.script_name
  when :full_url
    if (request.scheme == 'http' && request.port == 80 ||
        request.scheme == 'https' && request.port == 443)
      port = ""
    else
      port = ":#{request.port}"
    end
    base = "#{request.scheme}://#{request.host}#{port}#{request.script_name}"
  else
    raise "Unknown script_url mode #{mode}"
  end
  "#{base}#{url_fragment}"
end