-
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
103 additions
and
0 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 |
---|---|---|
|
@@ -35,3 +35,5 @@ jspm_packages | |
|
||
# Optional REPL history | ||
.node_repl_history | ||
|
||
helper-output.js |
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 @@ | ||
testhelpers.js |
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,50 @@ | ||
|
||
module.exports = function (plop, config) { | ||
|
||
// setup config defaults | ||
const cfg = Object.assign({ | ||
prefix: '', | ||
upperCaseHeaders: false, | ||
blockStart: '/*', | ||
blockEnd: '*/', | ||
inlineStart: '//' | ||
}, config || {}); | ||
|
||
plop.setDefaultInclude({ helpers: true }); | ||
|
||
plop.addHelper(`${cfg.prefix}multi-line-header`, multiLineHeader); | ||
|
||
plop.addHelper(`${cfg.prefix}header`, function(text) { | ||
return multiLineHeader(text.split('\n')[0]); | ||
}); | ||
|
||
plop.addHelper(`${cfg.prefix}header-end`, function(text) { | ||
if (cfg.upperCaseHeaders) { text = text.toUpperCase(); } | ||
// one line only | ||
text = text.split('\n')[0]; | ||
|
||
const border = '=='; | ||
const padding = ' '; | ||
return `${cfg.inlineStart} ${border}${padding}END ${text}${padding}${border}`; | ||
}); | ||
|
||
function multiLineHeader(text) { | ||
if (cfg.upperCaseHeaders) { text = text.toUpperCase(); } | ||
const border = '=='; | ||
const padding = ' '; | ||
const lines = text.split('\n'); | ||
const longestLine = Math.max.apply(null, lines.map(line => line.length)); | ||
var out = `${cfg.blockStart} ${repeat('=', longestLine + (border.length * 2) + (padding.length * 2))}`; | ||
out += `\n${repeat(' ', cfg.blockStart.length)} ${border}${padding}`; | ||
out += lines.map(line => (line.length < longestLine ? line + repeat(' ', longestLine - line.length) : line)) | ||
.join(`${padding}${border}\n${repeat(' ', cfg.blockStart.length)} ${border}${padding}`); | ||
out += `${padding}${border}\n`; | ||
out += `${repeat(' ', cfg.blockStart.length)} ${repeat('=', longestLine + (border.length * 2) + (padding.length * 2))} ${cfg.blockEnd}`; | ||
|
||
return out; | ||
} | ||
}; | ||
|
||
function repeat(char, amt) { | ||
return (new Array(amt + 1)).join(char); | ||
} |
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,27 @@ | ||
{ | ||
"name": "plop-pack-fancy-comments", | ||
"version": "0.1.0", | ||
"description": "A set of plop helpers that provide some fancy code commenting", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "chokidar 'index.js' 'testhelpers.js' -c 'node testhelpers.js'" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+https://github.com/amwmedia/plop-pack-fancy-comments.git" | ||
}, | ||
"keywords": [ | ||
"plop", | ||
"plop-pack", | ||
"helpers" | ||
], | ||
"author": "Andrew Worcester", | ||
"license": "MIT", | ||
"bugs": { | ||
"url": "https://github.com/amwmedia/plop-pack-fancy-comments/issues" | ||
}, | ||
"homepage": "https://github.com/amwmedia/plop-pack-fancy-comments#readme", | ||
"devDependencies": { | ||
"chokidar-cli": "^1.2.0" | ||
} | ||
} |
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,23 @@ | ||
const fs = require('fs'); | ||
const path = require('path'); | ||
const helpers = {}; | ||
const plop = { | ||
setDefaultInclude: function () {}, | ||
addHelper: function (name, func) { | ||
helpers[name] = func; | ||
} | ||
}; | ||
|
||
require('./index')(plop); | ||
|
||
var output = ''; | ||
Object.keys(helpers).forEach(function (name) { | ||
const func = helpers[name]; | ||
output += (`\n// ${name}\n`); | ||
output += func('simple test text 1'); | ||
output += '\n\n'; | ||
output += func('simple test text 1\nthis also has a longer line'); | ||
output += '\n\n'; | ||
}); | ||
|
||
fs.writeFileSync(path.resolve('./helper-output.js'), output, {encoding: 'utf8'}); |