z_props (zotonic_core v1.0.0-rc.11)

Query string processing, property lists and property maps for Zotonic resources.

Link to this section Summary

Functions

Find all different language codes in the maps.
Convert a list for rsc insert and/or update to a map. The list could be a list of (binary) query args, or a property list with atom keys.
Transform a proplist from older resources and/or code to a (nested) map. This knows how to handle nestes lists like the 'blocks' list of lists.

Combine properties from a form. The form consists of a flat list with query string properties. The result is a map which can be used by the rsc and other routines.

Like from_qs/1, except that a specific date is used to fill in any missing date/time parts.
Normalize dates, ensure that all dates are in UTC and parsed to Erlang datetime format.
Check all trans records, remove languages not mentioned.

Link to this section Types

-type qs_key() :: binary().
-type qs_prop() :: {qs_key(), qs_value()}.
-type qs_value() :: binary() | #upload{} | term().

Link to this section Functions

Link to this function

extract_languages(Props)

-spec extract_languages(map()) -> [atom()].
Find all different language codes in the maps.
-spec from_list(list()) -> {ok, #{binary() => term()}}.
Convert a list for rsc insert and/or update to a map. The list could be a list of (binary) query args, or a property list with atom keys.
-spec from_props(proplists:proplist() | undefined) -> map().
Transform a proplist from older resources and/or code to a (nested) map. This knows how to handle nestes lists like the 'blocks' list of lists.
-spec from_qs([qs_prop()]) -> {ok, #{binary() => term()}}.

Combine properties from a form. The form consists of a flat list with query string properties. The result is a map which can be used by the rsc and other routines.

The keys can have a special format, specifying how they are processed:
  • 'dt:ymd:0:property' is datetime property, 0 for start-date, 1 for end-date, the pattern 'ymd' describes what is in the value, could also be 'y', 'm', 'd', 'dmy', 'his', 'hi', 'h', 'i', or 's'
  • 'prop$en' is the 'en' translation of the property named 'prop'
  • 'a.b.c.d' is a nested map
  • 'blocks[].name' is a list of maps, use 'blocks[].' to append a new empty entry. Use 'name[]' to append to a list of values.
If a date/time part is missing then the current UTC date is used to fill the missing parts.
Link to this function

from_qs(Qs, Now)

-spec from_qs([qs_prop()], calendar:datetime()) -> {ok, #{binary() => term()}}.
Like from_qs/1, except that a specific date is used to fill in any missing date/time parts.
Link to this function

normalize_dates(Props, IsAllDay, Tz)

-spec normalize_dates(m_rsc:props(), boolean(), binary() | undefined) -> m_rsc:props().
Normalize dates, ensure that all dates are in UTC and parsed to Erlang datetime format.
Link to this function

prune_languages(Props, Langs)

-spec prune_languages(map(), [atom()]) -> map().
Check all trans records, remove languages not mentioned.