-
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.
handlebars partials and helpers support
- Loading branch information
1 parent
05ad6e1
commit 0f8ae2a
Showing
11 changed files
with
117 additions
and
2 deletions.
There are no files selected for viewing
Empty file.
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,3 @@ | ||
exports.default = function (text) { | ||
return text.toUpperCase() | ||
} |
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 @@ | ||
>{{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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
**{{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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
--- | ||
id: {{method.operationId}} | ||
title: {{method.summary}} | ||
--- | ||
|
||
## This will call a partial template to create the quote | ||
{{>quote text="Hello, World!"}} | ||
|
||
Part of this text will be {{>bold text="bold"}} | ||
|
||
{{loud "This text will uppercased using a helper"}} |
Empty file.
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,51 @@ | ||
"use strict"; | ||
|
||
import * as fs from "fs"; | ||
import * as path from "path"; | ||
import * as Handlebars from "handlebars"; | ||
|
||
const walkSync = (partialsPath: string, filelist: string[] = []): string[] => { | ||
fs.readdirSync(partialsPath).forEach((file) => { | ||
filelist = fs.statSync(path.join(partialsPath, file)).isDirectory() | ||
? walkSync(path.join(partialsPath, file), filelist) | ||
: filelist.concat(path.join(partialsPath, file)); | ||
}); | ||
return filelist; | ||
}; | ||
|
||
const loaders = { | ||
loadPartials: (partialsPath: string) => { | ||
if (fs.existsSync(partialsPath)) { | ||
const filelist = walkSync(partialsPath); | ||
if (filelist.length > 0) { | ||
Object.values(filelist).forEach((filename) => { | ||
const matches = /^([^.]+).hbs$/.exec(path.basename(filename)); | ||
if (!matches) { | ||
return; | ||
} | ||
const name = matches[1]; | ||
const template = fs.readFileSync(filename, "utf8"); | ||
Handlebars.registerPartial(name, template); | ||
}); | ||
} | ||
} | ||
}, | ||
loadHelpers: (helpersPath: string) => { | ||
if (fs.existsSync(helpersPath)) { | ||
const filelist = walkSync(helpersPath); | ||
if (filelist.length > 0) { | ||
Object.values(filelist).forEach((filename) => { | ||
const matches = /^([^.]+).js$/.exec(path.basename(filename)); | ||
if (!matches) { | ||
return; | ||
} | ||
const name = matches[1]; | ||
const helper = require(filename).default; | ||
Handlebars.registerHelper(name, helper); | ||
}); | ||
} | ||
} | ||
}, | ||
}; | ||
|
||
export default loaders; |
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