z_props (zotonic_core v1.0.0-rc.17)

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

Summary

Functions

Common resource properties used by exporter and backup routines.

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 map to a nested map with binary 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.

Return a type-hint atom derived from a property name.

Check all trans records, remove languages not mentioned.

Types

qs_key/0

-type qs_key() :: binary().

qs_prop/0

-type qs_prop() :: {qs_key(), qs_value()}.

qs_value/0

-type qs_value() ::
          binary() |
          #upload{filename :: binary() | undefined,
                  tmpfile :: file:filename_all() | undefined,
                  tmpmonitor :: undefined | pid(),
                  data :: binary() | undefined,
                  mime :: binary() | undefined} |
          term().

type_hint_t/0

-type type_hint_t() ::
          id | binary | text | html | int | datetime | list | language | float | bool | uri | email |
          unsafe.

Functions

common_properties()

-spec common_properties() -> [binary()].

Common resource properties used by exporter and backup routines.

extract_languages(Props)

-spec extract_languages(map()) -> [atom()].

Find all different language codes in the maps.

from_list(L)

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

from_map(Map)

-spec from_map(map() | undefined) -> map().

Transform a map to a nested map with binary keys.

from_props(Ps)

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

from_qs(Qs)

-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
  • 'a~1' is a multi occurence of 'a', useful for same named items
  • '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.

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.

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.

property_name_type_hint(Key)

-spec property_name_type_hint(Key) -> type_hint_t() | undefined when Key :: binary().

Return a type-hint atom derived from a property name.

prune_languages(Props, Langs)

-spec prune_languages(map(), [atom()]) -> map().

Check all trans records, remove languages not mentioned.