Skip to content

Commit

Permalink
Fix docs
Browse files Browse the repository at this point in the history
  • Loading branch information
jpsca committed Apr 25, 2024
1 parent 91bdfb8 commit b5df925
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 8 deletions.
24 changes: 16 additions & 8 deletions docs/content/guide/index.mdx
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,17 @@ catalog.jinja_env.tests.update({ ... })
catalog.jinja_env.extensions.extend([ ... ])
```

The ["do" extension](https://jinja.palletsprojects.com/en/3.0.x/extensions/#expression-statement) is enabled by default, so you can write things like:

```html+jinja
{% do attrs.set(class="btn", disabled=True) %}
```

### Reusing an existing Jinja Environment

You can also reuse an existing Jinja Environment, for example:
**Flask**:

#### Flask:

```python
app = Flask(__name__)
Expand All @@ -93,9 +102,13 @@ app = Flask(__name__)
catalog = jinjax.Catalog(jinja_env=app.jinja_env)

```
**Django**:
(configure jinja in setting.py and [jinja_env.py](https://docs.djangoproject.com/en/5.0/topics/templates/#django.template.backends.jinja2.Jinja2))

#### Django:

First, configure Jinja in setting.py and [jinja_env.py](https://docs.djangoproject.com/en/5.0/topics/templates/#django.template.backends.jinja2.Jinja2))

To have a separate "components" folder for shared components and also have "components" subfolder at each django app level

```python
import jinjax
from jinja2.loaders import FileSystemLoader
Expand All @@ -115,8 +128,3 @@ def environment(loader: FileSystemLoader, **options):
return env
```

The ["do" extension](https://jinja.palletsprojects.com/en/3.0.x/extensions/#expression-statement) is enabled by default, so you can write things like:

```html+jinja
{% do attrs.set(class="btn", disabled=True) %}
```
27 changes: 27 additions & 0 deletions docs/indexer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
var lunr = require("lunr");
require("lunr-languages/lunr.stemmer.support")(lunr);
const fs = require("node:fs");

function build_index([lang, outpath]) {
lang = lang || "en"
outpath = outpath || "."

if (lang !== "en") {
const lunr_lang = require(`lunr-languages/lunr.${lang}`)(lunr);
this.use(lunr_lang);
}

const idx = lunr(function() {
this.ref("id");
this.field("title", { boost: 10 });
this.field("body");
const docs = JSON.parse(fs.readFileSync(`${outpath}/docs-${lang}.json`));

for (let doc in docs) {
this.add(doc)
}
})
fs.writeFileSync(`${outpath}/search-${lang}.json`, JSON.stringify(idx));
}

build_index(process.argv.slice(2));

0 comments on commit b5df925

Please sign in to comment.