Views specs
Spec version 1.0.0-alpha.0
Why?
His goal is to describe a particular view like hello.twig
.
By describing the data that this view depends on, you can use that and build your backend automatically. Pretty usefull for medium/large projects.
Filename
A specification file has to be named with .spec.json
at his end. Usually this mean that if you have a view named card.twig
, the files will be something like this:
| src
| views
| components
| card
| card.twig
| card.spec.json
Structure
Here's an example of the card.spec.json file and how it can be written:
Note that the "cta" property is set to
@sugar.views.components.cta
. This is a link to another existing spec file that is available from the @coffeekraken/sugar package. To read a spec file, make use of the @coffeekraken/s-specs package that will resolve these links for you.
Data types
Here's the main data types that we think cover a lot of situations. Note that this is more to take as example that final types. You can specify your own types as well depending on your needs:
String
: Simple string dataText
: Similar as "String"Wysiwyg
: String that can contain formatting tagsDate
: Simple ISO date stringDateTime
: Simple ISO datetime stringTime
: Simple ISO time stringNumber
: Simple numberInteger
: Simple integer numberImage
: Simple image datasrc
: The source of the imagealt
: The alternative texttitle
: The image title
Object
: An object described by his ownprops
Repeatable types array
To define a prop as repeatable, simply suffix his type
with []
.
Here's a simple example
Resulting data
If we take the overview example above, the resulting data that has to be injected into the view at his render phase could be something like this: