Skip to content

Commit

Permalink
feat: outputHTML templatePath
Browse files Browse the repository at this point in the history
  • Loading branch information
LoeiFy committed May 24, 2019
1 parent 71707f2 commit 3caf6f3
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 2 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
## 3.4.0

- feat: hooks
- feat: outputHTML templatePath

## 3.3.2

Expand Down
9 changes: 7 additions & 2 deletions lib/utility/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ const { existsSync, outputFileSync } = require('fs-extra')

module.exports = function outputHTML({
template: tag,
templatePath: tplPath,
path,
data,
engine = 'swig',
Expand All @@ -14,11 +15,15 @@ module.exports = function outputHTML({
}

const methods = this.helper.get()
const tpl = join(templatePath, 'layout', `${tag}.html`)
const helpers = {}

let tpl = tplPath
if (!tpl) {
tpl = join(templatePath, 'layout', `${tag}.html`)
}

if (!existsSync(tpl)) {
this.logger.error(`Cannot find template: ${tag}.html`)
this.logger.error(`Cannot find template: ${tplPath || `${tag}.html`}`)
return
}

Expand Down
10 changes: 10 additions & 0 deletions test/utility/output.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,16 @@ describe('output', () => {
})
assert(readFileSync(resolve(__dirname, '../fixtures/temp/index.html'), 'utf8') === '<p>This is not h1</p>\n')

outputHTML.call(acyort, {
templatePath: join(config.templatePath, 'index.html'),
template: 'index',
path: 'index.html',
data: {
one: 1,
},
})
assert(readFileSync(resolve(__dirname, '../fixtures/temp/index.html'), 'utf8') === '<p>This is not h1</p>\n')

outputHTML.call(acyort, {
template: 'index',
path: 'index.html',
Expand Down

0 comments on commit 3caf6f3

Please sign in to comment.