From 466a378a082dde6fd43791a57de46c7c902e293a Mon Sep 17 00:00:00 2001 From: pantor Date: Mon, 14 Aug 2017 09:35:37 +0200 Subject: [PATCH] restructure third-parties, add licenses, add more gcc-compiler tests --- .travis.yml | 81 ++++++++++++++------------ README.md | 31 +++++++++- src/inja.hpp | 20 ++++++- test/src/test.cpp | 5 +- test/thirdparty/catch/LICENSE.txt | 23 ++++++++ test/thirdparty/{ => catch}/catch.hpp | 0 test/thirdparty/json/LICENSE.MIT | 21 +++++++ {src => test/thirdparty}/json/json.hpp | 0 8 files changed, 139 insertions(+), 42 deletions(-) create mode 100644 test/thirdparty/catch/LICENSE.txt rename test/thirdparty/{ => catch}/catch.hpp (100%) create mode 100644 test/thirdparty/json/LICENSE.MIT rename {src => test/thirdparty}/json/json.hpp (100%) diff --git a/.travis.yml b/.travis.yml index 2486a04..165e946 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,57 +7,64 @@ language: cpp dist: trusty sudo: required -#addons: -# apt: -# sources: -# # add PPAs with more up-to-date toolchains -# - ubuntu-toolchain-r-test -# - llvm-toolchain-precise-3.6 -# packages: -# # install toolchains -# - gcc-5 -# - g++-5 -# - clang-3.6 - matrix: include: + ### Coveralls ### - compiler: gcc addons: apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-4.9 - env: COMPILER=g++-4.9 - - compiler: gcc - addons: - apt: - sources: - - ubuntu-toolchain-r-test - packages: - - g++-5 + sources: ['ubuntu-toolchain-r-test'] + packages: g++-5 env: COMPILER=g++-5 + before_install: + - pip install --user cpp-coveralls + after_success: + - make clean + # - coveralls --exclude lib --exclude tests --gcov-options '\-lp' + + - compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-4.9 + env: COMPILER=g++-4.9 + + - compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-5 + env: COMPILER=g++-5 + + - compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-6 + env: COMPILER=g++-6 + + - compiler: gcc + addons: + apt: + sources: ['ubuntu-toolchain-r-test'] + packages: g++-7 + env: COMPILER=g++-7 + - compiler: clang addons: apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.6 - packages: - - clang-3.6 + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.6'] + packages: clang-3.6 env: COMPILER=clang++-3.6 + - compiler: clang addons: apt: - sources: - - ubuntu-toolchain-r-test - - llvm-toolchain-precise-3.7 - packages: - - clang-3.7 + sources: ['ubuntu-toolchain-r-test', 'llvm-toolchain-precise-3.7'] + packages: clang-3.7 env: COMPILER=clang++-3.7 -before_install: - - pip install --user cpp-coveralls + script: - if [[ "${COMPILER}" != "" ]]; then export CXX=${COMPILER}; fi - uname -a @@ -67,5 +74,3 @@ script: - cmake .. && cmake --build . --config Release -- -j4 - ctest -C Release -V - cd .. -#after_success: -# - coveralls --exclude lib --exclude tests --gcov-options '\-lp' \ No newline at end of file diff --git a/README.md b/README.md index 70ed4e5..5f72b13 100644 --- a/README.md +++ b/README.md @@ -5,4 +5,33 @@ A Template Engine for Modern C++ [![Build Status](https://travis-ci.org/pantor/inja.svg?branch=master)](https://travis-ci.org/pantor/inja) [![Coverage Status](https://img.shields.io/coveralls/pantor/inja.svg)](https://coveralls.io/r/pantor/inja) [![Github Issues](https://img.shields.io/github/issues/pantor/inja.svg)](http://github.com/pantor/inja/issues) -[![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/pantor/inja/master/LICENSE.MIT) \ No newline at end of file +[![GitHub License](https://img.shields.io/badge/license-MIT-blue.svg)](https://raw.githubusercontent.com/pantor/inja/master/LICENSE) + + + json data = {{"name", "world"}}; + string result = inja::render("Hello {{ world }}!", data); + // "Hello World!" + + +## Integration + +Inja is headers only. Just one dependency: json by nlohmann. + + #include "json.hpp" + #include "inja.hpp" + + + +## Examples + + +## Supported compilers + +Currently, the following compilers are tested: + +- GCC 4.9 - 7.1 (and possibly later) +- Clang 3.6 - 3.7 (and possibly later) + +## License + +The class is licensed under the [MIT License](https://raw.githubusercontent.com/pantor/inja/master/LICENSE). \ No newline at end of file diff --git a/src/inja.hpp b/src/inja.hpp index 31802a6..268d411 100644 --- a/src/inja.hpp +++ b/src/inja.hpp @@ -1,10 +1,19 @@ +/* + Inja - A Template Engine for Modern C++ +*/ + +#ifndef PANTOR_INJA_HPP +#define PANTOR_INJA_HPP + #include #include #include #include -#include "json/json.hpp" +#ifndef NLOHMANN_JSON_HPP + static_assert(false, "nlohmann/json not found."); +#endif namespace inja { @@ -428,4 +437,11 @@ public: } }; -} // namespace inja \ No newline at end of file +string render(string input, json data) { + Environment env = Environment(); + return env.render(input, data); +} + +} // namespace inja + +#endif // PANTOR_INJA_HPP \ No newline at end of file diff --git a/test/src/test.cpp b/test/src/test.cpp index 13bc596..4f6f556 100644 --- a/test/src/test.cpp +++ b/test/src/test.cpp @@ -1,6 +1,7 @@ #define CATCH_CONFIG_MAIN -#include "../thirdparty/catch.hpp" +#include "../thirdparty/catch/catch.hpp" +#include "../thirdparty/json/json.hpp" #include "../../src/inja.hpp" @@ -212,6 +213,8 @@ TEST_CASE("Render") { REQUIRE( env.render("(% if age != 28 %)Right(% else %)Wrong(% endif %)", data) == "Right" ); REQUIRE( env.render("(% if age >= 30 %)Right(% else %)Wrong(% endif %)", data) == "Wrong" ); REQUIRE( env.render("(% if age in [28, 29, 30] %)True(% endif %)", data) == "True" ); + + // Only works with gcc-5 // REQUIRE( env.render("(% if name in [\"Simon\", \"Tom\"] %)Test1(% else if name in [\"Peter\"] %)Test2(% else %)Test3(% endif %)", data) == "Test2" ); } } diff --git a/test/thirdparty/catch/LICENSE.txt b/test/thirdparty/catch/LICENSE.txt new file mode 100644 index 0000000..36b7cd9 --- /dev/null +++ b/test/thirdparty/catch/LICENSE.txt @@ -0,0 +1,23 @@ +Boost Software License - Version 1.0 - August 17th, 2003 + +Permission is hereby granted, free of charge, to any person or organization +obtaining a copy of the software and accompanying documentation covered by +this license (the "Software") to use, reproduce, display, distribute, +execute, and transmit the Software, and to prepare derivative works of the +Software, and to permit third-parties to whom the Software is furnished to +do so, all subject to the following: + +The copyright notices in the Software and this entire statement, including +the above license grant, this restriction and the following disclaimer, +must be included in all copies of the Software, in whole or in part, and +all derivative works of the Software, unless such copies or derivative +works are solely in the form of machine-executable object code generated by +a source language processor. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE, TITLE AND NON-INFRINGEMENT. IN NO EVENT +SHALL THE COPYRIGHT HOLDERS OR ANYONE DISTRIBUTING THE SOFTWARE BE LIABLE +FOR ANY DAMAGES OR OTHER LIABILITY, WHETHER IN CONTRACT, TORT OR OTHERWISE, +ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER +DEALINGS IN THE SOFTWARE. diff --git a/test/thirdparty/catch.hpp b/test/thirdparty/catch/catch.hpp similarity index 100% rename from test/thirdparty/catch.hpp rename to test/thirdparty/catch/catch.hpp diff --git a/test/thirdparty/json/LICENSE.MIT b/test/thirdparty/json/LICENSE.MIT new file mode 100644 index 0000000..00599af --- /dev/null +++ b/test/thirdparty/json/LICENSE.MIT @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2013-2017 Niels Lohmann + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. diff --git a/src/json/json.hpp b/test/thirdparty/json/json.hpp similarity index 100% rename from src/json/json.hpp rename to test/thirdparty/json/json.hpp