diff --git a/.clang-format b/.clang-format index 1bc36dc..5486ac5 100644 --- a/.clang-format +++ b/.clang-format @@ -1,5 +1,5 @@ --- -Language: Cpp +Language: Cpp BasedOnStyle: LLVM ColumnLimit: 120 diff --git a/README.md b/README.md index 9e2dffa..af79a45 100644 --- a/README.md +++ b/README.md @@ -29,7 +29,7 @@ Inja is a template engine for modern C++, loosely inspired by [jinja](http://jinja.pocoo.org) for python. It has an easy and yet powerful template syntax with all variables, loops, conditions, includes, callbacks, comments you need, nested and combined as you like. Inja uses the wonderful [json](https://github.com/nlohmann/json) library by nlohmann for data input and handling. Most importantly, *inja* needs only two header files, which is (nearly) as trivial as integration in C++ can get. Of course, everything is tested on all relevant compilers. Here is what it looks like: -```c++ +```.cpp json data; data["name"] = "world"; @@ -40,7 +40,7 @@ inja::render("Hello {{ name }}!", data); // Returns "Hello world!" Inja is a headers only library, which can be downloaded from the [releases](https://github.com/pantor/inja/releases) or directly from the `include/` or `single_include/` folder. Inja uses `nlohmann/json.hpp` as its single dependency, so make sure it can be included from `inja.hpp`. json can be downloaded [here](https://github.com/nlohmann/json/releases). Then integration is as easy as: -```c++ +```.cpp #include // Just for convenience @@ -67,7 +67,7 @@ This tutorial will give you an idea how to use inja. It will explain the most im The basic template rendering takes a template as a `std::string` and a `json` object for all data. It returns the rendered template as an `std::string`. -```c++ +```.cpp json data; data["name"] = "world"; @@ -76,7 +76,7 @@ render_to(std::cout, "Hello {{ name }}!", data); // Prints "Hello world!" ``` For more advanced usage, an environment is recommended. -```c++ +```.cpp Environment env; // Render a string with json data @@ -99,7 +99,7 @@ env.write_with_json_file("./templates/greeting.txt", "./data.json", "./result.tx ``` The environment class can be configured to your needs. -```c++ +```.cpp // With default settings Environment env_default; @@ -123,7 +123,7 @@ env.set_line_statement("##"); // Line statements ## (just an opener) ### Variables Variables are rendered within the `{{ ... }}` expressions. -```c++ +```.cpp json data; data["neighbour"] = "Peter"; data["guests"] = {"Jeff", "Tom", "Patrick"}; @@ -145,7 +145,7 @@ Statements can be written either with the `{% ... %}` syntax or the `##` syntax #### Loops -```c++ +```.cpp // Combining loops and line statements render(R"(Guest List: ## for guest in guests @@ -162,7 +162,7 @@ In a loop, the special variables `loop/index (number)`, `loop/index1 (number)`, #### Conditions Conditions support the typical if, else if and else statements. Following conditions are for example possible: -```c++ +```.cpp // Standard comparisons with variable render("{% if time.hour >= 20 %}…{% else if time.hour >= 18 %}…{% endif %}", data); // True @@ -179,7 +179,7 @@ render("{% if not guest_count %}…{% endif %}", data); // True #### Includes You can either include other template files or already parsed templates. -```c++ +```.cpp // Other template files are included relative from the current file location render("{% include \"footer.html\" %}", data); @@ -192,7 +192,7 @@ env.render("Content: {% include \"content\" %}", data); // "Content: Hello Peter ### Functions A few functions are implemented within the inja template syntax. They can be called with -```c++ +```.cpp // Upper and lower function, for string cases render("Hello {{ upper(neighbour) }}!", data); // "Hello PETER!" render("Hello {{ lower(neighbour) }}!", data); // "Hello peter!" @@ -249,7 +249,7 @@ render("{{ isArray(guests) }}", data); // "true" In the default configuration, no whitespace is removed while rendering the file. To support a more readable template style, you can configure the environment to control whitespaces before and after a statement automatically. While enabling `set_trim_blocks` removes the first newline after a statement, `set_lstrip_blocks` strips tabs and spaces from the beginning of a line to the start of a block. -```c++ +```.cpp Environment env; env.set_trim_blocks(true); env.set_lstrip_blocks(true); @@ -260,7 +260,7 @@ With both `trim_blocks` and `lstrip_blocks` enabled, you can put statements on t ### Callbacks You can create your own and more complex functions with callbacks. -```c++ +```.cpp Environment env; /* @@ -288,7 +288,7 @@ env.render("{{ double-greetings }}", data); // "Hello Hello!" ### Comments Comments can be written with the `{# ... #}` syntax. -```c++ +```.cpp render("Hello{# Todo #}!", data); // "Hello!" ``` diff --git a/include/inja/token.hpp b/include/inja/token.hpp index 50300c5..2de08e6 100644 --- a/include/inja/token.hpp +++ b/include/inja/token.hpp @@ -10,7 +10,7 @@ namespace inja { /*! - * \brief Helper-class for the inja Parser. + * \brief Helper-class for the inja Lexer. */ struct Token { enum class Kind { diff --git a/amalgamate/config.json b/scripts/amalgamate_config.json similarity index 100% rename from amalgamate/config.json rename to scripts/amalgamate_config.json diff --git a/scripts/update_single_include.sh b/scripts/update_single_include.sh index b7e1141..12d3ad3 100755 --- a/scripts/update_single_include.sh +++ b/scripts/update_single_include.sh @@ -6,4 +6,4 @@ SOURCE_ROOT=$(dirname "${DIR}") echo "Move to Source Root: ${SOURCE_ROOT}" cd ${SOURCE_ROOT} -python3 amalgamate/amalgamate.py -c amalgamate/config.json -s include -v yes +python3 third_party/amalgamate/amalgamate.py -c scripts/amalgamate_config.json -s include -v yes diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index 9b27e9b..6e1b633 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -1822,7 +1822,7 @@ struct JsonError : public InjaError { namespace inja { /*! - * \brief Helper-class for the inja Parser. + * \brief Helper-class for the inja Lexer. */ struct Token { enum class Kind { diff --git a/amalgamate/LICENSE.md b/third_party/amalgamate/LICENSE.md similarity index 100% rename from amalgamate/LICENSE.md rename to third_party/amalgamate/LICENSE.md diff --git a/amalgamate/amalgamate.py b/third_party/amalgamate/amalgamate.py similarity index 100% rename from amalgamate/amalgamate.py rename to third_party/amalgamate/amalgamate.py diff --git a/test/doctest/LICENSE.txt b/third_party/include/doctest/LICENSE.txt similarity index 100% rename from test/doctest/LICENSE.txt rename to third_party/include/doctest/LICENSE.txt diff --git a/test/doctest/doctest.h b/third_party/include/doctest/doctest.h similarity index 100% rename from test/doctest/doctest.h rename to third_party/include/doctest/doctest.h diff --git a/test/hayai/LICENSE.md b/third_party/include/hayai/LICENSE.md similarity index 100% rename from test/hayai/LICENSE.md rename to third_party/include/hayai/LICENSE.md diff --git a/test/hayai/hayai.hpp b/third_party/include/hayai/hayai.hpp similarity index 100% rename from test/hayai/hayai.hpp rename to third_party/include/hayai/hayai.hpp diff --git a/test/hayai/hayai_benchmarker.hpp b/third_party/include/hayai/hayai_benchmarker.hpp similarity index 100% rename from test/hayai/hayai_benchmarker.hpp rename to third_party/include/hayai/hayai_benchmarker.hpp diff --git a/test/hayai/hayai_clock.hpp b/third_party/include/hayai/hayai_clock.hpp similarity index 100% rename from test/hayai/hayai_clock.hpp rename to third_party/include/hayai/hayai_clock.hpp diff --git a/test/hayai/hayai_compatibility.hpp b/third_party/include/hayai/hayai_compatibility.hpp similarity index 100% rename from test/hayai/hayai_compatibility.hpp rename to third_party/include/hayai/hayai_compatibility.hpp diff --git a/test/hayai/hayai_console.hpp b/third_party/include/hayai/hayai_console.hpp similarity index 100% rename from test/hayai/hayai_console.hpp rename to third_party/include/hayai/hayai_console.hpp diff --git a/test/hayai/hayai_console_outputter.hpp b/third_party/include/hayai/hayai_console_outputter.hpp similarity index 100% rename from test/hayai/hayai_console_outputter.hpp rename to third_party/include/hayai/hayai_console_outputter.hpp diff --git a/test/hayai/hayai_default_test_factory.hpp b/third_party/include/hayai/hayai_default_test_factory.hpp similarity index 100% rename from test/hayai/hayai_default_test_factory.hpp rename to third_party/include/hayai/hayai_default_test_factory.hpp diff --git a/test/hayai/hayai_fixture.hpp b/third_party/include/hayai/hayai_fixture.hpp similarity index 100% rename from test/hayai/hayai_fixture.hpp rename to third_party/include/hayai/hayai_fixture.hpp diff --git a/test/hayai/hayai_json_outputter.hpp b/third_party/include/hayai/hayai_json_outputter.hpp similarity index 100% rename from test/hayai/hayai_json_outputter.hpp rename to third_party/include/hayai/hayai_json_outputter.hpp diff --git a/test/hayai/hayai_junit_xml_outputter.hpp b/third_party/include/hayai/hayai_junit_xml_outputter.hpp similarity index 100% rename from test/hayai/hayai_junit_xml_outputter.hpp rename to third_party/include/hayai/hayai_junit_xml_outputter.hpp diff --git a/test/hayai/hayai_main.hpp b/third_party/include/hayai/hayai_main.hpp similarity index 100% rename from test/hayai/hayai_main.hpp rename to third_party/include/hayai/hayai_main.hpp diff --git a/test/hayai/hayai_outputter.hpp b/third_party/include/hayai/hayai_outputter.hpp similarity index 100% rename from test/hayai/hayai_outputter.hpp rename to third_party/include/hayai/hayai_outputter.hpp diff --git a/test/hayai/hayai_test.hpp b/third_party/include/hayai/hayai_test.hpp similarity index 100% rename from test/hayai/hayai_test.hpp rename to third_party/include/hayai/hayai_test.hpp diff --git a/test/hayai/hayai_test_descriptor.hpp b/third_party/include/hayai/hayai_test_descriptor.hpp similarity index 100% rename from test/hayai/hayai_test_descriptor.hpp rename to third_party/include/hayai/hayai_test_descriptor.hpp diff --git a/test/hayai/hayai_test_factory.hpp b/third_party/include/hayai/hayai_test_factory.hpp similarity index 100% rename from test/hayai/hayai_test_factory.hpp rename to third_party/include/hayai/hayai_test_factory.hpp diff --git a/test/hayai/hayai_test_result.hpp b/third_party/include/hayai/hayai_test_result.hpp similarity index 100% rename from test/hayai/hayai_test_result.hpp rename to third_party/include/hayai/hayai_test_result.hpp