The web mode of the tool provides additional tools for developing websites with static component systems. When run on a project, the tool will copy all files to an output directory, run the templating engine on them, and host the files locally using your preferred web server.
Caution
The system packages for the UVKBuildTool are only built for the UntitledImGuiFramework, since the web version should be project-specific.
Compiling for web
To compile for web, simply run the setup-web.sh
shell
script with an argument for your web project's location. There is only 1
command in this version of the build tool.
Call the UVKBuildTool --build
command with the location
of your build directory, and the location of your project. This will
build and automatically host your project*.
The uvproj.yaml
file
You can define a uvproj.yaml
file in your project's
directory. It provides configuration for the generator. A full file
would look similar to this:
variables:
- var: a
val: a
- var: b
val: b
- var: c
val:
- a
- b
- c
- var: d
val:
a: b
c: d
e: f
g: h
- var: e
val: e
allowed-extensions:
-
- .css
- .js
filename-blacklist:
- test.txt
intermediate-extensions:
- .tmpl
- .tmpl.css
- .tmpl.js
localhost-commands:
- echo 'test' > real.txt
- python3 -m http.server
Variables
The variables
key holds an array of variable objects.
Each variable object has a name and can hold a string key, an array or a
map.
When UVKBuildTool --build
is called, these variables are
added to the parser and all files that have templating applied on them,
can use these variables.
Allowed extensions
In this list, you can add all file extensions you want to use the templating engine on.
File name blacklist
In this list, you can blacklist specific file names from being added to the output build.
ALWAYS
BLACKLIST UBTCustomFunctions
, .git
and
UVKBuildTool
, OTHERWISE YOUR FILE COPY OPERATIONS WILL
REALLY SLOW!!!
Intermediate extensions
In this list, you can list intermediate extensions. These files will have templating applied to them, but will be deleted after all files' templating finishes.
This is best used for files containing components, whose code you want to include into your other files, but don't need these components as independent files.
Localhost commands
This is a list of commands that will be executed to run a local web server for testing
The
run-localhost-automatically
field
If you're running the build tool on a CI system, like GitHub actions,
you can set this variable to false
to disable running the
localhost commands and therefore escaping an infinite loop
occurring.
The
custom-pre-generation-commands
field
Here, you can list commands that will be executed before the pages are processed and generated.
Useful for converting Markdown to HTML.
The custom include
function
A custom include
function is provided to the templating
engine. Using it, you can do automatic copy-paste from a file into your
file in a way, similar to C's #include
statements
The function receives a list of files. All files' contents are run through the templating engine and then their content is concatenated into a string, which is placed on the position of the include call.
Custom localisation functions
We use the UntitledI18N library for localising websites. The following 2 functions can be used to translate your page:
_
- Given a string ID, returns the translation. Additionally, pass an array after the ID to feed the positional arguments or a map to feed temporary variablesui18n_push_global_variable
- Given a variadic list of arguments, pushes a global variable. Every odd argument(after the function name) is the name of the variable, and every even argument is its value.
Translation config files are stored under the
Translations
directory.
Generated pages are stored under a directory corresponding to their
locale. For example, the translated version of index
for en_US
is stored under
mysite/en_US
.
More information about the translation format can be found here.
Adding custom functions to the templating engine
When first setting up the build tool for your project, a
UBTCustomFunctions
folder will be created, with the only
function there being UBT::funcExportMain
.
This function is called every time you build your project. Here you can add custom functions and variables to the generator. A reference to the generator used by the build tool is provided to the function as its only argument.
Since this function is written in C++, you will need to rebuild the
build tool. To do this easily, run rebuild.sh
by passing
the file location of your project and your project type
--web
(this is what you want to use) or
--framework
. Example:
https://madladsquad.com/rebuild.sh .. --web
Rerun this function every time you change the
UBTCustomFunctions.cpp
and
UBTCustomFunctions.hpp
files.