defmodule AppleTouchIcon do @moduledoc """ Documentation for `AppleTouchIcon`. """ @default_sizes [ {57, 57}, {72, 72}, {76, 76}, {114, 114}, {120, 120}, {144, 144}, {152, 152}, {180, 180} ] @default_device_attributes [ %{ min_device_width: 481, max_device_width: 1024, layout: "landscape", type: "px", webkit_device_pixel_ratio: 2 } ] @default_path "/images" @doc """ Render the icons. ## Examples iex> AppleTouchIcon.render() """ def render() do render( @default_path, @default_sizes, @default_device_attributes ) end def render(arg) when is_nil(arg) do render( @default_path, [], @default_device_attributes ) end def render(arg) when is_list(arg) do render( @default_path, arg, @default_device_attributes ) end def render(arg, arg2) when is_list(arg) and is_list(arg2) do render( @default_path, arg, arg2 ) end def render(arg, arg2) when is_nil(arg) and is_nil(arg2) do render( @default_path, [], [] ) end def render(arg, arg2) when is_nil(arg) and is_list(arg2) do render( @default_path, [], arg2 ) end def render(arg, arg2) when is_list(arg) and is_nil(arg2) do render( @default_path, arg, [] ) end def render( path, sizes \\ @default_sizes, device_attributes \\ @default_device_attributes ) do header = "" icons = for {h, w} <- sizes do size = "#{h}x#{w}" "" end attributes = for param <- device_attributes do case param do %{ min_device_width: min_w, max_device_width: max_w, orientation: orientation, type: type, webkit_device_pixel_ratio: pr } -> size = "#{min_w}x#{max_w}" min_w = "#{min_w}#{type}" max_w = "#{max_w}#{type}" "" %{ min_device_width: min_w, max_device_width: max_w, orientation: orientation, type: type } -> size = "#{min_w}x#{max_w}" min_w = "#{min_w}#{type}" max_w = "#{max_w}#{type}" "" %{min_device_width: min_w, max_device_width: max_w, orientation: orientation} -> size = "#{min_w}x#{max_w}" min_w = "#{min_w}px" max_w = "#{max_w}px" "" %{min_device_width: min_w, max_device_width: max_w} -> size = "#{min_w}x#{max_w}" min_w = "#{min_w}px" max_w = "#{max_w}px" "" %{ device_width: w, device_height: h, orientation: orientation, type: type, webkit_device_pixel_ratio: pr } -> size = "#{w}x#{h}" device_width = "#{w}#{type}" device_height = "#{h}#{type}" "" %{device_width: w, device_height: h, orientation: orientation, type: type} -> size = "#{w}x#{h}" device_width = "#{w}#{type}" device_height = "#{h}#{type}" "" %{device_width: w, device_height: h, orientation: orientation} -> size = "#{w}x#{h}" device_width = "#{w}px" device_height = "#{h}px" "" %{device_width: w, device_height: h} -> size = "#{w}x#{h}" device_width = "#{w}px" device_height = "#{h}px" "" _ -> {:error, "invalid device attributes"} end end header <> Enum.join(icons ++ attributes) end end