thelounge/client/views/index.js

28 lines
875 B
JavaScript
Raw Normal View History

"use strict";
// This creates a version of `require()` in the context of the current
// directory, so we iterate over its content, which is a map statically built by
// Webpack.
// Second argument says it's recursive, third makes sure we only load templates.
const requireViews = require.context(".", true, /\.tpl$/);
2016-12-18 15:53:28 +00:00
module.exports = requireViews.keys().reduce((acc, path) => {
// We are going to create nested properties on the accumulator object.
let tmp = acc;
2017-08-28 00:55:00 +00:00
// Split path by folders, and create a new property if necessary/
// First 2 characters are "./"/
// Last element in the array ends with `.tpl` and needs to be `require`d.
path.substr(2).split("/").forEach((key) => {
if (key.endsWith(".tpl")) { //
tmp[key.substr(0, key.length - 4)] = requireViews(path);
} else {
tmp[key] = tmp[key] || {};
}
tmp = tmp[key];
});
return acc;
}, {});