Start templating engine.

This commit is contained in:
jmsgrogan 2022-10-12 09:01:19 +01:00
parent c0bcfaccac
commit cdd0cc6b78
9 changed files with 230 additions and 1 deletions

View file

@ -13,6 +13,7 @@ list(APPEND TestFiles
core/TestBinaryStream.cpp
core/TestTomlReader.cpp
compiler/TestLexer.cpp
compiler/TestTemplatingEngine.cpp
compression/TestStreamCompressor.cpp
database/TestDatabase.cpp
fonts/TestFontReader.cpp
@ -50,7 +51,7 @@ foreach(TestFile ${TestFiles})
add_executable(${TestName} ${TestFile})
target_link_libraries(${TestName} PUBLIC core compression fonts network image publishing video database geometry audio graphics web client test_utils ${DBUS_LIBRARIES})
target_link_libraries(${TestName} PUBLIC core compiler compression fonts network image publishing video database geometry audio graphics web client test_utils ${DBUS_LIBRARIES})
set_property(TARGET ${TestName} PROPERTY FOLDER test)
endforeach()

View file

@ -0,0 +1,15 @@
#include "TemplatingEngine.h"
#include <filesystem>
#include <iostream>
int main()
{
const auto data_loc = std::filesystem::path(__FILE__) / "../../data";
auto engine = TemplatingEngine(data_loc);
engine.loadTemplateFiles();
engine.processTemplate("index");
}

17
test/data/base.html Normal file
View file

@ -0,0 +1,17 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% block head %}
<link rel="stylesheet" href="style.css" />
<title>{% block title %}{% endblock %} - My Webpage</title>
{% endblock %}
</head>
<body>
<div id="content">{% block content %}{% endblock %}</div>
<div id="footer">
{% block footer %}
&copy; Copyright 2008 by <a href="http://domain.invalid/">you</a>.
{% endblock %}
</div>
</body>
</html>

14
test/data/index.html Normal file
View file

@ -0,0 +1,14 @@
{% extends "base.html" %}
{% block title %}Index{% endblock %}
{% block head %}
{{ super() }}
<style type="text/css">
.important { color: #336699; }
</style>
{% endblock %}
{% block content %}
<h1>Index</h1>
<p class="important">
Welcome to my awesome homepage.
</p>
{% endblock %}