Skip to content

Commit

Permalink
feat: add public GLOBALS helper to access Edge globals
Browse files Browse the repository at this point in the history
  • Loading branch information
thetutlage committed Apr 17, 2020
1 parent 452e648 commit 3fb2f7c
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 4 deletions.
1 change: 1 addition & 0 deletions src/Contracts/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ export type EdgeOptions = {
export interface EdgeContract {
loader: LoaderContract,
compiler: CompilerContract,
GLOBALS: { [key: string]: any },

registerTag (tag: TagContract): this,
registerTemplate (templatePath: string, contents: LoaderTemplate): this,
Expand Down
6 changes: 3 additions & 3 deletions src/Edge/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export class Edge implements EdgeContract {
/**
* Globals are shared with all rendered templates
*/
private globals: any = {}
public GLOBALS: { [key: string]: any } = {}

/**
* List of registered tags. Adding new tags will only impact
Expand Down Expand Up @@ -94,7 +94,7 @@ export class Edge implements EdgeContract {
* ```
*/
public global (name: string, value: any): this {
this.globals[name] = value
this.GLOBALS[name] = value
return this
}

Expand Down Expand Up @@ -162,7 +162,7 @@ export class Edge implements EdgeContract {
* can be used to define locals.
*/
public getRenderer (): EdgeRendererContract {
return new EdgeRenderer(this.compiler, this.globals)
return new EdgeRenderer(this.compiler, this.GLOBALS)
}

/**
Expand Down
2 changes: 1 addition & 1 deletion test/edge.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ test.group('Edge', (group) => {
test('register globals', (assert) => {
const edge = new Edge()
edge.global('foo', 'bar')
assert.deepEqual(edge['globals'].foo, 'bar')
assert.deepEqual(edge.GLOBALS.foo, 'bar')
})

test('add a custom tag to the tags list', (assert) => {
Expand Down

0 comments on commit 3fb2f7c

Please sign in to comment.