-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
951 additions
and
97 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
#include "Template.hpp" | ||
#include "JSON.hpp" | ||
|
||
#include <iostream> | ||
|
||
using Qentem::JSON; | ||
using Qentem::StringStream; | ||
using Qentem::Template; | ||
using Qentem::Value; | ||
|
||
int main() { | ||
Value<char> value; | ||
|
||
value["phrase"] = "Welcome {0} to {1}. You have {2} points. " | ||
"Your points will become {3} next month. " | ||
"Your points will be here when you login to {1} every {4}."; | ||
|
||
value["username"] = "X"; | ||
value["site_name"] = "Y"; | ||
value["points"] = 10U; | ||
value["points_html"] = R"(<span id="pid">10U</span>)"; | ||
value["time"] = "week"; | ||
|
||
const char *content = | ||
"{svar:phrase, {var:username}, {var:site_name}, {raw:points_html}, {math: {var:points} * 2}, {var:time}}"; | ||
|
||
StringStream<char> stream; | ||
|
||
Template::Render(content, value, stream); | ||
std::cout << stream << '\n'; | ||
/* | ||
Output: Welcome X to Y. You have <span id="pid">10U</span> points. Your points will become 20 next month. Your | ||
points will be here when you login to Y every week. | ||
*/ | ||
|
||
////////////////////////////////////// | ||
value.Reset(); | ||
stream.Clear(); | ||
|
||
const char *json_data = R"( | ||
{ | ||
"phrase": "user {0} logged in {1}.\n", | ||
"list": [ | ||
{ | ||
"name": "X", | ||
"last_seen": "today" | ||
}, | ||
{ | ||
"name": "Y", | ||
"last_seen": "yesterday" | ||
}, | ||
{ | ||
"name": "Z", | ||
"last_seen": "last week" | ||
} | ||
] | ||
} | ||
)"; | ||
|
||
value = JSON::Parse(json_data); | ||
|
||
content = R"(<loop set="list" value="val">{svar:phrase, {var:val[name]}, {var:val[last_seen]}}</loop>)"; | ||
|
||
Template::Render(content, value, stream); | ||
std::cout << '\n' << stream << '\n'; | ||
|
||
/* | ||
Output: | ||
user User1 logged in today. | ||
user User2 logged in yesterday. | ||
user User3 logged in last week. | ||
*/ | ||
} |
Oops, something went wrong.