View Source Pyro.Component.Helpers (Pyro v0.3.7)
A library of helpers for using/authoring Pyro components.
Summary
Functions
Provides a configurable fallback timezone. Defaults to "Etc/UTC"
.
Formats datetimes to localized format.
Safely get nested values from maps or keyword lists that may be nil
or an otherwise non-map value at any point. Great for accessing nested assigns in a template.
A JS
function to toggle CSS classes, since Phoenix does not yet provide one out of the box.
Translates the errors for a field from a keyword list of errors.
Functions
Provides a configurable fallback timezone. Defaults to "Etc/UTC"
.
# runtime.exs
config :pyro, default_timezone: "America/Chicago"
Note:
Requires a timezone database to be properly installed and configured.
format_datetime(timestamp, tz, formatter \\ &simple_datetime_formatter/1)
View SourceFormats datetimes to localized format.
Examples
iex> format_datetime(DateTime.new!(~D[2016-05-24], ~T[13:26:08.003], "Etc/UTC"), default_timezone())
"2016-05-24 13:26 UTC"
iex> format_datetime(~N[2000-01-01 23:00:07], "Etc/UTC")
"2000-01-01 23:00 UTC"
iex> format_datetime(~N[2000-01-01 23:00:07], "Etc/UTC", :date_time_seconds_timezone)
"2000-01-01 23:00:07 UTC"
iex> format_datetime(nil, "Etc/UTC")
""
iex> format_datetime("", "Etc/UTC")
""
Safely get nested values from maps or keyword lists that may be nil
or an otherwise non-map value at any point. Great for accessing nested assigns in a template.
Examples
iex> get_nested(nil, [:one, :two, :three])
nil
iex> get_nested(%{one: nil}, [:one, :two, :three])
nil
iex> get_nested(%{one: %{two: %{three: 3}}}, [:one, :two, :three])
3
iex> get_nested(%{one: %{two: [three: 3]}}, [:one, :two, :three])
3
iex> get_nested([one: :nope], [:one, :two, :three])
nil
iex> get_nested([one: :nope], [:one, :two, :three], :default)
:default
A JS
function to toggle CSS classes, since Phoenix does not yet provide one out of the box.
Examples
toggle_class("rotate-180 bg-green", to: "#icon")
Translates the errors for a field from a keyword list of errors.