Skip to content

Instantly share code, notes, and snippets.

@mprymek
Created July 1, 2014 16:10
Show Gist options
  • Save mprymek/cc36a1ede979d0c157b4 to your computer and use it in GitHub Desktop.
Save mprymek/cc36a1ede979d0c157b4 to your computer and use it in GitHub Desktop.
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
@mprymek
Copy link
Author

mprymek commented Jul 1, 2014

Proof-of-concept of Plug (see https://github.com/elixir-lang/plug) detecting mobile clients.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment