aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorToni Uhlig <matzeton@googlemail.com>2021-10-23 02:24:24 +0200
committerToni Uhlig <matzeton@googlemail.com>2021-10-23 02:24:24 +0200
commit47f09ad8fb52de7ee9ed6c63574ea2f77e314fa2 (patch)
tree4259d1e1578d4ad7df3e05c0876723928bb9532f
parentca7ca2218e07a24075cdc9d48e967cfdc2a3543b (diff)
Sort filenames alpha-numeric, used as template system dependency management.
Signed-off-by: Toni Uhlig <matzeton@googlemail.com>
-rw-r--r--src/Filesystem.cpp15
-rw-r--r--src/Filesystem.hpp1
-rw-r--r--src/TemplateManager.cpp12
3 files changed, 24 insertions, 4 deletions
diff --git a/src/Filesystem.cpp b/src/Filesystem.cpp
index 9fe13bb..f3824e3 100644
--- a/src/Filesystem.cpp
+++ b/src/Filesystem.cpp
@@ -135,6 +135,21 @@ FilesDict & Filesystem::GetFiles()
return m_Files;
}
+void Filesystem::GetFilenamesSorted(std::vector<std::string> & sortedFilenames)
+{
+ for (auto const & f : GetFiles())
+ {
+ sortedFilenames.push_back(f.first);
+ }
+ std::sort(sortedFilenames.begin(), sortedFilenames.end());
+#if 1
+ for (auto const & f : sortedFilenames)
+ {
+ std::cout << "Added file (alnum sorted): " << f << std::endl;
+ }
+#endif
+}
+
void Filesystem::MagicInit()
{
m_Magic = magic_open(MAGIC_MIME_TYPE);
diff --git a/src/Filesystem.hpp b/src/Filesystem.hpp
index 98fbdcd..a87c0a3 100644
--- a/src/Filesystem.hpp
+++ b/src/Filesystem.hpp
@@ -32,6 +32,7 @@ public:
bool Scan(std::string root = "./wwwroot");
bool Scan(std::string root, std::vector<std::string> extensions, bool exclude_extensions = false);
FilesDict & GetFiles();
+ void GetFilenamesSorted(std::vector<std::string> & sortedFilenames);
private:
bool AddSingleFile(std::string path, std::string root);
diff --git a/src/TemplateManager.cpp b/src/TemplateManager.cpp
index 62b4e27..2c58306 100644
--- a/src/TemplateManager.cpp
+++ b/src/TemplateManager.cpp
@@ -38,11 +38,15 @@ TemplateManager::TemplateManager()
void TemplateManager::ParseTemplates(Filesystem & fs)
{
- for (auto & tpl : fs.GetFiles())
+ std::vector<std::string> sortedFilenames;
+ auto & files = fs.GetFiles();
+
+ fs.GetFilenamesSorted(sortedFilenames);
+ for (auto const & tpl : sortedFilenames)
{
- std::string tmpl(tpl.second.data.data(), tpl.second.data.data() + tpl.second.data.size());
- m_Inja.include_template(tpl.first, m_Inja.parse(tmpl));
- std::cout << "File: " << tpl.first << " may contain a renderable template." << std::endl;
+ std::string tmpl(files[tpl].data.data(), files[tpl].data.data() + files[tpl].data.size());
+ m_Inja.include_template(tpl, m_Inja.parse(tmpl));
+ std::cout << "File: " << tpl << " may contain a renderable template." << std::endl;
}
}