-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- use dustjs as template engine - wrap its callback based API using node native promise
- Loading branch information
Showing
6 changed files
with
66 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
/** | ||
* Created by at15 on 2016/9/12. | ||
*/ | ||
'use strict'; | ||
|
||
const Command = require('../lib/cli/command'); | ||
const logger = require('../lib/logger'); | ||
|
||
let renderCmd = new Command(); | ||
renderCmd.name = 'render'; | ||
renderCmd.description = 'render template to html with data from config file and markdown'; | ||
renderCmd.setFunc((app, args, flags) => { | ||
logger.info('try to render file', {file: args[0]}); | ||
}); | ||
|
||
module.exports = renderCmd; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
<html> | ||
<head> | ||
<title>{title}</title> | ||
</head> | ||
<body> | ||
|
||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
/** | ||
* Created by at15 on 2016/9/12. | ||
*/ | ||
'use strict'; | ||
|
||
const dust = require('dustjs-linkedin'); | ||
let compiled = dust.compile('this {title}', 'hello'); | ||
dust.loadSource(compiled); | ||
|
||
// based on http://stackoverflow.com/questions/22519784/how-do-i-convert-an-existing-callback-api-to-promises | ||
function renderAsync() { | ||
// Promise is already in node | ||
return new Promise((resolve, reject) => { | ||
dust.render('hello', {title: 'foo'}, function (err, out) { | ||
if (err != null) { | ||
// TODO: is return necessary and which position should it be? | ||
// return reject(err); | ||
reject(err); | ||
return; | ||
} | ||
resolve(out); | ||
}); | ||
}); | ||
} | ||
|
||
let p = renderAsync(); | ||
p.then((out) => { | ||
console.log(out); | ||
}).catch((e) => { | ||
console.error(e); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters