Calendrical.Format
(Calendrical v0.3.0)
Copy Markdown
Renders Calendrical calendars as years, months, weeks, and days using a pluggable formatter.
Calendrical.Format walks a calendar at year, month, or week granularity and
delegates the actual rendering to a formatter module that implements the
Calendrical.Formatter behaviour. The library ships with HTML and Markdown
formatters; the default formatter is returned by default_formatter_module/0.
Custom formatters can be added by implementing the Calendrical.Formatter
behaviour (format_year/3, format_month/4, format_week/5, and
format_day/4).
All entry points (year/2, month/3) accept a keyword list of options.
Summary
Functions
Returns the default CSS class used by the HTML formatters when wrapping a calendar in a container element.
Returns true if the given module appears to implement the
Calendrical.Formatter behaviour.
Formats one calendar month using the configured formatter.
Formats one calendar year using the configured formatter.
Functions
Returns the default CSS class used by the HTML formatters when wrapping a calendar in a container element.
Returns
- A string. Currently
"cldr_calendar".
Examples
iex> Calendrical.Format.default_calendar_css_class()
"cldr_calendar"
Returns the default formatter module used when no :formatter option is
given to year/2 or month/3.
Returns
- The module name of the default HTML formatter.
Examples
iex> Calendrical.Format.default_formatter_module()
Calendrical.Formatter.HTML.Basic
Returns true if the given module appears to implement the
Calendrical.Formatter behaviour.
The check is a runtime duck-typing check: the module is loaded and inspected
for an exported format_year/3 function.
Arguments
formatteris a module name.
Returns
trueif the module exportsformat_year/3, otherwisefalse.
Examples
iex> Calendrical.Format.formatter_module?(Calendrical.Formatter.HTML.Basic)
true
iex> Calendrical.Format.formatter_module?(String)
false
@spec month(Calendar.year(), Calendar.month(), Keyword.t() | map()) :: any()
Formats one calendar month using the configured formatter.
Arguments
yearis the year of the calendar to be formatted.monthis the month of the calendar to be formatted.optionsis a keyword list of options.
Options
:calendaris the Calendrical calendar module to format. Defaults toCalendrical.Gregorian.:formatteris the formatter module. Defaults to the value ofdefault_formatter_module/0.:localeis a locale identifier atom, string, or aLocalize.LanguageTag.t/0. The default isLocalize.get_locale/0.Any additional formatter-specific options are passed through to the formatter callbacks.
Returns
- The value returned by the
format_month/4callback of the configured formatter.
Examples
=> Calendrical.Format.month(2019, 4)
=> Calendrical.Format.month(2019, 4)
=> Calendrical.Format.month(2019, 4, formatter: Calendrical.Formatter.Markdown, locale: "fr")
@spec year(Calendar.year(), Keyword.t() | map()) :: any()
Formats one calendar year using the configured formatter.
Arguments
yearis the year of the calendar to be formatted.optionsis a keyword list of options.
Options
:calendaris the Calendrical calendar module to format. Defaults toCalendrical.Gregorian.:formatteris the formatter module. Defaults to the value ofdefault_formatter_module/0.:localeis a locale identifier atom, string, or aLocalize.LanguageTag.t/0. The default isLocalize.get_locale/0.Any additional formatter-specific options are passed through to the formatter callbacks.
Returns
- The value returned by the
format_year/3callback of the configured formatter.
Examples
=> Calendrical.Format.year(2019)
=> Calendrical.Format.year(2019, formatter: Calendrical.Formatter.Markdown)
=> Calendrical.Format.year(2019, formatter: Calendrical.Formatter.Markdown, locale: "fr")