Liking cljdoc? Tell your friends :D
All platforms.

fmnoise.template


templateclj/s

(template options)
(template {:keys [=> default defaults on-missing throw? remove-nils? throw-on
                  brackets]
           :as options}
          values)

Replaces placeholders in template form (string or data structure) with values from supplied source (should compatible with clojure.core/get). Keys in map can be either keywords or symbols or strings. String placeholder shoud be valid keyword name (without colon) in curly/square/angle braces (configurable) eg {name}, {user/name}, [user/name], <user/name>. String placeholder can contain desired format separated with colon eg {order/date:%tD}. Data placeholder should be valid keyword name (without colon) in angle braces represented as keyword eg :<name> or :<user/name>. Data placeholders can't contain formatting. First argument could be either template string, template data structure (if :=> key is missing) or options map. If first argument is a template data structure, options could be supplied as structure metadata. The following options are supported: :=> - template form: string or data structure :default - sets a default for all missing values :defaults - a map with default values for certain keys :on-missing - a 1-arg function which accepts a map with :name (contains placeholder name) and :values (contains values map) :throw? or :throw (when supplied as meta) - specifies if exception should be thrown in case of missing value and not having any defaults (defaults to false) :remove-nils? or :remove-nils (when supplied as meta) - specifies if binding for missing value should be removed. Makes the most sense for data templates. :throw-on - a set with keys which should be always provided either through values map or defaults map :brackets - a keyword indicating types of brackets used for placeholders in template string. Valid options are:

  • :curly (default) eg {user/name}
  • :square eg [user/name]
  • :angle eg <user/name>

Value for each key is resolved in the following order:

  1. keyword key lookup in supplied values and defaults (if present)
  2. string key lookup in supplied values and defaults (if present)
  3. symbol key lookup in supplied values and defaults (if present)
  4. if on-missing is provided, it's called with key name and values object
  5. if throw-on is provided and has either keyword or string or symbol key then ExceptionInfo is thrown
  6. if default is provided, it's used
  7. if throw? is set to true then ExceptionInfo is thrown
Replaces placeholders in template form (string or data structure) with values from supplied source (should compatible with `clojure.core/get`).
Keys in map can be either keywords or symbols or strings.
String placeholder shoud be valid keyword name (without colon) in curly/square/angle braces (configurable) eg {name}, {user/name}, [user/name], <user/name>.
String placeholder can contain desired format separated with colon eg {order/date:%tD}.
Data placeholder should be valid keyword name (without colon) in angle braces represented as keyword eg :<name> or :<user/name>.
Data placeholders can't contain formatting.
First argument could be either template string, template data structure (if `:=>` key is missing) or options map.
If first argument is a template data structure, options could be supplied as structure metadata.
The following options are supported:
`:=>` - template form: string or data structure
`:default` - sets a default for all missing values
`:defaults` - a map with default values for certain keys
`:on-missing` - a 1-arg function which accepts a map with `:name` (contains placeholder name) and `:values` (contains values map)
`:throw?` or `:throw` (when supplied as meta) - specifies if exception should be thrown in case of missing value and not having any defaults (defaults to false)
`:remove-nils?` or `:remove-nils` (when supplied as meta) - specifies if binding for missing value should be removed. Makes the most sense for data templates.
`:throw-on` - a set with keys which should be always provided either through values map or defaults map
`:brackets` - a keyword indicating types of brackets used for placeholders in template string. Valid options are:
   - `:curly` (default) eg {user/name}
   - `:square` eg [user/name]
   - `:angle` eg <user/name>

Value for each key is resolved in the following order:
1. `keyword` key lookup in supplied values and defaults (if present)
2. `string` key lookup in supplied values and defaults (if present)
3. `symbol` key lookup in supplied values and defaults (if present)
4. if `on-missing` is provided, it's called with key name and values object
5. if `throw-on` is provided and has either keyword or string or symbol key then `ExceptionInfo` is thrown
6. if `default` is provided, it's used
7. if `throw?` is set to true then `ExceptionInfo` is thrown
sourceraw docstring

template-keysclj/s

(template-keys form)
(template-keys form {:keys [brackets as]})

Returns set of keys used in given template form (string or data). Can accept options as optional 2nd argument: :as - determines how to interpret the keys, possible values are: :symbols, :strings, :keywords (default) :brackets - a keyword indicating types of brackets used for placeholders in string template form. Valid options are:

  • :curly (default) eg {user/name}
  • :square eg [user/name]
  • :angle eg <user/name>
Returns set of keys used in given `template` form (string or data). Can accept options as optional 2nd argument:
`:as` - determines how to interpret the keys, possible values are: `:symbols`, `:strings`, `:keywords` (default)
`:brackets` - a keyword indicating types of brackets used for placeholders in string template form. Valid options are:
 - `:curly` (default) eg {user/name}
 - `:square` eg [user/name]
 - `:angle` eg <user/name>
sourceraw docstring

cljdoc is a website building & hosting documentation for Clojure/Script libraries

× close