Created
July 1, 2014 16:10
-
-
Save mprymek/cc36a1ede979d0c157b4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
defmodule MyApp.Plug.Mobile do | |
import Plug.Conn | |
def init(options), do: options | |
@default_layout "application" | |
def call(conn, opts) do | |
layout = case get_req_header(conn,"user-agent") do | |
[ua|_] -> | |
cond do | |
String.contains?(ua,"Android") -> "mobile" | |
true -> @default_layout | |
end | |
_ -> @default_layout | |
end | |
assign(conn,:layout,layout) | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Proof-of-concept of Plug (see https://github.com/elixir-lang/plug) detecting mobile clients.