Updated Transforms And Templates (markdown) authored by Michael J Pearson's avatar Michael J Pearson
This is the Documentation for Snow 0.4, old 0.3 docs can be found [here](https://github.com/bipio-server/bipio/wiki/Transforms-And-Templates-(Sansa-0.3)).
Transforms are used by Bip `hub` objects to map and combine attributes between adjacent channels. They are a JSON object where the object keys are the named imports of a target channel on a hub and the value is the data to inject, evaluated as a text template.
Transforms are used by Bip `hub` objects to map and combine attributes between adjacent nodes. They are a JSON object where the object keys are the named imports of a target node on a hub and the value is the data to inject, evaluated as a text template.
For example if we have an [email.smtp_forward channel](https://bip.io/docs/pods/email) and we want to set two of its imports, `subject` and `body_text`. We can inject custom values like so :
For example if we have an [email.smtp_forward node](https://bip.io/docs/pods/email) and we want to set two of its imports, `subject` and `body_text`. We can inject custom values like so :
```
{
......@@ -11,11 +11,11 @@ For example if we have an [email.smtp_forward channel](https://bip.io/docs/pods/
}
```
Templates can also be interpolated with variables from upstream channels or metadata as [JSON Paths](http://goessner.net/articles/JsonPath/) if they take the form
Templates can also be interpolated with variables from parent nodes or metadata as [JSON Paths](http://goessner.net/articles/JsonPath/) if they take the form
`[%source.title%]`
`json_path` in the example means the [JSON Path](http://goessner.net/articles/JsonPath/) of an attribute exported by an upstream channel, keyed by either an explicit channel id, or `source` (ie: whatever the bip receives or generates). This means you can concatenate exports and text together to create a custom import. With the previous email example, lets assume we're using an `smtp` bip and want to pass through some of the details to an email channel on its hub :
`json_path` in the example means the [JSON Path](http://goessner.net/articles/JsonPath/) of an attribute exported by a parent node, keyed by either an explicit channel UUID, action pointer (`email.smtp_forward._0`), or `source` (ie: whatever the bip receives or generates). This means you can concatenate exports and text together to create a custom import. With the previous email example, lets assume we're using an `smtp` bip and want to pass through some of the details to an email channel on its hub :
```
{
......@@ -24,6 +24,10 @@ Templates can also be interpolated with variables from upstream channels or meta
}
```
## Type Casting
The system will attempt to correctly cast values to their appropriate types during import, immediately after transformation. Type casting is inferred from the `manifest.json` file for a pod.
## Object and Array Passthrough
Transform templates which only include a single JSONPath will be evaluated in-place, meaning that if the path evaluates to an object or array, then it will be replaced with that structured data.
......
......