Sha256: 1b60338fe9f959c95ae204d3b0263551cf473fb50b1d96734453b19bbf8fedc0
Contents?: true
Size: 1.87 KB
Versions: 2
Compression:
Stored size: 1.87 KB
Contents
module Storefront module RequestHelper 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? [subdomain, request.domain(2), 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
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
storefront-0.2.1 | lib/storefront/helpers/request_helper.rb |
storefront-0.2.0 | lib/storefront/helpers/request_helper.rb |