aboutsummaryrefslogtreecommitdiffstats
path: root/include
diff options
context:
space:
mode:
authoripknHama <ipknhama@gmail.com>2014-08-07 05:55:31 +0900
committeripknHama <ipknhama@gmail.com>2014-08-07 05:55:31 +0900
commitbd1481656adcd8d79bc0d23672df1599ca8e9e50 (patch)
tree1d86baf4792dce6f3c604a97ed0a9bdfd1a451cb /include
parent1b83b78c8344b40355d9238d2fbeaf9a9b348ef9 (diff)
downloadcrow-bd1481656adcd8d79bc0d23672df1599ca8e9e50.tar.gz
crow-bd1481656adcd8d79bc0d23672df1599ca8e9e50.zip
improve mustache.h
Diffstat (limited to 'include')
-rw-r--r--include/logging.h1
-rw-r--r--include/mustache.h37
2 files changed, 23 insertions, 15 deletions
diff --git a/include/logging.h b/include/logging.h
index b43a969..2984cce 100644
--- a/include/logging.h
+++ b/include/logging.h
@@ -1,7 +1,6 @@
#pragma once
#include <string>
-#include <chrono>
#include <cstdio>
#include <cstdlib>
#include <ctime>
diff --git a/include/mustache.h b/include/mustache.h
index 7218ae8..fb4d664 100644
--- a/include/mustache.h
+++ b/include/mustache.h
@@ -505,18 +505,22 @@ namespace crow
std::string body_;
};
- template_t compile(const std::string& body)
+ inline template_t compile(const std::string& body)
{
return template_t(body);
}
namespace detail
{
- std::string template_base_directory = "templates";
+ inline std::string& get_template_base_directory_ref()
+ {
+ static std::string template_base_directory = "templates";
+ return template_base_directory;
+ }
}
- std::string default_loader(const std::string& filename)
+ inline std::string default_loader(const std::string& filename)
{
- std::ifstream inf(detail::template_base_directory + filename);
+ std::ifstream inf(detail::get_template_base_directory_ref() + filename);
if (!inf)
return {};
return {std::istreambuf_iterator<char>(inf), std::istreambuf_iterator<char>()};
@@ -524,27 +528,32 @@ namespace crow
namespace detail
{
- std::function<std::string (std::string)> loader = default_loader;
+ inline std::function<std::string (std::string)> get_loader_ref()
+ {
+ static std::function<std::string (std::string)> loader = default_loader;
+ return loader;
+ }
}
- void set_base(const std::string& path)
+ inline void set_base(const std::string& path)
{
- detail::template_base_directory = path;
- if (detail::template_base_directory.back() != '\\' &&
- detail::template_base_directory.back() != '/')
+ auto& base = detail::get_template_base_directory_ref();
+ base = path;
+ if (base.back() != '\\' &&
+ base.back() != '/')
{
- detail::template_base_directory += '/';
+ base += '/';
}
}
- void set_loader(std::function<std::string(std::string)> loader)
+ inline void set_loader(std::function<std::string(std::string)> loader)
{
- detail::loader = std::move(loader);
+ detail::get_loader_ref() = std::move(loader);
}
- template_t load(const std::string& filename)
+ inline template_t load(const std::string& filename)
{
- return compile(detail::loader(filename));
+ return compile(detail::get_loader_ref()(filename));
}
}
}