diff --git a/lib/claper/accounts/user_token.ex b/lib/claper/accounts/user_token.ex index 86798df..4c2fed2 100644 --- a/lib/claper/accounts/user_token.ex +++ b/lib/claper/accounts/user_token.ex @@ -1,7 +1,8 @@ -@moduledoc """ - Plug for user session token. -""" defmodule Claper.Accounts.UserToken do + @moduledoc """ + Plug for user session token. + """ + use Ecto.Schema import Ecto.Query diff --git a/lib/claper_web/controllers/user_auth.ex b/lib/claper_web/controllers/user_auth.ex index eaf770b..1f525d2 100644 --- a/lib/claper_web/controllers/user_auth.ex +++ b/lib/claper_web/controllers/user_auth.ex @@ -1,7 +1,8 @@ -@moduledoc """ - Plug for user authentication. -""" defmodule ClaperWeb.UserAuth do + @moduledoc """ + Plug for user authentication. + """ + import Plug.Conn import Phoenix.Controller diff --git a/lib/claper_web/plugs/locale.ex b/lib/claper_web/plugs/locale.ex index 6e89885..fa1fc26 100644 --- a/lib/claper_web/plugs/locale.ex +++ b/lib/claper_web/plugs/locale.ex @@ -1,64 +1,65 @@ -@moduledoc """ - Plug to set the locale based on the Accept-Language header. - - ## Usage - - Add the plug to your pipeline in `router.ex`: - - pipeline :browser do - ... - plug ClaperWeb.Plugs.Locale - end - - ## Configuration - - The plug will use the `:default_locale` configuration value as the default - locale. If the `:default_locale` is not set, it will default to `:en`. - - ## Accept-Language header - - The plug will parse the `Accept-Language` header and set the locale to the - first language in the list that is known to the application. If no language - is known, the locale will not be changed. - - The `Accept-Language` header is a comma-separated list of language tags with - optional quality values. The quality value is a number between 0 and 1, - where 1 is the highest quality. The quality value is optional and defaults - to 1. - - Examples: - - Accept-Language: en-US,en;q=0.8,da;q=0.6 - - The above example will set the locale to `:en` if it is known to the - application. If `:en` is not known, it will set the locale to `:da` if it is - known to the application. If neither `:en` nor `:da` is known, the locale - will not be changed. - - Accept-Language: en-US,en;q=0.8 - - The above example will set the locale to `:en` if it is known to the - application. If `:en` is not known, the locale will not be changed. - - Accept-Language: en-US - - The above example will set the locale to `:en` if it is known to the - application. If `:en` is not known, the locale will not be changed. - - ## Known locales - - The plug will only set the locale if it is known to the application. The - known locales are determined by the `:gettext` configuration. The - `:gettext` configuration is set in `config/config.exs`: - - config :claper, ClaperWeb.Gettext, - default_locale: "en", - default_domain: "claper", - available_locales: ~w(en fr) - - The `:available_locales` option is -""" defmodule ClaperWeb.Plugs.Locale do + @moduledoc """ + Plug to set the locale based on the Accept-Language header. + + ## Usage + + Add the plug to your pipeline in `router.ex`: + + pipeline :browser do + ... + plug ClaperWeb.Plugs.Locale + end + + ## Configuration + + The plug will use the `:default_locale` configuration value as the default + locale. If the `:default_locale` is not set, it will default to `:en`. + + ## Accept-Language header + + The plug will parse the `Accept-Language` header and set the locale to the + first language in the list that is known to the application. If no language + is known, the locale will not be changed. + + The `Accept-Language` header is a comma-separated list of language tags with + optional quality values. The quality value is a number between 0 and 1, + where 1 is the highest quality. The quality value is optional and defaults + to 1. + + Examples: + + Accept-Language: en-US,en;q=0.8,da;q=0.6 + + The above example will set the locale to `:en` if it is known to the + application. If `:en` is not known, it will set the locale to `:da` if it is + known to the application. If neither `:en` nor `:da` is known, the locale + will not be changed. + + Accept-Language: en-US,en;q=0.8 + + The above example will set the locale to `:en` if it is known to the + application. If `:en` is not known, the locale will not be changed. + + Accept-Language: en-US + + The above example will set the locale to `:en` if it is known to the + application. If `:en` is not known, the locale will not be changed. + + ## Known locales + + The plug will only set the locale if it is known to the application. The + known locales are determined by the `:gettext` configuration. The + `:gettext` configuration is set in `config/config.exs`: + + config :claper, ClaperWeb.Gettext, + default_locale: "en", + default_domain: "claper", + available_locales: ~w(en fr) + + The `:available_locales` option is + """ + import Plug.Conn def init(_opts), do: nil @@ -111,10 +112,10 @@ defmodule ClaperWeb.Plugs.Locale do end defp ensure_language_fallbacks(tags) do - Enum.flat_map(tags, &fallback_tags/1) + Enum.flat_map(tags, &fallback_tags(&1, tags)) end - defp fallback_tags(tag) do + defp fallback_tags(tag, tags) do case String.split(tag, "-") do [language, _country_variant] -> if Enum.member?(tags, language), do: [tag], else: [tag, language] diff --git a/lib/claper_web/views/components/input_component.ex b/lib/claper_web/views/components/input_component.ex index 301efd7..1285b6a 100644 --- a/lib/claper_web/views/components/input_component.ex +++ b/lib/claper_web/views/components/input_component.ex @@ -1,7 +1,7 @@ -@moduledoc """ - Input component for forms -""" defmodule ClaperWeb.Component.Input do + @moduledoc """ + Input component for forms + """ use ClaperWeb, :view_component def text(assigns) do