amelinium.web.taggers
added in 1.0.0
amelinium service, Selmer taggers.
ad-hoc-id
(ad-hoc-id a)
(ad-hoc-id a b)
(ad-hoc-id a b c)
(ad-hoc-id a b c d)
(ad-hoc-id a b c d e)
(ad-hoc-id a b c d e & more)
Generates ad-hoc ID (a numeric string) on a basis of values passed as arguments.
add-taggers
(add-taggers router language translations-fn validators js-config)
Registers taggers in a global repository. To be changed to a pure fn some day.
anti-spam-code
(anti-spam-code config)
(anti-spam-code config num)
(anti-spam-code config num rng)
Generates anti-spam HTML string containing randomly selected fields and values using validators/gen-required
.
args->map
(args->map args)
Transforms the given sequence of arguments args
to a map by taking each consecutive pair and changing its first element into a keyword (using amelinium.utils/keyword-from-param
) to become a key associated with its paired value.
assignments->kw-map
(assignments->kw-map s ctx)
(assignments->kw-map s)
Parses a string s
with key=value assignments and returns a map with keys as keywords. Variables are resolved if they have [[
and ]]
around.
assignments->map
(assignments->map s ctx)
(assignments->map s)
Parses a string s
with key=value assignments and returns a map with keys as strings. Variables are resolved if they have [[
and ]]
around.
form-field
(form-field args tr-sub errors params)
(form-field args tr-sub errors params props)
Helper to generate HTML for the form-field
tag.
form-fields
(form-fields args tr-sub errors params)
Helper to generate HTML for the form-fields
tag.
form-submit
(form-submit label args tr-sub validators)
(form-submit label args tr-sub validators html)
Helper to generate HTML for the form-submit
tag.
form-submit-session
(form-submit-session label args tr-sub session-field session-id validators)
(form-submit-session label args tr-sub session-field session-id validators html)
Helper to generate HTML for the form-submit
tag.
get-field-value
(get-field-value ctx v)
Retrieves value of a field v
from :params
map of :form/errors
key of the given ctx
map. If there is no entry or value is nil
or false
, it looks it up directly in ctx
. Returns a value or an empty string.
get-form-action
(get-form-action args ctx)
Prepares default form action attribute by removing form-errors
from a query string for current page if the :action
in args
is not present. If the :action
is present`, it is returned as is.
If the action is missing and there are no query params, nil
is returned. If there is no form-errors
in query params, nil
is returned too.
This function takes care about a corner case where leaving form action empty on a rendered form would cause current form errors encoded in a query parameter string to be sent again to the same page, giving possibly misleading information about the form errors.
get-lang
(get-lang ctx)
Obtains a language string from a context map ctx
by trying the following keys: :language/str
, :lang
, :language
and :language/default
.
get-lang-id
(get-lang-id ctx)
Obtains a language identifier (as keyword) from a context map ctx
by trying the following keys: :language/str
, :lang
, :language
and :language/default
.
html-add-attrs
(html-add-attrs args)
(html-add-attrs args to-remove)
Generates HTML attribute list in a form of name= "value"
from the given args
map. Returns a string with each pair separated by a single space and the whole string prefixed with a single space (if it is not empty).
html-esc
(html-esc s)
Escapes string s
to be used in HTML using Selmer’s selmer.filter-parser/escape-html*
function.
init
(init {:keys [enabled? router language translations validators js-config], :or {enabled? true}})
Initializes Selmer taggers.
kw-param?
(kw-param? v)
Returns true
if the given value is a keyword or a string expressing a keyword (with :
symbol as its first character).
lang-url
(lang-url router ctx path-or-name lang localized? path-params query-params)
(lang-url router ctx path-or-name lang localized? path-params)
(lang-url router ctx path-or-name lang localized?)
(lang-url router ctx path-or-name lang)
(lang-url router ctx path-or-name)
(lang-url router ctx)
(lang-url router ctx path-or-name lang localized? path-params query-params lang-param)
Transforms the given URI (a path expressed as a string) or a route name (a keyword) to a localized path using the detected (or given) language. Calls amelinium.common/lang-url
. Tries to be very optimistic: if a path was given and there was no success in transforming it into localized variant, it will return it.
param-try-tr
(param-try-tr tr-sub-fn v)
(param-try-tr tr-sub-fn k v)
(param-try-tr tr-sub-fn k v a)
(param-try-tr tr-sub-fn k v a b)
(param-try-tr tr-sub-fn k v a b & more)
Tries to translate tag parameters k
and v
using the given tr-sub-fn
function (which should be a result of calling translator-sub
). If the value of v
is not a keyword or keyworded string (kw-param?
applied to v
does not return true
) then a string of v
is returned without calling a translation function. Any additional arguments are passed to a translation function as additional arguments.
parse-args
(parse-args args)
Parses arguments using selmer.filter-parser/fix-filter-args
function.
render-assignment-value
(render-assignment-value ctx v)
Interpolates values enclosed within [[
and ]]
tokens by getting values associated with the obtained keys in ctx
map. Additionally, parses form field values enclosed within [-
and -]
tokens by replacing them with default values transferred from propagated error data or, if there was no error, with values associated with keys in ctx
map.
tr
(tr args ctx)
(tr args ctx translations-fn)
Translation function. Creates a translator by calling translator
and prepares arguments from a template tag to be passed to it (the first being converted to a keyword). Returns a string or nil
.
tr-sub
(tr-sub args ctx)
(tr-sub args ctx translations-fn)
Translation function. Creates a translator by calling translator-sub
and prepares arguments from a template tag to be passed to it (the first and second being converted to keywords). Returns a string or nil
.
translator
(translator ctx)
(translator ctx translations-fn)
For the given context map ctx
and optional translation function translations-fn
it returns a translation function with predefined language, taking a translation key k
and optional arguments.
The value of translations-fn
argument is used as fallback when there is no :i18n/translator
nor :i18n/translator-nd
key found in a context map. It should be a function returned by the amelinium.i18n/translation-fn
. If translations-fn
is nil
or false
, it will fall back to a generic, globally initialized amelinium.i18n/translations
.
translator-sub
(translator-sub ctx)
(translator-sub ctx translations-fn)
For the given context map ctx
and optional translation function translations-fn
it returns a translation function with predefined language, taking a translation key k
and optional arguments. If the first optional argument is present and it is not nil
nor false
then its value will become a name and the value of k
will become a namespace for a translation key.
The value of translations-fn
argument is used as fallback when there is no :i18n/translator-sub
nor :i18n/translator-sub-nd
key found in a context map. It should be a function returned by the amelinium.i18n/translation-fn
. If translations-fn
is nil
or false
, it will fall back to a generic, globally initialized amelinium.i18n/translations
.
url-esc
(url-esc s)
Escapes certain characters (<
, >
, "
and '
) in the given string s
by replacing them with character codes prefixed with %
symbol.