Skip to content

Commit

Permalink
[feat] make Email and template like a true Fabrix Generic
Browse files Browse the repository at this point in the history
  • Loading branch information
scott-wyatt committed Jul 5, 2018
1 parent 12ff9b0 commit ef71bb6
Show file tree
Hide file tree
Showing 4 changed files with 59 additions and 67 deletions.
34 changes: 28 additions & 6 deletions lib/Email.ts
Original file line number Diff line number Diff line change
@@ -1,19 +1,20 @@
import { EventEmitter } from 'events'
import { FabrixApp } from '@fabrix/fabrix'
import { FabrixGeneric } from '@fabrix/fabrix/dist/common'
import * as stripTags from 'striptags'

export class Email extends FabrixGeneric {
methods
compose
private _app: FabrixApp
public compose

constructor (app: FabrixApp) {
if (!(app instanceof EventEmitter)) {
throw new Error('The "app" argument must be of type EventEmitter')
}
super(app)
this._app = app

Object.defineProperties(this, {
app: {
enumerable: false,
value: app
},
/**
* If the Email is now immutable
*/
Expand Down Expand Up @@ -68,6 +69,27 @@ export class Email extends FabrixGeneric {
writable: true
}
})

this.app.emit(`controller:${this.id}:constructed`, this)
}

/**
* Reference to i18n
*/
get __ () {
if (this.app.__) {
return this.app.__
}
else {
throw new Error('Missing spool-i18n, make sure it is included in app.main.spools')
}
}

/**
* Get the Fabrix App Instance that Template was constructed with
*/
get app(): FabrixApp {
return this._app
}

/**
Expand Down
34 changes: 28 additions & 6 deletions lib/Template.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,22 @@
import { EventEmitter } from 'events'
import { FabrixApp } from '@fabrix/fabrix'
import { FabrixGeneric } from '@fabrix/fabrix/dist/common'

// https://www.npmjs.com/package/ejs
import * as ejs from 'ejs'

export class Template extends FabrixGeneric {
ejs
methods
private _app: FabrixApp
public ejs

constructor (app: FabrixApp) {
if (!(app instanceof EventEmitter)) {
throw new Error('The "app" argument must be of type EventEmitter')
}
super(app)
this._app = app

Object.defineProperties(this, {
app: {
enumerable: false,
value: app
},
ejs: {
enumerable: false,
value: function (input, data, options) {
Expand All @@ -27,6 +28,27 @@ export class Template extends FabrixGeneric {
writable: true
}
})

this.app.emit(`controller:${this.id}:constructed`, this)
}

/**
* Reference to i18n
*/
get __ () {
if (this.app.__) {
return this.app.__
}
else {
throw new Error('Missing spool-i18n, make sure it is included in app.main.spools')
}
}

/**
* Get the Fabrix App Instance that Template was constructed with
*/
get app(): FabrixApp {
return this._app
}

/**
Expand Down
55 changes: 1 addition & 54 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "@fabrix/spool-email",
"version": "1.0.0",
"version": "1.0.1",
"description": "Spool - Emails",
"homepage": "https://fabrix.app",
"author": {
Expand Down Expand Up @@ -41,6 +41,7 @@
"@fabrix/fabrix": "^1.0.3",
"@fabrix/lint": "^1.0.0-alpha.3",
"@fabrix/spool-i18n": "^1.0.0",
"@fabrix/spool-router": "^1.0.0",
"@types/node": "~10.3.4",
"lodash": "^4.17.4",
"mocha": "^5",
Expand Down

0 comments on commit ef71bb6

Please sign in to comment.