forked from tldr-pages/tldr-node-client
-
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.
- Loading branch information
1 parent
cf1c8f2
commit a898fb6
Showing
5 changed files
with
119 additions
and
26 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
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,55 @@ | ||
var _ = require('lodash'); | ||
var config = require('./config'); | ||
|
||
var theme = null; | ||
|
||
function getTheme() { | ||
if (!theme) { | ||
theme = loadTheme(); | ||
} | ||
return theme; | ||
} | ||
|
||
function loadTheme() { | ||
var themes = config.get().themes; | ||
var currentTheme = config.get().theme; | ||
return themes[currentTheme]; | ||
} | ||
|
||
function buildStylingFunction(styles) { | ||
if (_.isEmpty(styles)) { | ||
return _.identity; | ||
} | ||
var stylingFunction = require('chalk'); | ||
var stylesPath = styles.replace(/,\s*/, '.'); | ||
return _.get(stylingFunction, stylesPath); | ||
} | ||
|
||
function renderPart(partName, text) { | ||
// var theme = theme; | ||
var styles = getTheme()[partName]; | ||
var stylingFunction = buildStylingFunction(styles); | ||
return stylingFunction(text); | ||
} | ||
|
||
module.exports = { | ||
renderName: function(text) { | ||
return renderPart('name', text); | ||
}, | ||
|
||
renderDescription: function(text) { | ||
return renderPart('description', text); | ||
}, | ||
|
||
renderExampleDescription: function(text) { | ||
return renderPart('exampleDescription', text); | ||
}, | ||
|
||
renderExampleCode: function(text) { | ||
return renderPart('exampleCode', text); | ||
}, | ||
|
||
renderExampleArgument: function(text) { | ||
return renderPart('exampleArgument', text); | ||
} | ||
}; |
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