Documentationcurrent version
Help us improve the docs by fixing typos and proposing enhancements.

Nikita

Metadata "templated"

Nikita provides templating in configuration properties using the Handlebars templating engine. It traverses properties recursively and uses the same self-referenced object as a context. The templated metadata enables or disables templating.

Templating is disabled by default. Set metadata.templating to true to enable it. There is a performance penality to expect.

  • Type: boolean Default: false, inherited from parent

All the properties from the current action are available including config and metadata.

You can traverse relative actions with the parent, siblings and sibling properties as well. Those last three properties will no longer be available once an action has resolved.

Once it is resolved, in addition to the config and metadata properties, the action exposes the children property as well as one of the output or error properties depending on its outcome.

Usage

You can access all the properties of the current action. Here is an example accessible the output of the previous sibling:

nikita
.call({
  secret: 'my previous',}, function({config}) {
  return `My secret is "${config.secret}"`
})
.call({
  $templated: true,  secret: '{{{sibling.output}}}',}, function({config}) {
  console.info(config.secret)  // Print `My secret is "my previous"`
})

Dynamic references

It is not required to refer directly to a property. A property may refer to another property which itself refers to another property. Properties do not need to be set in any particular order. Their value is dynamically resolved and an error is thrown in case of a circular reference.

nikita({
  secret: 'my precious',
  $templated: true}, function(){
  this.call({
    my: 'My {{{config.secret}}}',    // Note the usage of triple-stash to avoid escaping html entities
    is: 'is "{{{parent.config.secret}}}"',    secret: 'secret {{{config.is}}}'  }, function({config}) {
    console.info(config.my)
    // Print `My secret is "my previous"`
  })
})

Accessing properties of resolved actions

The sibling property is no longer available once the action has resolved. The same goes for the parent and siblings properties. This example uses the parent and children properties:

nikita
.call({
  secret: 'my previous',}, function({config}) {
  return `My secret is "${config.secret}"`
})
.call(function({config}) {
  // Call a child action
  this.call({
    $templated: true,    // Note the usage of triple-stash to avoid escaping html entities
    secret: '{{{parent.parent.children.[0].output}}}',  }, function({config}) {
    console.info(config.secret)
    // Print `My secret is "my previous"`
  })
})

Desactivation

Templating is not enabled by default. If a parent action enables it, it can be desactivated with the value false:

nikita({
  $templated: true})
// Call an action with templating (by default)
.call({
  $templated: false,  key_1: 'value 1',
  key_2: 'value 2 and {{config.key_1}}'}, function({config}) {
  console.info(config.key_2)
  // Print "value 2 and {{config.key_1}}"
})

Note, the value applies to the action and all its children.

Edit on GitHub
Navigate
About

Nikita is an open source project hosted on GitHub and developed by Adaltas.