Skip to content

Commit

Permalink
Merge pull request #362 from CrowCpp/global_template_base
Browse files Browse the repository at this point in the history
added `set_global_base` method
  • Loading branch information
The-EDev authored Mar 19, 2022
2 parents a970167 + a0e6e37 commit bdbed55
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 2 deletions.
1 change: 1 addition & 0 deletions include/crow/app.h
Original file line number Diff line number Diff line change
Expand Up @@ -179,6 +179,7 @@ namespace crow
}

/// Set a response body size (in bytes) beyond which Crow automatically streams responses (Default is 1MiB)

///
/// Any streamed response is unaffected by Crow's timer, and therefore won't timeout before a response is fully sent.
self_t& stream_threshold(size_t threshold)
Expand Down
18 changes: 18 additions & 0 deletions include/crow/mustache.h
Original file line number Diff line number Diff line change
Expand Up @@ -631,6 +631,13 @@ namespace crow
static std::string template_base_directory = "templates";
return template_base_directory;
}

/// A base directory not related to any blueprint
inline std::string& get_global_template_base_directory_ref()
{
static std::string template_base_directory = "templates";
return template_base_directory;
}
} // namespace detail

inline std::string default_loader(const std::string& filename)
Expand Down Expand Up @@ -668,6 +675,17 @@ namespace crow
}
}

inline void set_global_base(const std::string& path)
{
auto& base = detail::get_global_template_base_directory_ref();
base = path;
if (base.back() != '\\' &&
base.back() != '/')
{
base += '/';
}
}

inline void set_loader(std::function<std::string(std::string)> loader)
{
detail::get_loader_ref() = std::move(loader);
Expand Down
4 changes: 2 additions & 2 deletions include/crow/routing.h
Original file line number Diff line number Diff line change
Expand Up @@ -595,8 +595,8 @@ namespace crow
{
if (!custom_templates_base.empty())
mustache::set_base(custom_templates_base);
else if (mustache::detail::get_template_base_directory_ref() != "templates")
mustache::set_base("templates");
else if (mustache::detail::get_template_base_directory_ref() != mustache::detail::get_global_template_base_directory_ref())
mustache::set_base(mustache::detail::get_global_template_base_directory_ref());

detail::routing_handler_call_helper::call<
detail::routing_handler_call_helper::call_params<decltype(handler_)>,
Expand Down

0 comments on commit bdbed55

Please sign in to comment.