-
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
Showing
5 changed files
with
121 additions
and
75 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,84 @@ | ||
/** | ||
* ``` | ||
* _____ ___ _ _ _____ ___ | ||
* |_ _/ _ \| \| |_ _/ _ \ | ||
* | || (_) | .` | | || (_) | | ||
* |_| \___/|_|\_| |_| \___/.JS | ||
* APACHE CONFIG FILE GENERATOR | ||
* ``` | ||
* # TontoDirectiveRenderer.js | ||
* | ||
* Renders TontoDirectives into valid apache config strings. | ||
* | ||
* @class TontoDirectiveRenderer | ||
* @constructor | ||
*/ | ||
function TontoDirectiveRenderer() {} | ||
|
||
module.exports = TontoDirectiveRenderer; | ||
|
||
(function TontoDirectiveNamespace(TontoDirectiveRenderer) { | ||
|
||
'use strict'; | ||
|
||
TontoDirectiveRenderer.render = render; | ||
|
||
function render(directive) { | ||
|
||
if (directive.directives) { | ||
return renderBlock(directive); | ||
} else { | ||
return renderSolo(directive); | ||
} | ||
} | ||
|
||
function renderBlock(directive) { | ||
|
||
var startTag = renderStartTag(directive), | ||
content = renderBlockContent(directive), | ||
endTag = renderEndTag(directive); | ||
|
||
content = addTabination(content); | ||
|
||
return [startTag, content, endTag].join('\n'); | ||
|
||
} | ||
|
||
function addTabination(content) { | ||
content = content.split('\n'); | ||
content.forEach(addTab); | ||
function addTab(contentLine, index) { | ||
content[index] = '\t' + contentLine; | ||
} | ||
return content.join('\n'); | ||
} | ||
|
||
function renderStartTag(directive) { | ||
return '<' + directive.name + ' ' + directive.value + '>'; | ||
} | ||
|
||
function renderEndTag(directive) { | ||
return '</' + directive.name + '>'; | ||
} | ||
|
||
function renderBlockContent(directive) { | ||
|
||
var content = []; | ||
|
||
directive.directives.forEach(renderToContent); | ||
|
||
function renderToContent(directive) { | ||
content.push(directive.render()); | ||
} | ||
|
||
return content.join('\n'); | ||
|
||
} | ||
|
||
function renderSolo(directive) { | ||
|
||
return directive.name + ' ' + directive.value; | ||
|
||
} | ||
|
||
})(TontoDirectiveRenderer); |
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