Sablon.Props (sablon v0.4.4)

Copy Markdown View Source

An insertion-ordered property list.

WordML property tags are emitted in the order they were defined, and the Ruby implementation relies on Ruby's ordered hashes for that. Property keys are intentionally a mix of strings (CSS properties, which still need conversion) and atoms (WordML properties, which are used as-is), so this module keeps both without normalising them.

Summary

Functions

Removes a key.

Returns true when there are no properties.

Fetches a value, returning default when the key is absent.

Returns true when the key is present, even if its value is nil.

All keys in order.

Merges other into props. Keys already present keep their position but take the new value; unknown keys are appended.

Builds a property list from any enumerable of key/value pairs.

Sets a key, preserving its position when it already exists.

Types

key()

@type key() :: binary() | atom()

t()

@type t() :: [{key(), term()}]

Functions

delete(props, key)

@spec delete(t(), key()) :: t()

Removes a key.

empty?(props)

@spec empty?(t()) :: boolean()

Returns true when there are no properties.

get(props, key, default \\ nil)

@spec get(t(), key(), term()) :: term()

Fetches a value, returning default when the key is absent.

has_key?(props, key)

@spec has_key?(t(), key()) :: boolean()

Returns true when the key is present, even if its value is nil.

keys(props)

@spec keys(t()) :: [key()]

All keys in order.

merge(props, other)

@spec merge(t(), t() | map()) :: t()

Merges other into props. Keys already present keep their position but take the new value; unknown keys are appended.

new(enumerable \\ [])

@spec new(Enumerable.t()) :: t()

Builds a property list from any enumerable of key/value pairs.

put(props, key, value)

@spec put(t(), key(), term()) :: t()

Sets a key, preserving its position when it already exists.