-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Patch handlebars, eliminate
hbs
global variable
- Loading branch information
Showing
10 changed files
with
579 additions
and
177 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
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,47 @@ | ||
// View engine (Handlebars) | ||
const handlebars = require('handlebars') | ||
const expressHandlebars = require('express-handlebars') | ||
const helpers = require('handlebars-helpers')() | ||
const { allowInsecurePrototypeAccess } = require('@handlebars/allow-prototype-access') | ||
const hbs = expressHandlebars.create({ | ||
handlebars: allowInsecurePrototypeAccess(handlebars), | ||
defaultLayout: 'main', | ||
partialsDir: ['views/partials/', 'views/partials/scriptPartials/'], | ||
helpers: { | ||
...helpers, | ||
...{ | ||
plural: function (number, text) { | ||
var singular = number === 1 | ||
// If no text parameter was given, just return a conditional s. | ||
if (typeof text !== 'string') return singular ? '' : 's' | ||
// Split with regex into group1/group2 or group1(group3) | ||
var match = text.match(/^([^()\/]+)(?:\/(.+))?(?:\((\w+)\))?/) | ||
// If no match, just append a conditional s. | ||
if (!match) return text + (singular ? '' : 's') | ||
// We have a good match, so fire away | ||
return ( | ||
// Singular case | ||
(singular && match[1]) || | ||
// Plural case: 'bagel/bagels' --> bagels | ||
match[2] || | ||
// Plural case: 'bagel(s)' or 'bagel' --> bagels | ||
match[1] + (match[3] || 's') | ||
) | ||
}, | ||
buildComment (comment, depth) { | ||
if (!depth) depth = 1 | ||
var tree = [] | ||
tree.push({ | ||
comment: comment, | ||
depth: depth | ||
}) | ||
comment.replies.forEach((r) => { | ||
depth = depth + 1 | ||
tree.comment.replies.depth = depth | ||
}) | ||
return tree | ||
} | ||
} | ||
} | ||
}) | ||
module.exports = hbs |
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 |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module.exports = { | ||
maximumCommentDepth: 5 | ||
}; | ||
maximumCommentDepth: 5 | ||
} |
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
Oops, something went wrong.