Crow  1.1
A C++ microframework for the web
crow::mustache Namespace Reference

In this namespace is defined most of the functions and classes related to template rendering. More...

Classes

class  invalid_template_exception
 Represents compilation error of an template. Throwed specially at mustache compile time. More...
 
struct  rendered_template
 Returned object after call the template_t::render() method. Its intended to be returned during a rule declaration. More...
 
struct  Action
 Used during mustache template compilation to represent parsing actions. More...
 
class  template_t
 Compiled mustache template object. More...
 

Typedefs

using context = json::wvalue
 

Enumerations

enum class  ActionType {
  Ignore , Tag , UnescapeTag , OpenBlock ,
  CloseBlock , ElseBlock , Partial
}
 Used in Action to represent different parsing behaviors. More...
 

Functions

template_t load (const std::string &filename)
 Open, read and renders a file using a mustache compiler. It also sanitize the input before compilation.
 
template_t compile (const std::string &body)
 The function that compiles a source into a mustache template.
 
std::string default_loader (const std::string &filename)
 The default way that load, load_unsafe, load_text and load_text_unsafe use to read the contents of a file.
 
void set_base (const std::string &path)
 Defines the templates directory path at route level. By default is templates/.
 
void set_global_base (const std::string &path)
 Defines the templates directory path at global level. By default is templates/.
 
void set_loader (std::function< std::string(std::string)> loader)
 Change the way that load, load_unsafe, load_text and load_text_unsafe reads a file. More...
 
std::string load_text (const std::string &filename)
 Open, read and sanitize a file but returns a std::string without a previous rendering process. More...
 
std::string load_text_unsafe (const std::string &filename)
 Open and read a file but returns a std::string without a previous rendering process. More...
 
template_t load_unsafe (const std::string &filename)
 Open, read and renders a file using a mustache compiler. But it do not sanitize the input before compilation. More...
 

Detailed Description

In this namespace is defined most of the functions and classes related to template rendering.

If you are here you might want to read these functions and classes:

As name suggest, crow uses mustache as main template rendering system.

You may be interested in taking a look at the Templating guide page.

Enumeration Type Documentation

◆ ActionType

Used in Action to represent different parsing behaviors.

See also
Action

Function Documentation

◆ load_text()

std::string crow::mustache::load_text ( const std::string &  filename)
inline

Open, read and sanitize a file but returns a std::string without a previous rendering process.

Except for the sanitize process this function does the almost the same thing that load_text_unsafe.

◆ load_text_unsafe()

std::string crow::mustache::load_text_unsafe ( const std::string &  filename)
inline

Open and read a file but returns a std::string without a previous rendering process.

This function is more like a helper to reduce code like this...

std::ifstream file("home.html");
return std::string({std::istreambuf_iterator<char>(file), std::istreambuf_iterator<char>()});

... Into this...

return load("home.html");
template_t load(const std::string &filename)
Open, read and renders a file using a mustache compiler. It also sanitize the input before compilatio...
Definition: mustache.h:812
Warning
Usually load_text is more recommended to use instead because it may prevent some XSS Attacks. Never blindly trust your users!

◆ load_unsafe()

template_t crow::mustache::load_unsafe ( const std::string &  filename)
inline

Open, read and renders a file using a mustache compiler. But it do not sanitize the input before compilation.

Warning
Usually load is more recommended to use instead because it may prevent some XSS Attacks. Never blindly trust your users!

◆ set_loader()

void crow::mustache::set_loader ( std::function< std::string(std::string)>  loader)
inline

Change the way that load, load_unsafe, load_text and load_text_unsafe reads a file.

By default, the previously mentioned functions load files using default_loader, that only reads a file and returns a std::string.