Sha256: 82ef72fb6f7de858c8bcf413f8e9d662a9dcd7f1e7aecd9a7a123354f4e5544c

Contents?: true

Size: 1.31 KB

Versions: 19

Compression:

Stored size: 1.31 KB

Contents

require 'action_view'

class ActionView::TemplateRenderer

  def render(context, options)
    @view    = context
    @details = extract_details(options)
    template = get_template_by_user_agent(context, options)
    context  = @lookup_context

    prepend_formats(template.formats)

    unless context.rendered_format
      context.rendered_format = template.formats.first || formats.first
    end

    render_template(template, options[:layout], options[:locals])
  end

  private

  def get_user_agent(context)
    if context.respond_to?(:user_agent)
      if context.respond_to?(:controller)
        if context.controller.respond_to?(:session)
          context.user_agent
        end
      end
    end
  end

  def get_template_by_user_agent(context, options)
    ret = nil
    option_for_template = options[:template]

    ua = get_user_agent(context)
    if ua
      ua.priorities.each do |priority|
        begin
          options[:template] = option_for_template + '.' + priority
          ret = determine_template(options)
          break
        rescue ActionView::MissingTemplate
        end
      end
    end

    unless ret
      options[:template] = option_for_template
      ret = determine_template(options)
    end

    Rails.logger.debug "UserAgent: #{ua ? ua.name : 'unknown'} => #{ret.identifier}"
    ret
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
bizside-2.2.3 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.2.2 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.2.1 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.2.0 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.12 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.11 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.10 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.9 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.8 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.7 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.6 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.5 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.4 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.3 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.2 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.1 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.1.0 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.0.9 lib/bizside/user_agent/action_view/action_view_4.rb
bizside-2.0.8 lib/bizside/user_agent/action_view/action_view_4.rb