Skip to content
This repository has been archived by the owner on Jul 22, 2020. It is now read-only.

Commit

Permalink
add support for docs
Browse files Browse the repository at this point in the history
  • Loading branch information
Mihkel Eidast committed Dec 5, 2019
1 parent 91bc020 commit f0087e3
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 2 deletions.
25 changes: 24 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,29 @@ fractal.components.engine(twigAdapter);
fractal.components.set('ext', '.twig');
```

## Using Twig for docs

To use Twig for docs, set the docs engine to `@frctl/twig`:
```
fractal.docs.engine(twigAdapter);
```

However, due to the way this adapter currently extends Twig, it is necessary to *set the docs engine before setting the components engine*.

```
/*
* Require the Twig adapter
*/
const twigAdapter = require('@frctl/twig')();
// first set docs engine
fractal.docs.engine(twigAdapter);
// then set components engine
fractal.components.engine(twigAdapter);
```


## Extending with a custom config
```
/*
Expand All @@ -39,7 +62,7 @@ const twigAdapter = require('@frctl/twig')({
// this will change your includes to {% include '%button' %}
// default is '@'
handlePrefix: '%',
// set a base path for twigjs
// Setting base to '/' will make sure all resolved render paths
// start at the defined components dir, instead of being relative.
Expand Down
2 changes: 1 addition & 1 deletion src/adapter.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ class TwigAdapter extends Fractal.Adapter {
let prefixMatcher = new RegExp(`^\\${self._config.handlePrefix}`);
let entity = source.find(handle.replace(prefixMatcher, '@'));
if (entity) {
entity = entity.isVariant ? entity : entity.variants().default();
entity = entity.isComponent ? entity.variants().default() : entity;
if (config.importContext) {
context = utils.defaultsDeep(_.cloneDeep(context), entity.getContext());
context._self = entity.toJSON();
Expand Down

0 comments on commit f0087e3

Please sign in to comment.