Mustache

Transformer, generates text files using the {{ mustache }} template.

Entity class IRI
IRI of the RDF class of the objects, to which the {{ mustache }} template is applied.
Mustache template
The {{ mustache }} template

Characteristics

ID
t-mustache
Type
transformer
Inputs
RDF data
Outputs
Files
Look in pipeline
Mustache
Sample pipeline
available

First, we recommend the potential user of this component to get to know the library itself and its demo. There, a template and a sample JSON file with data are shown and the resulting text can be generated. In LinkedPipes ETL, we work with RDF, therefore, the template placeholders will be IRIs and the data will be stored as RDF.

Mustache input data in JSON and in RDF

Below, you can see the original Mustache input data from the demo in JSON and the same input data in RDF. This can be used for comparison, because the structure and meaning remains the same.

Input data in JSON

{
  "header": "Colors",
  "items": [
      {"name": "red", "first": true, "url": "#Red"},
      {"name": "green", "link": true, "url": "#Green"},
      {"name": "blue", "link": true, "url": "#Blue"}
  ],
  "empty": false
}

Input data in RDF (Turtle)

<http://localhost/resources/1> a <http://localhost/outputClass> ;
  <http://localhost/ontology/header> "Colors" ;
  <http://localhost/ontology/item> <http://localhost/resources/1/1> ;
  <http://localhost/ontology/item> <http://localhost/resources/1/2> ;
  <http://localhost/ontology/item> <http://localhost/resources/1/3> ;
  <http://localhost/ontology/isEmpty> false ;
  <http://plugins.linkedpipes.com/ontology/t-mustache#fileName> "file.html" .

<http://localhost/resources/1/1> 
  <http://localhost/ontology/name> "blue" ; 
  <http://localhost/ontology/link> true ;
  <http://localhost/ontology/url> "#Blue" ;
  <http://plugins.linkedpipes.com/ontology/t-mustache#order> 2 .

<http://localhost/resources/1/2> 
  <http://localhost/ontology/name> "red" ; 
  <http://localhost/ontology/first> true ;
  <http://localhost/ontology/url> "#Red" ;
  <http://plugins.linkedpipes.com/ontology/t-mustache#order> 1 .

<http://localhost/resources/1/3> 
  <http://localhost/ontology/name> "green" ; 
  <http://localhost/ontology/link> true ;
  <http://localhost/ontology/url> "#Green" ;
  <http://plugins.linkedpipes.com/ontology/t-mustache#order> 3 .

Mustache templates for JSON and for RDF

Below, you can see the original {{ mustache }} template from the demo for the JSON data and the same template usable for RDF data in LP-ETL. This can be used for comparison, because the structure and meaning remains the same.

Template for demo JSON


<h1>{{header}}</h1>
{{#bug}}
{{/bug}}

{{#items}}
  {{#first}}
    <li><strong>{{name}}</strong></li>
  {{/first}}
  {{#link}}
    <li><a href="{{url}}">{{name}}</a></li>
  {{/link}}
{{/items}}

{{#empty}}
  <p>The list is empty.</p>
{{/empty}}

Template for LP-ETL


<h1>{{http://localhost/ontology/header}}</h1>
{{#bug}}
{{/bug}}

{{#http://localhost/ontology/item}}
  {{#http://localhost/ontology/first}}
    <li><strong>{{http://localhost/ontology/name}}</strong></li>
  {{/http://localhost/ontology/first}}
  {{#http://localhost/ontology/link}}
    <li><a href=\"{{http://localhost/ontology/url}}\">{{http://localhost/ontology/name}}</a></li>
  {{/http://localhost/ontology/link}}
{{/http://localhost/ontology/item}}

{{#http://localhost/ontology/isEmpty}}
  <p>The list is empty.</p>
{{/http://localhost/ontology/isEmpty}}

Output in HTML

The templates, when executed on the input data, both JSON data and JSON template and RDF data and LP-ETL template, produce the same result, which in this case is the following simple HTML. A sample importable {{ mustache }} pipeline fragment is available.

<h1>Colors</h1>
<li><strong>red</strong></li>
<li><a href="#Green">green</a></li>
<li><a href="#Blue">blue</a></li>

LP-ETL template specifics

The component looks in the input data for the instances of the entity class specified in the configuration and executes the template on each one. In our example, the entity class was http://localhost/outputClass. Note that only values stored in literals can be used by the template as IRIs are used to connect one object to another. In the case that you need to output the IRI itself, you can generate a literal version of it using, e.g. the SPARQL update before passing the data to the {{ mustache }} component. In addition to the standard {{ mustache }} usage, in LP-ETL templates there are special properties, using which you can further customize the outputs.

Output filename

The output filename property, denoted by the http://plugins.linkedpipes.com/ontology/t-mustache#fileName IRI, which can be attached to the entity class instance, can be used to generate a different file for each entity class instance.

List item order

One of the key {{ mustache }} concepts is a list of items. In JSON, the order of the items is given implicitly, because JSON is a tree and therefore each node has an ordered sequence of children. In RDF, the order of the list items needs to be specified explicitly, because the RDF data model is a generic graph. We could have used the RDF list, however, it seemed that the explicit order will be more usable. The property is denoted by the http://plugins.linkedpipes.com/ontology/t-mustache#order IRI and can be attached to a list item.

Prefixes in templates


{{!
  PREFIX on: <http://localhost/ontology/>
}}
<h1>{{on:header}}</h1>
IRI: {{on:iri}}

{{#on:item}}
  {{#on:first}}
    <li><strong>{{http://localhost/ontology/name}}</strong>
      <a [email protected]}}>[email protected]}}</a>
    </li>
  {{/on:first}}
  {{#on:link}}
    <li><a href="{{on:url}}">{{on:name}}</a></li>
  {{/on:link}}
{{/on:item}}

In order to declare namespace prefixes, you can start your Mustache template with a comment (i.e. {{! comment }}) that contains namespace declarations in the SPARQL syntax.

Generating lists

When you are generating lists, for example in JSON, you may want to use the "Add the mustache:first predicate to first items of input lists" option, which adds the http://plugins.linkedpipes.com/ontology/t-mustache#first predicate to the first item of each input list. You can then skip adding the list separator for that item like so:

{{^http://plugins.linkedpipes.com/ontology/t-mustache#first}}
,
{{/http://plugins.linkedpipes.com/ontology/t-mustache#first}}