feat add mustache.hpp
This commit is contained in:
parent
f99ccf6baf
commit
fd8fdfc5f5
@ -225,6 +225,7 @@ target_precompile_headers(tile PUBLIC json/nlohann/json.hpp)
|
|||||||
target_include_directories(
|
target_include_directories(
|
||||||
tile
|
tile
|
||||||
PUBLIC
|
PUBLIC
|
||||||
|
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/mustache.hpp"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}"
|
"${CMAKE_CURRENT_BINARY_DIR}"
|
||||||
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/fmt/include"
|
"${CMAKE_CURRENT_SOURCE_DIR}/third_party/fmt/include"
|
||||||
"${CMAKE_CURRENT_BINARY_DIR}/third_party/glog"
|
"${CMAKE_CURRENT_BINARY_DIR}/third_party/glog"
|
||||||
|
5
third_party/mustache/.gitignore
vendored
Normal file
5
third_party/mustache/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
/build
|
||||||
|
/build_xcode
|
||||||
|
/build64
|
||||||
|
mustache
|
||||||
|
mustache14
|
26
third_party/mustache/.travis.yml
vendored
Normal file
26
third_party/mustache/.travis.yml
vendored
Normal file
@ -0,0 +1,26 @@
|
|||||||
|
language: cpp
|
||||||
|
|
||||||
|
sudo: required
|
||||||
|
dist: trusty
|
||||||
|
|
||||||
|
matrix:
|
||||||
|
include:
|
||||||
|
- os: linux
|
||||||
|
compiler: gcc
|
||||||
|
|
||||||
|
- os: linux
|
||||||
|
compiler: clang
|
||||||
|
|
||||||
|
- os: osx
|
||||||
|
compiler: clang
|
||||||
|
|
||||||
|
script:
|
||||||
|
- make coverage
|
||||||
|
|
||||||
|
after_success:
|
||||||
|
# Use "-X gcov" to disable Codecov from running gcov. We already run this
|
||||||
|
# command in "make coverage" and then delete unwanted coverage files that
|
||||||
|
# contribute falsely to the coverage report, such as catch.hpp
|
||||||
|
# Only send Linux (GCC) code coverage as the clang ones seem to be buggy and
|
||||||
|
# report curly braces as unexecuted lines.
|
||||||
|
- if [ "${TRAVIS_OS_NAME}" == "linux" ]; then bash <(curl -s https://codecov.io/bash) -X gcov; fi
|
19
third_party/mustache/CMakeLists.txt
vendored
Normal file
19
third_party/mustache/CMakeLists.txt
vendored
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
cmake_minimum_required(VERSION 2.8)
|
||||||
|
project(mustache)
|
||||||
|
if (UNIX)
|
||||||
|
add_definitions(
|
||||||
|
-Wall
|
||||||
|
-Wextra
|
||||||
|
-Werror
|
||||||
|
-std=c++11
|
||||||
|
)
|
||||||
|
elseif (MSVC)
|
||||||
|
add_definitions(
|
||||||
|
/W3
|
||||||
|
/WX
|
||||||
|
)
|
||||||
|
endif()
|
||||||
|
add_executable(mustache
|
||||||
|
mustache.hpp # to show in IDE
|
||||||
|
tests.cpp
|
||||||
|
)
|
25
third_party/mustache/LICENSE
vendored
Normal file
25
third_party/mustache/LICENSE
vendored
Normal file
@ -0,0 +1,25 @@
|
|||||||
|
Boost Software License - Version 1.0
|
||||||
|
|
||||||
|
Copyright 2015-2020 Kevin Wojniak
|
||||||
|
|
||||||
|
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.
|
31
third_party/mustache/Makefile
vendored
Normal file
31
third_party/mustache/Makefile
vendored
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
default:
|
||||||
|
g++ -O3 -Wall -Wextra -Werror -std=c++11 -o mustache tests.cpp
|
||||||
|
./mustache
|
||||||
|
|
||||||
|
mac:
|
||||||
|
clang++ -O3 -Wall -Wextra -Werror -std=c++11 -stdlib=libc++ -o mustache tests.cpp
|
||||||
|
./mustache
|
||||||
|
|
||||||
|
mac14:
|
||||||
|
clang++ -O3 -Wall -Wextra -Werror -std=c++14 -stdlib=libc++ -o mustache14 tests.cpp
|
||||||
|
./mustache14
|
||||||
|
|
||||||
|
clang:
|
||||||
|
clang++ -O3 -Wall -Wextra -Werror -std=c++11 -o mustache tests.cpp
|
||||||
|
|
||||||
|
# https://gcc.gnu.org/onlinedocs/gcc/Invoking-Gcov.html
|
||||||
|
coverage:
|
||||||
|
g++ -std=c++11 -coverage -O0 -o mustache tests.cpp
|
||||||
|
./mustache
|
||||||
|
gcov -l tests.cpp
|
||||||
|
# We only want coverage for mustache.hpp and tests.cpp, so delete all the other *.gcov files
|
||||||
|
find . -type f -name 'tests.cpp*.gcov' ! -name 'tests.cpp.gcov' ! -name 'tests.cpp##mustache.hpp.gcov' -delete
|
||||||
|
|
||||||
|
xcode:
|
||||||
|
mkdir -p build_xcode
|
||||||
|
cd build_xcode && cmake -GXcode ..
|
||||||
|
open build_xcode/*.xcodeproj
|
||||||
|
|
||||||
|
clean:
|
||||||
|
rm -rf mustache mustache14 build build_xcode
|
||||||
|
rm -rf *.gcov *.gcda *.gcno # coverage artifacts
|
125
third_party/mustache/README.md
vendored
Normal file
125
third_party/mustache/README.md
vendored
Normal file
@ -0,0 +1,125 @@
|
|||||||
|
# About
|
||||||
|
|
||||||
|
* [Mustache](http://mustache.github.io) implementation for modern C++ (requires C++11)
|
||||||
|
* Header only
|
||||||
|
* Zero dependencies
|
||||||
|
* Templated string type for compatibility with any STL-like string (std::string, std::wstring, etc)
|
||||||
|
* Boost license
|
||||||
|
|
||||||
|
[![travis](https://travis-ci.org/kainjow/Mustache.svg?branch=master)](https://travis-ci.org/kainjow/Mustache) [![appveyor](https://ci.appveyor.com/api/projects/status/6uh5d5weajrffkyw?svg=true)](https://ci.appveyor.com/project/kainjow/mustache) [![codecov](https://codecov.io/gh/kainjow/Mustache/branch/master/graph/badge.svg)](https://codecov.io/gh/kainjow/Mustache)
|
||||||
|
|
||||||
|
## Example usage
|
||||||
|
|
||||||
|
All examples assume `using namespace kainjow::mustache`. Additional examples and usage can be found in the `tests.cpp` file.
|
||||||
|
|
||||||
|
### Example 1 - Hello World
|
||||||
|
|
||||||
|
````cpp
|
||||||
|
mustache tmpl{"Hello {{what}}!"};
|
||||||
|
std::cout << tmpl.render({"what", "World"}) << std::endl;
|
||||||
|
// Hello World!
|
||||||
|
````
|
||||||
|
|
||||||
|
### Example 2 - Lists
|
||||||
|
|
||||||
|
````cpp
|
||||||
|
mustache tmpl{"{{#employees}}{{name}}, {{/employees}}"};
|
||||||
|
data employees{data::type::list};
|
||||||
|
employees << data{"name", "Steve"} << data{"name", "Bill"};
|
||||||
|
tmpl.render({"employees", employees}, std::cout);
|
||||||
|
// Steve, Bill,
|
||||||
|
````
|
||||||
|
|
||||||
|
### Example 3 - Custom Render Handler
|
||||||
|
|
||||||
|
````cpp
|
||||||
|
mustache tmpl("Hello {{what}}!");
|
||||||
|
std::stringstream ss;
|
||||||
|
tmpl.render({"what", "World"}, [&ss](const std::string& str) {
|
||||||
|
ss << str;
|
||||||
|
});
|
||||||
|
// ss.str() == "Hello World!"
|
||||||
|
````
|
||||||
|
|
||||||
|
## Supported Features
|
||||||
|
|
||||||
|
This library supports all current Mustache features:
|
||||||
|
|
||||||
|
- Variables
|
||||||
|
- HTML escaping
|
||||||
|
- Sections
|
||||||
|
- Inverted Sections
|
||||||
|
- True/False
|
||||||
|
- Lists
|
||||||
|
- Lambdas
|
||||||
|
- Partials
|
||||||
|
- Comments
|
||||||
|
- Set Delimiter
|
||||||
|
|
||||||
|
Additional features:
|
||||||
|
|
||||||
|
- Custom escape function for use outside of HTML
|
||||||
|
|
||||||
|
## Run Tests
|
||||||
|
|
||||||
|
For *nix:
|
||||||
|
|
||||||
|
make
|
||||||
|
|
||||||
|
For macOS:
|
||||||
|
|
||||||
|
make mac
|
||||||
|
|
||||||
|
For Visual Studio 2013 (CMake 2.8+ required):
|
||||||
|
|
||||||
|
build.bat
|
||||||
|
|
||||||
|
For Visual Studio 2015 (CMake 3.1+ required):
|
||||||
|
|
||||||
|
build.bat 14
|
||||||
|
|
||||||
|
## Release Notes
|
||||||
|
|
||||||
|
#### 4.1 - April 18, 2020
|
||||||
|
|
||||||
|
* Fixed incorrect results when using lambda renderers
|
||||||
|
|
||||||
|
#### 4.0 - October 28, 2019
|
||||||
|
|
||||||
|
* Lines with sections that result in an empty line are removed, per the Mustache spec.
|
||||||
|
|
||||||
|
#### 3.2.1 - July 22, 2018
|
||||||
|
|
||||||
|
* Add an overload to render() that accepts a context and a stream (thanks Kitsune Ral)
|
||||||
|
* Added checks for empty objects (thanks Snafuuz)
|
||||||
|
* Refactored parser in preparation for future changes
|
||||||
|
|
||||||
|
#### 3.2 - February 24, 2018
|
||||||
|
|
||||||
|
* Added ability to provide a custom escape function (thanks to Kitsune Ral)
|
||||||
|
* Allow `data.set()` to override an existing value
|
||||||
|
|
||||||
|
#### 3.1 - July 22, 2017
|
||||||
|
|
||||||
|
* Added a new lambda type (innovatively called `lambda2`) that takes an additional render function. It will not render its result but allows the user to call the `render` argument to render the section text, or any other text.
|
||||||
|
|
||||||
|
#### 3.0 - July 8, 2017
|
||||||
|
|
||||||
|
* Performance improvements - about 45% faster than version 2
|
||||||
|
* Even simpler API. Not backwards compatible but upgrading should be straightforward:
|
||||||
|
* Namespace, classes, and methods are now in snake case to match the STL. For example, `Kainjow::Mustache` is now `kainjow::mustache`
|
||||||
|
* Classes and aliases are now under a `mustache` namespace, instead of being under the mustache class
|
||||||
|
* Removed `Data::List()` - use `data{data::type::list}` instead
|
||||||
|
* Removed `Data::type()` - use the various `is_xxx` methods to identity the type
|
||||||
|
|
||||||
|
#### 2.0 - June 11, 2016
|
||||||
|
|
||||||
|
* New simpler API (not backwards compatible)
|
||||||
|
* std::wstring support
|
||||||
|
* Bug fixes (thanks to Shen-Ta Hsieh)
|
||||||
|
* Automated tests on OS X
|
||||||
|
* 100% test coverage
|
||||||
|
|
||||||
|
#### 1.0 - April 19, 2015
|
||||||
|
|
||||||
|
* All current Mustache features are implemented.
|
18
third_party/mustache/appveyor.yml
vendored
Normal file
18
third_party/mustache/appveyor.yml
vendored
Normal file
@ -0,0 +1,18 @@
|
|||||||
|
branches:
|
||||||
|
only:
|
||||||
|
- master
|
||||||
|
environment:
|
||||||
|
matrix:
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2013
|
||||||
|
CMAKE_GENERATOR: Visual Studio 12 Win64
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2015
|
||||||
|
CMAKE_GENERATOR: Visual Studio 14 Win64
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2017
|
||||||
|
CMAKE_GENERATOR: Visual Studio 15 Win64
|
||||||
|
- APPVEYOR_BUILD_WORKER_IMAGE: Visual Studio 2019
|
||||||
|
CMAKE_GENERATOR: Visual Studio 16 2019
|
||||||
|
platform: x64
|
||||||
|
build_script:
|
||||||
|
- cmake -G "%CMAKE_GENERATOR%" .
|
||||||
|
- cmake --build . --config Release
|
||||||
|
- Release\mustache.exe
|
50
third_party/mustache/build.bat
vendored
Normal file
50
third_party/mustache/build.bat
vendored
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
:: don't output commands
|
||||||
|
@echo off
|
||||||
|
|
||||||
|
:: get version from input args
|
||||||
|
:: default value is 12
|
||||||
|
:: only 12 and 14 are supported
|
||||||
|
set vers=%1
|
||||||
|
if "%vers%" == "" set vers=12
|
||||||
|
if "%vers%" neq "12" (
|
||||||
|
if "%vers%" neq "14" (
|
||||||
|
echo Invalid version "%vers%" - expected 12 or 14.
|
||||||
|
exit /b 1
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
:: make build directory
|
||||||
|
if not exist build mkdir build
|
||||||
|
pushd build
|
||||||
|
|
||||||
|
:: run CMake
|
||||||
|
cmake -G "Visual Studio %vers%" ..
|
||||||
|
if %errorlevel% neq 0 popd & exit /b %errorlevel%
|
||||||
|
|
||||||
|
:: build with CMake
|
||||||
|
cmake --build . --config Release
|
||||||
|
if %errorlevel% neq 0 popd & exit /b %errorlevel%
|
||||||
|
|
||||||
|
:: run tests
|
||||||
|
Release\mustache.exe
|
||||||
|
if %errorlevel% neq 0 popd & exit /b %errorlevel%
|
||||||
|
|
||||||
|
popd
|
||||||
|
|
||||||
|
:: make build64 directory
|
||||||
|
if not exist build64 mkdir build64
|
||||||
|
pushd build64
|
||||||
|
|
||||||
|
:: run CMake
|
||||||
|
cmake -G "Visual Studio %vers% Win64" ..
|
||||||
|
if %errorlevel% neq 0 popd & exit /b %errorlevel%
|
||||||
|
|
||||||
|
:: build with CMake
|
||||||
|
cmake --build . --config Release
|
||||||
|
if %errorlevel% neq 0 popd & exit /b %errorlevel%
|
||||||
|
|
||||||
|
:: run tests
|
||||||
|
Release\mustache.exe
|
||||||
|
if %errorlevel% neq 0 popd & exit /b %errorlevel%
|
||||||
|
|
||||||
|
popd
|
11689
third_party/mustache/catch.hpp
vendored
Normal file
11689
third_party/mustache/catch.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1185
third_party/mustache/mustache.hpp
vendored
Normal file
1185
third_party/mustache/mustache.hpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
1504
third_party/mustache/tests.cpp
vendored
Normal file
1504
third_party/mustache/tests.cpp
vendored
Normal file
File diff suppressed because it is too large
Load Diff
@ -44,6 +44,7 @@
|
|||||||
#include "sigslot/signal.h"
|
#include "sigslot/signal.h"
|
||||||
|
|
||||||
// Tile Init
|
// Tile Init
|
||||||
|
#include "mustache.hpp"
|
||||||
#include "tile/init.h"
|
#include "tile/init.h"
|
||||||
|
|
||||||
#endif // TILE_TILE_H
|
#endif // TILE_TILE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user