class Rack::BodyClasses
Constants
- VERSION
Public Class Methods
new(app)
click to toggle source
# File lib/rack/body_classes.rb, line 10 def initialize(app) @app = app end
Public Instance Methods
call(env)
click to toggle source
# File lib/rack/body_classes.rb, line 14 def call(env) browser = Browser.new(ua: env["HTTP_USER_AGENT"], accept_language: env['HTTP_ACCEPT_LANGUAGE']).meta device = mobile_esp(env["HTTP_USER_AGENT"], env['HTTP_ACCEPT']) env['rack.body_classes'] = [device, browser].flatten.compact.join(" ") status, headers, body = @app.call(env) [status, headers, body] end
Private Instance Methods
mobile_esp(user_agent, http_accept)
click to toggle source
# File lib/rack/body_classes.rb, line 24 def mobile_esp(user_agent, http_accept) return 'unknown-device' if user_agent.nil? || http_accept.nil? mobileesp = MobileESPConverted::UserAgentInfo.new(user_agent, http_accept) return :mobile if mobileesp.is_tier_generic_mobile || mobileesp.is_tier_iphone || mobileesp.is_tier_rich_css return :tablet if mobileesp.is_tier_tablet return :desktop end