Skip to content

Instantly share code, notes, and snippets.

@timriley
Forked from joshprice/mobile_helper_sinatra.rb
Created February 7, 2010 22:56
Show Gist options
  • Save timriley/297744 to your computer and use it in GitHub Desktop.
Save timriley/297744 to your computer and use it in GitHub Desktop.
helpers do
def mobile_request?
[ /AppleWebKit.*Mobile/, /Android.*AppleWebKit/ ].any? {|r| request.env['HTTP_USER_AGENT'] =~ r}
end
def mobile_file(name)
File.exist?("#{options.views}/#{name}#{@mobile}.haml") ? :"#{name}#{@mobile}" : name.to_sym
end
def partial(name)
haml mobile_file("_#{name}"), :layout => false
end
def deliver(name)
haml mobile_file(name), :layout => :"layout#{@mobile}"
end
end
before do
@mobile = mobile_request? ? ".mobile" : ""
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment