Skip to content
This repository was archived by the owner on Aug 26, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 14 additions & 5 deletions lib/mobylette/resolvers/chained_fallback_resolver.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
require 'action_view'
require 'action_view/template/resolver'

module Mobylette
module Resolvers
class ChainedFallbackResolver < ::ActionView::FileSystemResolver
Expand All @@ -24,9 +27,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.
#
Expand All @@ -39,13 +42,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.
Expand Down
6 changes: 3 additions & 3 deletions lib/mobylette/respond_to_mobile_requests.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -213,7 +213,7 @@ def set_mobile_format
return device if request_device?(device)
end
end
:mobile
:mobile
end

end
Expand Down
5 changes: 5 additions & 0 deletions spec/lib/respond_to_mobile_requests_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down