MishkaDocument.Resources.Helpers.Labels (Mishka Document v0.0.1)

Copy Markdown View Source

The small words, numbers and dates the document resources' tables draw in their cells.

A table cell only receives the fields it requires, and a field the viewer's policy hides arrives as a struct rather than a value, so each function here takes term() and answers a safe value for anything it was not given.

Labels.version_label("1.2.0")   #=> "v1.2.0"
Labels.counted(%Ash.NotLoaded{})  #=> 0

Summary

Types

A badge a cell draws: its words and the Tailwind classes it wears.

Functions

A count as a cell draws it: the integer itself, else 0.

The first of fields of record that is loaded, nil when none is or the loaded one holds nil.

The word for a kind of version bump, in the viewer's language.

The day a record was written, in the viewer's language; a dash for anything that is not a time.

The badge a review status wears, %{label: label, class: classes}, with the label in the viewer's language. A status that is none of the five reads as a dash.

A badge map with its :label message id translated into the viewer's language.

A version number as a tag reads it, v1.2.0; a record without one reads as v0.0.1.

Types

badge()

@type badge() :: %{label: String.t(), class: String.t()}

A badge a cell draws: its words and the Tailwind classes it wears.

Functions

counted(value)

@spec counted(term()) :: non_neg_integer()

A count as a cell draws it: the integer itself, else 0.

first_loaded(record, fields)

@spec first_loaded(map(), [atom()]) :: term()

The first of fields of record that is loaded, nil when none is or the loaded one holds nil.

A record read by a master carries its relationships under master_ names, one read by a site user under the plain ones; the other set stays %Ash.NotLoaded{}.

Labels.first_loaded(draft, [:master_section, :section])

increment_label(other)

@spec increment_label(term()) :: String.t()

The word for a kind of version bump, in the viewer's language.

inserted_on(at)

@spec inserted_on(term()) :: String.t()

The day a record was written, in the viewer's language; a dash for anything that is not a time.

review_badge(status)

@spec review_badge(term()) :: badge()

The badge a review status wears, %{label: label, class: classes}, with the label in the viewer's language. A status that is none of the five reads as a dash.

translate_label(badge)

@spec translate_label(badge()) :: badge()

A badge map with its :label message id translated into the viewer's language.

version_label(version)

@spec version_label(term()) :: String.t()

A version number as a tag reads it, v1.2.0; a record without one reads as v0.0.1.