Fix docs and compile errors

This commit is contained in:
Alex
2023-09-09 18:10:11 +02:00
parent cdb92f7ca2
commit d52411d761
4 changed files with 74 additions and 71 deletions

View File

@@ -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

View File

@@ -1,7 +1,8 @@
@moduledoc """
Plug for user authentication.
"""
defmodule ClaperWeb.UserAuth do
@moduledoc """
Plug for user authentication.
"""
import Plug.Conn
import Phoenix.Controller

View File

@@ -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]

View File

@@ -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