-
Notifications
You must be signed in to change notification settings - Fork 2
Yaml syntax
Templates files whose name ends in .yaml
will be parsed as YAML rather than JSON source.
Most JSON templates files can be treated as YAML without modification. The primary issue to be aware of is that the Yaml processor used does not allow tabs, not even outside of actual data content, so replace any tabs by spaces.
The primary benefits of Yaml in templates are:
- allows comments (
#
) - allows multi-line patterns - use literals (
|
) or folded-literals (>
) with indenting
The Yaml also offers a more readable syntax for lists and objects which may be preferred. See snakeyaml documentation for a more readable intro to YAML than the specification.
For example, the template:
{
"type" : "Composite",
"bind" : {"$base" : "http://example.com"},
"prefixes" : {
"foo" : "http://example.com/def/foo#",
"foo2" : "http://example.com/def/foo2#" },
"templates" : [
{
"required" : [ "label"],
"@id" : "<{$base}/{notation}>",
"<rdf:type>" : "<skos:Concept>",
"<foo:label>" : "{label}",
"<foo2:label>" : "{label}"
}
]
}
can be written as:
# Example composite template in Yaml
type : Composite
bind : {"$base" : "http://example.com"}
prefixes :
foo : http://example.com/def/foo#
foo2 : http://example.com/def/foo2#
templates :
- required : [ "label" ]
"@id" : <{$base}/{notation}>
<rdf:type> : <skos:Concept>
<foo:label> : "{label}"
<foo2:label> : "{label}"
or
# Example composite template in Yaml
type : Composite
bind :
$base : http://example.com
prefixes :
foo : http://example.com/def/foo#
foo2 : http://example.com/def/foo2#
templates :
- required : [ "label" ]
"@id" : <{$base}/{notation}>
<rdf:type> : <skos:Concept>
<foo:label> : "{label}"
<foo2:label> : "{label}"
Note that literal quotes ('
"
or multi-line literals >
or |
) are needed for patterns starting with {
otherwise YAML will mistake this for the start of a nested object.
An example of long literals is:
# Example template in Yaml
type : Composite
templates :
"@id" : <{$base}/{notation}>
<rdf:type> : <skos:Concept>
<rdfs:label> : >
this is a long
multi-line label,
though in this case it will be folded into a single line
in the resulting RDF