-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
87 lines (63 loc) · 2.04 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
c++ template engine powered by google's v8 javascript engine
r8t = rat + v8 + WIP
(don't try to understand)
Requires
- http://www.boost.org 1.42+
- http://code.google.com/p/v8
r8t is headers only.
---
Demo
---
#include <iostream>
#include "include/r8t/tpl.hpp"
int main()
{
r8t::tpl t;
r8t::tpl::context_type ctx = t.new_context();
ctx.set("hello", "hello world")
.set("pi", 3.14);
std::string str = "{{hello}} " \
"{% for (i in [1,2,3]) :%}" \
" pi is {{pi}} " \
"{% end %} " ;
t.base_path("/templates/path");
try {
std::cout << t.render_string(str, ctx)
<< t.render("file.html", ctx)
<< std::endl;
}
catch (...) {
;
}
return 0;
}
---
Design
---
r8t::tpl is a typedef to r8t::basic_tpl wich is parameterized with policies
for the parser, context, engine, loader and cache types.
More types later. Right now, only standard policies are under implementation:
- parser : utf8 aware Django/js like grammar.
- context: support a few std types and containers.
custom types supported through template specializations.
- engine : simple runtime around google v8
- loader : filesystem
- cache : simple assoc in memory container. stores compiled templates (v8 byte code)
---
Tests
---
SConstruct is coming. For now:
$ g++ -o test \
-I/path/to/boost/include \
-I/path/to/v8/include \
-L/path/to/boost/lib \
-L/path/to/v8/lib \
-lv8 -lpthread -lboost_filesystem -lboost_system \
-DBOOST_TEST_STATIC_LINK \
-lboost_test_exec_monitor \
-Werror \
test.cpp
$ ./test --log_level=test_suite --build_info=yes --report_level=detailed
Note: You can remove -DBOOST_TEST_STATIC_LINK and -lboost_test_exec_monitor
from the command above if you want boost_test_exec_monitor to be built
in place rather than statically linking to libboost_test_exec_monitor