Skip to main content

Snippets

Cenit uses the "Snippet" concept to refer pieces of code of algorithms, translators and data types definition. When you create a data type or any kind of algorithm, Cenit let you know a snippet will be implicitly created to store the data type schema or the algorithm code.

You may also manipulate snippets via Cenit IO API V2. See the spec for snippets in Cenit IO API V2 Specifications.

snippets

The Compute/Snippets submenu allows to manage the snippets.

snippets menu

As mentioned before, when creating a data type or algorithm, Cenit implicitly creates a snippet and links it with the created element. The behavior is pretty similar when that element or snippet is being edited, except for those snippets which have been shared with other tenants.

snippets  edit button

The window for editing the snippet is shown:

snippets edit1

There is another way which clarifies the process. Since a snippet is linked with a father element and that element contains the snippet's reference, you may access the snippet from its father element. Any change you make in the snippet means a change in the father element as well, so by accessing the snippet from its father, the probability of misleading the snippet to edit is low.

In the father element window you can click the snippet name:

snippets algorithm edit

and a new window for inspecting the snippet is shown:

snippet show

You should notice the window above only shows the snippet details. For editing the snippet you must click the Edit button and then you will be able to edit:

snippets edit1

Editing the snippet code is fine. However, editing the code directly in the father window use to be more convenient. For example, when editing the snippet linked with a Converter Translator, there is a lot of context to be aware of. If you decide to edit the code in the snippet as shown below:

snippet edit code in snippet

some questions might arise:

  • Would I use the variable "source" or "sources"?

  • Which is the source data type?

  • Which is the target data type?

By editing the snippet code directly in the father windows, the lack of context can be solved:

snippet in father

The context issue is present not only when dealing with translators, but also with generic algorithms. For example, if one or more parameters were defined in the algorithm, the parameter's name and type is not available when editing the code in the snippet window. So, editing the code directly in the father window is probably the best option.

Editing shared snippets​

When a father element and, consequently its snippet, are shared with other tenants, editing the snippet bring about the creation of a new snippet.

For example, we shared an algorithm an its snippet to all the user's tenants, as shown in both pictures below. You can notice there that the algorithm json_sent is shared in tenants JoeTest and JoeSlack.

snipped algorithm tenant 1 edit button

snipped algorithm tenant 2 edit button

When editing the shared algorithm a warning is shown in the code warning area. The alert lets you know the snippet is shared and therefore it's not editable. It shows another advice: if you continue editing and you save changes, a new snippet will be created.

snipped algorithm tenant 1 edit window

snipped algorithm tenant 2 edit window

So we modified the code in tenant JoeSlack and save as shown below:

snipped algorithm tenant 2 edit window change

As a result a new snippet was created and it's now editable. You should notice the warning message changed:

snippet non shared inside algorithm

If we check the snippet list, we can confirm a new snippet was created and it appears as non shared. A default name was generated for the snippet, but it can be changed considering that snippet is now editable.

snippet non shared

In the snippet list we can also check the shared original snippet continue being shared.

snippet shared