-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtemplate.cpp
More file actions
90 lines (74 loc) · 1.86 KB
/
template.cpp
File metadata and controls
90 lines (74 loc) · 1.86 KB
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
88
89
90
#include <string.h>
#include <iostream>
#include <sstream>
#include <algorithm>
#include "include/nlohmann/json.hpp"
using json = nlohmann::json;
using namespace nlohmann::literals;
void manifest();
void transform(std::string from, std::string to);
void transformTemplate(std::string to);
int main(int argc, char *argv[])
{
if (argc == 1)
{
std::cerr << "No arguments found" << std::endl;
return 1;
}
std::string action = argv[1];
if (!action.compare("manifest"))
manifest();
else if (!action.compare("transform"))
transform(argv[2], argv[3]);
else
std::cerr << "Invalid action: " << action << std::endl;
return 0;
}
void manifest()
{
json output = R"(
{
"name": "template",
"version": "0.1",
"description": "This is a template package.",
"transforms": [
{
"from": "template",
"to": ["html"],
"arguments": []
}
]
}
)"_json;
std::cout << output.dump() << std::endl;
}
void transform(std::string from, std::string to)
{
if (!from.compare("template"))
transformTemplate(to);
else
std::cerr << "Package does not support: " << from << std::endl;
}
void transformTemplate(std::string to)
{
std::string in = "", buffer;
while (std::getline(std::cin, buffer))
in.append(buffer);
json input = json::parse(in);
std::string content = input["data"];
json output = json::array();
if (!to.compare("html"))
{
std::ostringstream oss;
oss << content;
output.push_back(json::parse(R"( {"name": "raw", "data": "<a>"} )"));
output.push_back(json::parse(R"( {"name": "raw", "data": ""} )"));
output.push_back(json::parse(R"( {"name": "raw", "data": "</a>"} )"));
output[1]["data"] = oss.str();
std::cout << output.dump() << std::endl;
}
else
{
std::cerr << "Cannot convert template to: " << to << std::endl;
}
}