stencet  v0.1.16
Build C++ web server modules that allow easy routing and deployment.
template.h
1 /* Copyright (C) 2012-2013 Justin Berger
2  The full license is available in the LICENSE file at the root of this project and is also available at http://opensource.org/licenses/MIT. */
3 
4 #pragma once
5 
6 #include <stencet/region.h>
7 #include <vector>
8 #include <iostream>
9 #include <mxcomp/reflection.h>
10 #include "parser.h"
11 
12 namespace stencet {
13 
14  struct Template {
15  std::vector<Region*> regions;
16 
17  void render(std::ostream& out, ViewContext& vc) const;
18  void render(std::ostream& out, ViewModel& vm) const;
19 
20  template <typename T>
21  auto render(std::ostream& out, const T& t) const
22  -> decltype(MetaClass_<T>::fields(), void());
23 
24  template <typename T>
25  auto With(T& t) const
26  -> std::function< void (std::ostream&)>
27  {
28  return [&](std::ostream& out) {
29  this->render(out, t);
30  };
31  }
32 
33  ~Template();
34 
35  ParseStatus::t Parse(std::istream& stream);
36  ParseStatus::t Parse(const std::string&);
37  ParseStatus::t Parse(std::istream& stream, std::string&);
38  static void AddDirectory(const std::string&);
39  static std::map<std::string, Template>& Templates();
40  static Template& ByName(const std::string& name);
41 
42  };
43 
44 
45 
46  bool RegisterBuiltins();
47  // void split(const std::string&, std::vector<std::string>&);
48 }
49 
50 #include "template.tcc"