From 20a91ad400144db5e5b487ee65c1fdbadd87a707 Mon Sep 17 00:00:00 2001 From: petrushka Date: Thu, 3 Apr 2014 00:26:38 +0400 Subject: [PATCH 1/3] Fix skip user agent behaviour dealing with regexp --- lib/mobylette/respond_to_mobile_requests.rb | 6 +++--- spec/lib/respond_to_mobile_requests_spec.rb | 5 +++++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/lib/mobylette/respond_to_mobile_requests.rb b/lib/mobylette/respond_to_mobile_requests.rb index a47ece6..6704ecf 100644 --- a/lib/mobylette/respond_to_mobile_requests.rb +++ b/lib/mobylette/respond_to_mobile_requests.rb @@ -101,7 +101,7 @@ def mobylette_config # Private: Configures how the resolver shall handle fallbacks. # - # if options has a :fallback_chains key, it will use it + # if options has a :fallback_chains key, it will use it # as the fallback rules for the resolver, the format should # be a hash, where each key defines a array of formats. # Example: @@ -160,7 +160,7 @@ def respond_as_mobile? # Private: Rertuns true if the current user agent should be skipped by configuration # def user_agent_excluded? - request.user_agent.to_s.downcase =~ Regexp.union([self.mobylette_options[:skip_user_agents]].flatten.map(&:to_s)) + request.user_agent.to_s.downcase =~ Regexp.union([self.mobylette_options[:skip_user_agents]].flatten.map{|e| e.is_a?(Regexp) ? e : e.to_s}) end # Private: Returns true if the visitor has the force_mobile set in it's session @@ -213,7 +213,7 @@ def set_mobile_format return device if request_device?(device) end end - :mobile + :mobile end end diff --git a/spec/lib/respond_to_mobile_requests_spec.rb b/spec/lib/respond_to_mobile_requests_spec.rb index df02a1c..e3cb127 100644 --- a/spec/lib/respond_to_mobile_requests_spec.rb +++ b/spec/lib/respond_to_mobile_requests_spec.rb @@ -200,6 +200,11 @@ class MockController < ActionController::Base subject.send(:respond_as_mobile?).should be_false end + it "should be false if skip_user_agents contains the current user agent defined using regexp" do + subject.mobylette_options[:skip_user_agents] = [/ipad/, /android/] + subject.send(:respond_as_mobile?).should be_false + end + it "should be true if skip_user_agents is not set" do subject.mobylette_options[:skip_user_agents] = [] subject.send(:respond_as_mobile?).should be_true From 628fd15f9374cb8f3922682b1351c185393faa7d Mon Sep 17 00:00:00 2001 From: Dominique d'Argent Date: Fri, 4 Jul 2014 12:00:38 +0200 Subject: [PATCH 2/3] Fix compatibility with Rails 4.1 by forward-porting a require statement to load FileSystemResolver * Fixes #44 * I've transplanted this commit from netzpirat/haml_coffee_assets@7167b263e9bf852b2c63906752cb521f2ec89fc7 * This fixes mobylette-3.5/lib/mobylette/resolvers/chained_fallback_resolver.rb:3:in `': uninitialized constant ActionView::FileSystemResolver (NameError) * For more details, see rails @ 3fbff78 (rails/rails@3fbff78#diff-90f6f2b6859f5da65e11631ebcdf3f09) --- lib/mobylette/resolvers/chained_fallback_resolver.rb | 3 +++ 1 file changed, 3 insertions(+) diff --git a/lib/mobylette/resolvers/chained_fallback_resolver.rb b/lib/mobylette/resolvers/chained_fallback_resolver.rb index 24cca05..44fd0bb 100644 --- a/lib/mobylette/resolvers/chained_fallback_resolver.rb +++ b/lib/mobylette/resolvers/chained_fallback_resolver.rb @@ -1,3 +1,6 @@ +require 'action_view' +require 'action_view/template/resolver' + module Mobylette module Resolvers class ChainedFallbackResolver < ::ActionView::FileSystemResolver From c3a9d1cc1709055c5bcc2c3ccb872ae354654e80 Mon Sep 17 00:00:00 2001 From: Akito Kasai Date: Fri, 25 Mar 2016 18:20:31 +0900 Subject: [PATCH 3/3] add arguments for find_templates --- .../resolvers/chained_fallback_resolver.rb | 16 +++++++++++----- 1 file changed, 11 insertions(+), 5 deletions(-) diff --git a/lib/mobylette/resolvers/chained_fallback_resolver.rb b/lib/mobylette/resolvers/chained_fallback_resolver.rb index 24cca05..1250cf3 100644 --- a/lib/mobylette/resolvers/chained_fallback_resolver.rb +++ b/lib/mobylette/resolvers/chained_fallback_resolver.rb @@ -24,9 +24,9 @@ def initialize(formats = {}, view_paths = ['app/views']) # ... # } # - # It will add the fallback chain array of the + # It will add the fallback chain array of the # request.format to the resolver. - # + # # If the format.request is not defined in formats, # it will behave as a normal FileSystemResovler. # @@ -39,13 +39,19 @@ def replace_fallback_formats_chain(formats) # Private: finds the right template on the filesystem, # using fallback if needed # - def find_templates(name, prefix, partial, details) + def find_templates(name, prefix, partial, details, outside_app_allowed = nil) # checks if the format has a fallback chain if @fallback_formats.has_key?(details[:formats].first) details = details.dup - details[:formats] = Array.wrap(@fallback_formats[details[:formats].first]) + details[:formats] = Array.wrap(@fallback_formats[details[:formats].first]) + end + + if outside_app_allowed.nil? + # Consider the backward compatibility with older Rails + super(name, prefix, partial, details) + else + super(name, prefix, partial, details, outside_app_allowed) end - super(name, prefix, partial, details) end # Helper for building query glob string based on resolver's pattern.