diff --git a/CMakeLists.txt b/CMakeLists.txt
index 439a757..5b8510c 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -1,11 +1,11 @@
cmake_minimum_required(VERSION 3.18)
-project(hypertextcpp VERSION 1.2.1 DESCRIPTION "hypertextcpp")
+project(hypertextcpp VERSION 2.0.0 DESCRIPTION "hypertextcpp")
include(external/seal_lake)
-SealLake_Import(cmdlime 2.6.0
+SealLake_Import(cmdlime 2.7.0
GIT_REPOSITORY https://github.com/kamchatka-volcano/cmdlime
- GIT_TAG dev
+ GIT_TAG v2.7.0
)
SealLake_Import(sfun 5.1.0
@@ -24,6 +24,10 @@ SealLake_Bundle(
GIT_REPOSITORY https://github.com/ericniebler/range-v3
GIT_TAG 0.12.0
)
+SealLake_Import(fmt 9.1.0
+ GIT_REPOSITORY https://github.com/fmtlib/fmt
+ GIT_TAG 9.1.0
+)
set(SRC
src/codenode.cpp
@@ -41,7 +45,8 @@ set(SRC
src/utils.cpp
src/node_utils.cpp
src/single_header_transpiler_renderer.cpp
- src/shared_lib_transpiler_renderer.cpp)
+ src/shared_lib_transpiler_renderer.cpp
+ src/header_and_source_transpiler_renderer.cpp)
SealLake_Executable(
@@ -54,6 +59,7 @@ SealLake_Executable(
cmdlime::cmdlime
sfun::sfun
Microsoft.GSL::GSL
+ fmt::fmt
)
SealLake_OptionalSubProjects(tests examples)
diff --git a/README.md b/README.md
index 5378892..ca935ec 100644
--- a/README.md
+++ b/README.md
@@ -252,33 +252,66 @@ Now the tasks list can be output to stdout by itself like this:
### Command line parameters
```console
kamchatka-volcano@home:~$ hypertextcpp --help
-Usage: hypertextcpp [params] [flags]
+Usage: hypertextcpp [commands] [flags]
+Flags:
+ --help show usage info and exit
+Commands:
+ generateHeaderOnly [options] generate header only file
+ generateSharedLibrarySource [options] generate shared library source
+ file
+ generateHeaderAndSource [options] generate header and source files
+ ```
+
+Single header renderer generation:
+ ```console
+kamchatka-volcano@home:~$ hypertextcpp generateHeaderOnly --help
+Usage: hypertextcpp generateHeaderOnly [params] [flags]
+Arguments:
+ (path) .htcpp file to transpile
+ -outputDir= output dir
+ (if empty, current working directory is used)
+ (optional, default: "")
+ -className= generated class name
+ (if empty, input file name is used)
+ (optional, default: "")
+Flags:
+ --help show usage info and exit
+ ```
+
+Header and source renderer generation:
+ ```console
+kamchatka-volcano@home:~$ hypertextcpp generateHeaderAndSource --help
+Usage: hypertextcpp generateHeaderAndSource -configClassName= [params] [flags]
Arguments:
(path) .htcpp file to transpile
Parameters:
- -o, --output output c++ file path
+ -configClassName= config class name
+ -outputDir= output dir
(if empty, current working directory is used)
(optional, default: "")
- -c, --class-name generated class name
- (optional)
+ -className= generated class name
+ (if empty, input file name is used)
+ (optional, default: "")
Flags:
- -s, --shared-lib generate result as shared library source
- files
- --class-pascalcase generate class name by using .htcpp filename
- in PascalCase
- --class-snakecase generate class name by using .htcpp filename
- in snake_case
- --class-lowercase generate class name by using .htcpp filename
- in lowercase
- --help show usage info and exit
-
-
-Process finished with exit code 0
+ --help show usage info and exit
+ ```
+Shared library renderer generation:
+ ```console
+kamchatka-volcano@home:~$ hypertextcpp generateSharedLibrarySource --help
+Usage: hypertextcpp generateSharedLibrarySource [params] [flags]
+Arguments:
+ (path) .htcpp file to transpile
+ -outputDir= output dir
+ (if empty, current working directory is used)
+ (optional, default: "")
+Flags:
+ --help show usage info and exit
```
+
### Single header renderer
-By default, the **hypertextcpp** transpiler works in a single header mode and generates a C++ header file that you're supposed to simply include in your project. A generated renderer class has the name of the `.htcpp` template file. You can override the name by using the `--class-name` parameter, or you can specify one of the following flags: `--class-pascalcase`, `--class-snakecase`, or `--class-lowercase` to use the `.htcpp` template's filename converted to the corresponding case as a class name.
+In this mode, the **hypertextcpp** generates a C++ header file that you're supposed to simply include in your project. A generated renderer class has the name of the `.htcpp` template file.
Converting the template to C++ code each time you modify it is a laborious task, so it makes sense to add this step to your build process. To do this with CMake you can use `hypertextcpp_GenerateHeader` function from the `hypertextcpp.cmake` file.
Note that this function launches the `hypertextcpp` executable, so it should be installed on your system first.
@@ -288,23 +321,37 @@ cmake_minimum_required(VERSION 3.18)
include(../../hypertextcpp.cmake)
-hypertextcpp_GenerateHeader(NAME todolist CLASS_NAME TodoList)
+hypertextcpp_GenerateHeader(
+ TEMPLATE_FILE todolist.htcpp
+ CLASS_NAME TodoList
+)
set(SRC
todolist_printer.cpp
todolist.h)
+#Please note that to generate the header todolist.h, it must pe passed to the target sources
add_executable(todolist_printer ${SRC})
target_compile_features(todolist_printer PUBLIC cxx_std_17)
set_target_properties(todolist_printer PROPERTIES CXX_EXTENSIONS OFF)
```
-Now, every time you change the template, the corresponding header will be regenerated on the next build.
+Now, every time you change the template `todolist.htcpp`, the corresponding header will be regenerated on the next build.
+
+### Header and source renderer
+It can feel quite wasteful to rebuild all object files that include the renderer header each time the template file is changed, so `hypertextcpp` supports the generation of the renderer as a header and implementation file. In this mode, the generated rendering methods aren't function templates, and you need to provide the config name as a command-line parameter and either define the config structure inside the template or include it from there (check `examples/ex_06` and `examples/ex_07`).
+To do this with CMake, you can use the `hypertextcpp_GenerateHeaderAndSource` function from the `hypertextcpp.cmake` file.
+
+```
+hypertextcpp_GenerateHeaderAndSource(
+ TEMPLATE_FILE todolist.htcpp
+ CONFIG_CLASS_NAME PageParams)
+```
### Shared library renderer
-It can feel quite wasteful to rebuild your project each time the template file is changed, so **hypertextcpp** supports the generation of a C++ source file for building templates in the form of shared libraries and linking them dynamically from your application.
-It requires duplicating the config declaration in the .htcpp template, registering it with the `HTCPP_CONFIG` macro in both the template and the application source, generating the renderer code with the `--shared-lib` command line flag, building the library, and loading it using the tiny API installed from the `shared_lib_api/` directory. It sounds scarier than it is, so let's quickly update the todolist example to see how it works.
+ **hypertextcpp** also supports the generation of a C++ source file for building templates in the form of shared libraries and linking them dynamically from your application. This way it's possible to rebuild the template and update it without restarting the application.
+It requires duplicating the config declaration in the .htcpp template, registering it with the `HTCPP_CONFIG` macro in both the template and the application source, generating the renderer code with the `generateSharedLibrarySource` command, building the library, and loading it using the tiny API installed from the `shared_lib_api/` directory. It sounds scarier than it is, so let's quickly update the todolist example to see how it works.
First we need to copy the config structure declaration in the template:
[`examples/05/todolist.htcpp`](examples/05/todolist.htcpp)
@@ -336,7 +383,7 @@ First we need to copy the config structure declaration in the template: