Skip to content

Commit 652e378

Browse files
committed
Merge branch 'master' of https://github.com/pantor/inja
2 parents aad2cc4 + c36cbac commit 652e378

File tree

6 files changed

+639
-224
lines changed

6 files changed

+639
-224
lines changed

Diff for: CMakeLists.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@ set(INJA_INSTALL_INCLUDE_DIR "include")
1616
set(CMAKE_MODULE_PATH ${CMAKE_MODULE_PATH} ${PROJECT_SOURCE_DIR}/cmake)
1717

1818
if(CMAKE_COMPILER_IS_GNUCC)
19-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall")
19+
add_compile_options(-Wall)
2020
endif()
2121

2222
if(MSVC)
23-
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} /W4")
23+
add_compile_options(/W4 /permissive- /utf-8 /Zc:__cplusplus)
2424
endif()
2525

2626

Diff for: appveyor.yml

+4-4
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,14 @@ platform:
88
- x64
99

1010
configuration:
11-
# - Debug
11+
- Debug
1212
- Release
1313

1414
environment:
1515
matrix:
1616
# Visual Studio 2015
17-
# - TOOLCHAIN: v140
18-
# STD: 14
17+
- TOOLCHAIN: v140
18+
STD: 14
1919
# Visual Studio 2017
2020
- TOOLCHAIN: v141
2121
STD: 14
@@ -34,7 +34,7 @@ init:
3434
before_build:
3535
- mkdir -p build
3636
- cd build
37-
- cmake .. -A %PLATFORM% -T %TOOLCHAIN% -DCMAKE_CXX_STANDARD=%STD% -DCMAKE_CXX_FLAGS="/permissive- /utf-8 /Zc:__cplusplus"
37+
- cmake .. -A %PLATFORM% -T %TOOLCHAIN% -DCMAKE_CXX_STANDARD=%STD%
3838

3939
build_script:
4040
- cmake --build . --config %CONFIGURATION% -- -verbosity:n

Diff for: include/inja/environment.hpp

+37-47
Original file line numberDiff line numberDiff line change
@@ -28,84 +28,64 @@ using json = nlohmann::json;
2828
* \brief Class for changing the configuration.
2929
*/
3030
class Environment {
31-
class Impl {
32-
public:
33-
std::string input_path;
34-
std::string output_path;
35-
36-
LexerConfig lexer_config;
37-
ParserConfig parser_config;
38-
39-
FunctionStorage callbacks;
40-
TemplateStorage included_templates;
41-
};
42-
43-
std::unique_ptr<Impl> m_impl;
44-
4531
public:
4632
Environment(): Environment("") { }
4733

48-
explicit Environment(const std::string& global_path): m_impl(stdinja::make_unique<Impl>()) {
49-
m_impl->input_path = global_path;
50-
m_impl->output_path = global_path;
51-
}
34+
explicit Environment(const std::string& global_path): m_input_path(global_path), m_output_path(global_path) {}
5235

53-
explicit Environment(const std::string& input_path, const std::string& output_path): m_impl(stdinja::make_unique<Impl>()) {
54-
m_impl->input_path = input_path;
55-
m_impl->output_path = output_path;
56-
}
36+
Environment(const std::string& input_path, const std::string& output_path): m_input_path(input_path), m_output_path(output_path) {}
5737

5838
/// Sets the opener and closer for template statements
5939
void set_statement(const std::string& open, const std::string& close) {
60-
m_impl->lexer_config.statement_open = open;
61-
m_impl->lexer_config.statement_close = close;
62-
m_impl->lexer_config.update_open_chars();
40+
m_lexer_config.statement_open = open;
41+
m_lexer_config.statement_close = close;
42+
m_lexer_config.update_open_chars();
6343
}
6444

6545
/// Sets the opener for template line statements
6646
void set_line_statement(const std::string& open) {
67-
m_impl->lexer_config.line_statement = open;
68-
m_impl->lexer_config.update_open_chars();
47+
m_lexer_config.line_statement = open;
48+
m_lexer_config.update_open_chars();
6949
}
7050

7151
/// Sets the opener and closer for template expressions
7252
void set_expression(const std::string& open, const std::string& close) {
73-
m_impl->lexer_config.expression_open = open;
74-
m_impl->lexer_config.expression_close = close;
75-
m_impl->lexer_config.update_open_chars();
53+
m_lexer_config.expression_open = open;
54+
m_lexer_config.expression_close = close;
55+
m_lexer_config.update_open_chars();
7656
}
7757

7858
/// Sets the opener and closer for template comments
7959
void set_comment(const std::string& open, const std::string& close) {
80-
m_impl->lexer_config.comment_open = open;
81-
m_impl->lexer_config.comment_close = close;
82-
m_impl->lexer_config.update_open_chars();
60+
m_lexer_config.comment_open = open;
61+
m_lexer_config.comment_close = close;
62+
m_lexer_config.update_open_chars();
8363
}
8464

8565
/// Sets whether to remove the first newline after a block
8666
void set_trim_blocks(bool trim_blocks) {
87-
m_impl->lexer_config.trim_blocks = trim_blocks;
67+
m_lexer_config.trim_blocks = trim_blocks;
8868
}
8969

9070
/// Sets whether to strip the spaces and tabs from the start of a line to a block
9171
void set_lstrip_blocks(bool lstrip_blocks) {
92-
m_impl->lexer_config.lstrip_blocks = lstrip_blocks;
72+
m_lexer_config.lstrip_blocks = lstrip_blocks;
9373
}
9474

9575
/// Sets the element notation syntax
9676
void set_element_notation(ElementNotation notation) {
97-
m_impl->parser_config.notation = notation;
77+
m_parser_config.notation = notation;
9878
}
9979

10080

10181
Template parse(nonstd::string_view input) {
102-
Parser parser(m_impl->parser_config, m_impl->lexer_config, m_impl->included_templates);
82+
Parser parser(m_parser_config, m_lexer_config, m_included_templates);
10383
return parser.parse(input);
10484
}
10585

10686
Template parse_template(const std::string& filename) {
107-
Parser parser(m_impl->parser_config, m_impl->lexer_config, m_impl->included_templates);
108-
return parser.parse_template(m_impl->input_path + static_cast<std::string>(filename));
87+
Parser parser(m_parser_config, m_lexer_config, m_included_templates);
88+
return parser.parse_template(m_input_path + static_cast<std::string>(filename));
10989
}
11090

11191
std::string render(nonstd::string_view input, const json& data) {
@@ -128,13 +108,13 @@ class Environment {
128108
}
129109

130110
void write(const std::string& filename, const json& data, const std::string& filename_out) {
131-
std::ofstream file(m_impl->output_path + filename_out);
111+
std::ofstream file(m_output_path + filename_out);
132112
file << render_file(filename, data);
133113
file.close();
134114
}
135115

136116
void write(const Template& temp, const json& data, const std::string& filename_out) {
137-
std::ofstream file(m_impl->output_path + filename_out);
117+
std::ofstream file(m_output_path + filename_out);
138118
file << render(temp, data);
139119
file.close();
140120
}
@@ -150,33 +130,43 @@ class Environment {
150130
}
151131

152132
std::ostream& render_to(std::ostream& os, const Template& tmpl, const json& data) {
153-
Renderer(m_impl->included_templates, m_impl->callbacks).render_to(os, tmpl, data);
133+
Renderer(m_included_templates, m_callbacks).render_to(os, tmpl, data);
154134
return os;
155135
}
156136

157137
std::string load_file(const std::string& filename) {
158-
Parser parser(m_impl->parser_config, m_impl->lexer_config, m_impl->included_templates);
159-
return parser.load_file(m_impl->input_path + filename);
138+
Parser parser(m_parser_config, m_lexer_config, m_included_templates);
139+
return parser.load_file(m_input_path + filename);
160140
}
161141

162142
json load_json(const std::string& filename) {
163-
std::ifstream file = open_file_or_throw(m_impl->input_path + filename);
143+
std::ifstream file = open_file_or_throw(m_input_path + filename);
164144
json j;
165145
file >> j;
166146
return j;
167147
}
168148

169149
void add_callback(const std::string& name, unsigned int numArgs, const CallbackFunction& callback) {
170-
m_impl->callbacks.add_callback(name, numArgs, callback);
150+
m_callbacks.add_callback(name, numArgs, callback);
171151
}
172152

173153
/** Includes a template with a given name into the environment.
174154
* Then, a template can be rendered in another template using the
175155
* include "<name>" syntax.
176156
*/
177157
void include_template(const std::string& name, const Template& tmpl) {
178-
m_impl->included_templates[name] = tmpl;
158+
m_included_templates[name] = tmpl;
179159
}
160+
161+
private:
162+
std::string m_input_path;
163+
std::string m_output_path;
164+
165+
LexerConfig m_lexer_config;
166+
ParserConfig m_parser_config;
167+
168+
FunctionStorage m_callbacks;
169+
TemplateStorage m_included_templates;
180170
};
181171

182172
/*!

0 commit comments

Comments
 (0)