module Storefront module RequestHelper # requesting?(:deals) # requesting?("/admin/users/:id") # requesting?("admin/users#show") def requesting?(expression) case expression when ::Symbol (request.path =~ /#{expression}\/?$/).present? else (request.path =~ expression).present? end end def self.clear_session before_filter { |controller| controller.session.clear } end # ensure_domain :production => "site.com", :staging => "site-development.heroku.com" def self.ensure_domain(options = {}) @ensure_domain_options = options.symbolize_keys true end def ensure_domain domain = self.class.ensure_domain_options[Rails.env.to_sym] return true if domain.blank? redirect_to(request.protocol + domain + request.request_uri) if request.env['HTTP_HOST'] != domain true end def self.ensure_domain_options @ensure_domain_options end def on_current_page?(options) url_string = CGI.unescapeHTML(url_for(options)) request = controller.request if url_string.index("?") fullpath = request.fullpath else fullpath = request.fullpath.split('?').first end if url_string =~ /^\w+:\/\// url_string == "#{request.protocol}#{request.host_with_port}#{fullpath}" else url_string == fullpath.gsub(/&sort_by=.*/, "").gsub(/&vendor_name=.*/, "") end end def with_subdomain(subdomain) subdomain = (subdomain || "") subdomain += "." unless subdomain.empty? # needs to be dynamic! [subdomain, request.domain, request.port_string].join end def url_for(options = {}) if options.kind_of?(Hash) && options.has_key?(:subdomain) options[:host] = with_subdomain(options.delete(:subdomain)) end if options.is_a?(Symbol) && options == :up request.path.split("/")[0..-2].join("/") else super(options) end end end end