Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(theme-as-promise): allow theme to render with promise
- Loading branch information
Showing
4 changed files
with
76 additions
and
47 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
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,20 @@ | ||
const path = require('path') | ||
const chalk = require('chalk') | ||
|
||
module.exports = async function renderHtml(resumeJson, theme) { | ||
if (!theme.match('jsonresume-theme-.*')) { | ||
theme = 'jsonresume-theme-' + theme | ||
} | ||
|
||
const themePath = path.resolve(process.cwd(), 'node_modules', theme) | ||
const render = require(themePath).render | ||
|
||
if (typeof render !== 'function') { | ||
console.log( | ||
chalk.yellow('Could not run the render function from local theme.'), | ||
) | ||
return Promise.reject(new Error(`Can't render with "${theme}"'s theme`)) | ||
} | ||
|
||
return render(resumeJson) | ||
} |
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,40 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const should = require('should'); | ||
const renderHtml = require('../lib/render-html'); | ||
|
||
describe('renderHtml', () => { | ||
const resumeJson = { | ||
basics: { | ||
name: 'test', | ||
label: 'Programmer', | ||
email: 'test4@test.com', | ||
}, | ||
}; | ||
|
||
it('should reject when theme is not availlable', async () => { | ||
const theme = 'unkown'; | ||
|
||
const result = renderHtml(resumeJson, theme); | ||
|
||
return result.should.be.rejected(); | ||
}); | ||
|
||
describe('should render html when theme is availlable', () => { | ||
it('with long theme name', async () => { | ||
const theme = 'jsonresume-theme-flat'; | ||
|
||
const html = await renderHtml(resumeJson, theme); | ||
|
||
return html.should.startWith('<!doctype html>'); | ||
}); | ||
|
||
it('with short theme name', async () => { | ||
const theme = 'flat'; | ||
|
||
const html = await renderHtml(resumeJson, theme); | ||
|
||
return html.should.startWith('<!doctype html>'); | ||
}); | ||
}); | ||
}); |