Skip to content

Commit

Permalink
switch global context back to global functions using new hopefully fa…
Browse files Browse the repository at this point in the history
…st method for retrieving hass object
  • Loading branch information
Nerwyn committed Sep 22, 2024
1 parent 267218a commit 6117631
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
11 changes: 6 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
import nunjucks from 'nunjucks';
import { CONTEXT } from './context';
import { addFilters } from './filters';
import { addGlobals } from './globals';
import { addTests } from './tests';
import { buildStatesObject } from './utils/states';
export let HASS;
nunjucks.installJinjaCompat();
const env = addTests(addFilters(new nunjucks.Environment()));
const env = addTests(addFilters(addGlobals(new nunjucks.Environment())));
/**
* Render a Home Assistant template string using nunjucks
* @param {HomeAssistant} hass The Home Assistant object
Expand All @@ -19,9 +20,9 @@ export function renderTemplate(hass, str, context) {
HASS = hass;
str = env
.renderString(structuredClone(str), {
// hass,
// _states: buildStatesObject(hass),
...CONTEXT(hass),
hass,
_states: buildStatesObject(hass),
// ...CONTEXT(hass),
...context,
})
.trim();
Expand Down
11 changes: 6 additions & 5 deletions src/index.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,14 @@
import { HomeAssistant } from 'custom-card-helpers';
import nunjucks from 'nunjucks';

import { CONTEXT } from './context';
import { addFilters } from './filters';
import { addGlobals } from './globals';
import { addTests } from './tests';
import { buildStatesObject } from './utils/states';

export let HASS: HomeAssistant;
nunjucks.installJinjaCompat();
const env = addTests(addFilters(new nunjucks.Environment()));
const env = addTests(addFilters(addGlobals(new nunjucks.Environment())));

/**
* Render a Home Assistant template string using nunjucks
Expand All @@ -29,9 +30,9 @@ export function renderTemplate(
HASS = hass;
str = env
.renderString(structuredClone(str), {
// hass,
// _states: buildStatesObject(hass),
...CONTEXT(hass),
hass,
_states: buildStatesObject(hass),
// ...CONTEXT(hass),
...context,
})
.trim();
Expand Down

0 comments on commit 6117631

Please sign in to comment.