Module: MobileEnhancements::UrlHelper

Defined in:
lib/mobile_enhancements/url_helper.rb

Instance Method Summary collapse

Instance Method Details

#strip_domain(url) ⇒ Object

converts a URL/path to a path



30
31
32
# File 'lib/mobile_enhancements/url_helper.rb', line 30

def strip_domain(url)
  url.gsub(/([a-z]+\:)?\/\/.*?\//i, "/")
end

#url_for(*args) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/mobile_enhancements/url_helper.rb', line 3

def url_for(*args)
  url = super
  # ignore our direct calls for desktop/mobile URLs
  if args.size == 1 && args.first.frozen?
    url
  # if it's from a mobile
  elsif mobile_request?
    # mobilify the url
    murl = mobile_url(url)
    # verify or resort to original
    verify_path(murl) || url
  # if it's a desktop request
  else
    # desktopify the url
    durl = desktop_url(super)
    # verify or resort to original
    verify_path(durl) || durl
  end
end

#verify_path(url) ⇒ Object

ensures a URL/path exists



24
25
26
27
# File 'lib/mobile_enhancements/url_helper.rb', line 24

def verify_path(url)
  path = strip_domain(url)
  Rails.application.routes.recognize_path(path) && url rescue false
end