Class: Mobylette::Resolvers::ChainedFallbackResolver

Inherits:
ActionView::FileSystemResolver
  • Object
show all
Defined in:
lib/plugins/ext/mobylette/resolvers/chained_fallback_resolver.rb

Instance Method Summary collapse

Constructor Details

#initialize(formats = {}, view_paths = ['app/views']) ⇒ ChainedFallbackResolver

Initializes the fallback resolver with a default mobile format.



9
10
11
12
13
# File 'lib/plugins/ext/mobylette/resolvers/chained_fallback_resolver.rb', line 9

def initialize(formats = {}, view_paths = ['app/views'])
  @fallback_formats = formats
  @paths = view_paths.map { |view_path| File.expand_path(view_path)}
  super(@paths.first, DEFAULT_PATTERN)
end

Instance Method Details

#replace_fallback_formats_chain(formats) ⇒ Object

Updates the fallback resolver replacing the fallback format hash.

formats - hash of fallbacks, example:

formats = {
  mobile: [:mobile, :html],
  iphone: [:iphone, :ios, :mobile, :html],
  android: [:android, :mobile],
  ...
}

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.



33
34
35
# File 'lib/plugins/ext/mobylette/resolvers/chained_fallback_resolver.rb', line 33

def replace_fallback_formats_chain(formats)
  @fallback_formats = formats
end