- Rendering of JSX based views in C++
complate adapter that can be used in C++ 17 projects to render JSX based HTML views. This project was inspired by complate-java.
For a detailed description how to use this library checkout out the User Guide. I recommend you to check out the dedicated Sample Project to try out complate-cpp.
import {createElement} from 'complate-stream';
export default function Greeting({person}) {
return <html>
<head>
<meta charSet="UTF-8"/>
<title>Greeting | Example</title>
</head>
<body>
<h1>Hello {person.name}</h1>
</body>
</html>
}
// Please read User Guide - Instantiate a Renderer, for more details.
unique_ptr<Renderer> renderer;
string html = renderer->renderToString("Greeting", Object{
{ "person", Object{
{ "name", "John Doe" }
}}
});
# install dependencies
sudo apt install -y build-essential git cmake libv8-dev
# build and install the library
git clone https://github.com/tmehnert/complate-cpp.git && cd complate-cpp
cmake -B build
cmake --build build -j4
sudo cmake --install build/
When you have installed the library, you can use find_package
and
target_link_libraries
as follows.
find_package(complate REQUIRED CONFIG)
# and
target_link_libraries(your_app PRIVATE complate::quickjs)
# or
target_link_libraries(your_app PRIVATE complate::v8)
Another possibility, without having to install the library, is let CMake fetch it. When you use this method, you may not
use find_package(complate)
. Just put the following commands in your CMakeLists.txt file and replace the GIT_TAG HEAD
with the commit-sha or git-tag you want.
message("-- Fetching complate...")
FetchContent_Declare(
complate
GIT_REPOSITORY https://github.com/tmehnert/complate-cpp.git
GIT_TAG HEAD
GIT_SHALLOW 1
)
FetchContent_MakeAvailable(complate)
message("-- Fetching complate - done")
# and
target_link_libraries(your_app PRIVATE complate::quickjs)
# or
target_link_libraries(your_app PRIVATE complate::v8)
The unittests and the example are not built by default, you have to enable them using BUILD_TESTS=on and BUILD_EXAMPLE=on as shown below.
# install dependencies
sudo apt install -y build-essential git cmake libv8-dev
# build the project with tests and example enabled
git clone https://github.com/tmehnert/complate-cpp.git && cd complate-cpp
cmake -B build -DBUILD_TESTS=on -DBUILD_EXAMPLE=on
cmake --build build -j4
cd build/
# execute tests
ctest --output-on-failure
# run example, which starts a webserver which serves views/greeting.jsx.
example/complate-example
The library is tested with following compilers.
- GCC 7 - 10
- Clang 7 - 12
Only QuickJS supported, build with -DBUILD_V8_RENDERER=off
. ThreadLocalRenderer is not supported using MinGW and will
raise a compiler error is you accidentally use it.
- MinGW latest installed from MSYS2.
Only QuickJS supported, build with -DBUILD_V8_RENDERER=off
.
- AppleClang on macOS 10.15.
- Catch2, BSL-1.0 (fetched via CMake)
- trompeloeil, BSL-1.0 (fetched via CMake)
- cpp-httplib, MIT License (fetched via CMake)
- Node.js
- CMake >= 3.14 required
complate-cpp is Open Source software released under the Apache 2.0 license.
See LICENCE for more information about bundled software.