Module: LightMobile::DynamicRenderer

Defined in:
lib/light_mobile/dynamic_renderer.rb

Instance Method Summary collapse

Instance Method Details

#render(*args, &blk) ⇒ Object

In order to only render mobile views if they exist.



3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/light_mobile/dynamic_renderer.rb', line 3

def render(*args, &blk)
  if request.user_agent && view_context.agent_mobile? && (session[:light_mobile_version].to_s == "mobile" || !session[:light_mobile_version].present?)
    name = args[0]
    name = action_name.to_sym if !name.is_a?(Symbol) && !name.is_a?(String)

    if name.is_a? Symbol
      view_paths.each do |view_path|
        ActionView::Template::Handlers.extensions.each do |handler|
          full_path = "#{view_path}/#{controller_path}/#{name}.mobile.#{handler}"
          next unless File.exists? full_path
          request.format = :mobile
          self.formats = [:mobile, :html]
        end
      end
    end
  end

  super
end