diff --git a/README.md b/README.md index 0bf6de5..4c3b18e 100644 --- a/README.md +++ b/README.md @@ -44,7 +44,6 @@ Inja is a headers only library, which can be downloaded from the [releases](http // Just for convenience using namespace inja; -using json = nlohmann::json; ``` If you are using the [Meson Build System](http://mesonbuild.com), then you can wrap this repository as a subproject. diff --git a/include/inja/inja.hpp b/include/inja/inja.hpp index 569edc2..f6d3d6e 100644 --- a/include/inja/inja.hpp +++ b/include/inja/inja.hpp @@ -28,7 +28,11 @@ SOFTWARE. #include namespace inja { +#ifndef INJA_DATA_TYPE using json = nlohmann::json; +#else + using json = INJA_DATA_TYPE; +#endif } #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(INJA_NOEXCEPTION) diff --git a/single_include/inja/inja.hpp b/single_include/inja/inja.hpp index 7cbdb97..b0f571b 100644 --- a/single_include/inja/inja.hpp +++ b/single_include/inja/inja.hpp @@ -28,7 +28,11 @@ SOFTWARE. #include namespace inja { +#ifndef INJA_DATA_TYPE using json = nlohmann::json; +#else + using json = INJA_DATA_TYPE; +#endif } #if (defined(__cpp_exceptions) || defined(__EXCEPTIONS) || defined(_CPPUNWIND)) && !defined(INJA_NOEXCEPTION) diff --git a/test/test-files.cpp b/test/test-files.cpp index d1f859c..2de97fc 100644 --- a/test/test-files.cpp +++ b/test/test-files.cpp @@ -2,7 +2,7 @@ TEST_CASE("loading") { inja::Environment env; - json data; + inja::json data; data["name"] = "Jeff"; SUBCASE("Files should be loaded") { CHECK(env.load_file(test_file_directory + "simple.txt") == "Hello {{ name }}."); } @@ -58,7 +58,7 @@ TEST_CASE("complete-files-whitespace-control") { TEST_CASE("global-path") { inja::Environment env {test_file_directory, "./"}; inja::Environment env_result {"./"}; - json data; + inja::json data; data["name"] = "Jeff"; SUBCASE("Files should be written") { @@ -79,7 +79,7 @@ TEST_CASE("include-without-local-files") { TEST_CASE("include-in-memory-and-file-template") { inja::Environment env {test_file_directory}; - json data; + inja::json data; data["name"] = "Jeff"; CHECK_THROWS_WITH(env.render_file("include-both.txt", data), "[inja.exception.file_error] failed accessing file at '../test/data/body'"); diff --git a/test/test-functions.cpp b/test/test-functions.cpp index 8640885..92eca89 100644 --- a/test/test-functions.cpp +++ b/test/test-functions.cpp @@ -3,7 +3,7 @@ TEST_CASE("functions") { inja::Environment env; - json data; + inja::json data; data["name"] = "Peter"; data["city"] = "New York"; data["names"] = {"Jeff", "Seb", "Peter", "Tom"}; @@ -199,7 +199,7 @@ TEST_CASE("functions") { TEST_CASE("assignments") { inja::Environment env; - json data; + inja::json data; data["age"] = 28; CHECK(env.render("{% set new_hour=23 %}{{ new_hour }}", data) == "23"); @@ -209,7 +209,7 @@ TEST_CASE("assignments") { TEST_CASE("callbacks") { inja::Environment env; - json data; + inja::json data; data["age"] = 28; env.add_callback("double", 1, [](inja::Arguments &args) { @@ -262,7 +262,7 @@ TEST_CASE("callbacks") { SUBCASE("Variadic") { env.add_callback("argmax", [](inja::Arguments& args) { - auto result = std::max_element(args.begin(), args.end(), [](const json* a, const json* b) { return *a < *b;}); + auto result = std::max_element(args.begin(), args.end(), [](const inja::json* a, const inja::json* b) { return *a < *b;}); return std::distance(args.begin(), result); }); @@ -273,7 +273,7 @@ TEST_CASE("callbacks") { TEST_CASE("combinations") { inja::Environment env; - json data; + inja::json data; data["name"] = "Peter"; data["city"] = "Brunswick"; data["age"] = 29; diff --git a/test/test-renderer.cpp b/test/test-renderer.cpp index e06b803..35f423d 100644 --- a/test/test-renderer.cpp +++ b/test/test-renderer.cpp @@ -2,7 +2,7 @@ TEST_CASE("types") { inja::Environment env; - json data; + inja::json data; data["name"] = "Peter"; data["city"] = "Brunswick"; data["age"] = 29; @@ -74,7 +74,7 @@ TEST_CASE("types") { } SUBCASE("nested loops") { - auto ldata = json::parse(R""""( + auto ldata = inja::json::parse(R""""( { "outer" : [ { "inner" : [ { "in2" : [ 1, 2 ] }, @@ -158,7 +158,7 @@ Yeah! } TEST_CASE("templates") { - json data; + inja::json data; data["name"] = "Peter"; data["city"] = "Brunswick"; data["is_happy"] = true; @@ -186,8 +186,8 @@ TEST_CASE("templates") { } SUBCASE("include-in-loop") { - json loop_data; - loop_data["cities"] = json::array({{{"name", "Munich"}}, {{"name", "New York"}}}); + inja::json loop_data; + loop_data["cities"] = inja::json::array({{{"name", "Munich"}}, {{"name", "New York"}}}); inja::Environment env; env.include_template("city.tpl", env.parse("{{ loop.index }}:{{ city.name }};")); @@ -246,7 +246,7 @@ TEST_CASE("templates") { } TEST_CASE("other syntax") { - json data; + inja::json data; data["name"] = "Peter"; data["city"] = "Brunswick"; data["age"] = 29; diff --git a/test/test-units.cpp b/test/test-units.cpp index 95862f2..2366dde 100644 --- a/test/test-units.cpp +++ b/test/test-units.cpp @@ -36,16 +36,16 @@ TEST_CASE("copy environment") { env.include_template("tpl", t1); std::string test_tpl = "{% include \"tpl\" %}"; - REQUIRE(env.render(test_tpl, json()) == "4"); + REQUIRE(env.render(test_tpl, inja::json()) == "4"); inja::Environment copy(env); - CHECK(copy.render(test_tpl, json()) == "4"); + CHECK(copy.render(test_tpl, inja::json()) == "4"); // overwrite template in source env inja::Template t2 = env.parse("{{ double(4) }}"); env.include_template("tpl", t2); - REQUIRE(env.render(test_tpl, json()) == "8"); + REQUIRE(env.render(test_tpl, inja::json()) == "8"); // template is unchanged in copy - CHECK(copy.render(test_tpl, json()) == "4"); + CHECK(copy.render(test_tpl, inja::json()) == "4"); } diff --git a/test/test.cpp b/test/test.cpp index 50161be..7645ade 100644 --- a/test/test.cpp +++ b/test/test.cpp @@ -5,8 +5,6 @@ #include "doctest/doctest.h" #include "inja/inja.hpp" -using json = nlohmann::json; - const std::string test_file_directory {"../test/data/"}; #include "test-files.cpp"