Module: Jpmobile::FallbackViewSelector

Defined in:
lib/jpmobile/fallback_view_selector.rb

Instance Method Summary collapse

Instance Method Details

#render_to_body(options) ⇒ Object


6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/jpmobile/fallback_view_selector.rb', line 6

def render_to_body(options)
  if Jpmobile.config.fallback_view_selector and
      lookup_context.mobile.present? and !lookup_context.mobile.empty?
    begin
      expected_view_file = lookup_context.find_template(options[:template], options[:prefixes])

      _candidates = lookup_context.mobile.map { |variant|
        target_template = options[:template] + '_' + variant
        expected_view_file.virtual_path.match(target_template)
      }.compact

      if _candidates.empty?
        lookup_context.mobile = []
      end
    rescue ActionView::MissingTemplate
    end
  end

  super(options)
end