Add Child Inheritance Feature (#198)

* add block and extend feature

* constify, code cleaning

* update single include

* add html language to readme

* clean tests

* constantify, update year
This commit is contained in:
pantor
2021-05-25 10:18:21 +02:00
committed by GitHub
parent b4b9d8dc16
commit 95af782ca2
22 changed files with 561 additions and 173 deletions

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
{% block head -%}
<title>{% block title %}Default - {% endblock %}</title>
{%- endblock -%}
</head>
<body>
{% block body %}ignored{% endblock %}
</body>
</html>

View File

@@ -0,0 +1,12 @@
{
"author": "Pantor",
"date": "23/12/2018",
"tags": [
"test",
"templates"
],
"views": 123,
"title": "Inja works.",
"content": "Inja is the best and fastest template engine for C++. Period.",
"footer-text": "This is the footer."
}

View File

@@ -0,0 +1,3 @@
{% extends "base.txt" %}
{% block title %}Inter {{ author }}{% endblock %}
{% block body %}<main>Intermediate Content</main>{% endblock %}

View File

@@ -0,0 +1,11 @@
<!DOCTYPE html>
<html lang="en">
<head>
<title>Default - Inter Pantor: Inja works.</title>
<style type="text/css">.important { color: #336699; }</style>
</head>
<body>
<main>Inja is the best and fastest template engine for C++. Period.</main>
</body>
</html>

View File

@@ -0,0 +1,7 @@
{% extends "inter.txt" %}
{% block head -%}
{{ super(2) }}
<style type="text/css">.important { color: #336699; }</style>
{%- endblock %}
{% block title %}{{ super(2) }}{{ super() }}: {{ title }}{% endblock %}
{% block body %}<main>{{ content }}</main>{% endblock %}

View File

@@ -27,7 +27,7 @@ TEST_CASE("loading") {
TEST_CASE("complete-files") {
inja::Environment env {test_file_directory};
for (std::string test_name : {"simple-file", "nested", "nested-line", "html"}) {
for (std::string test_name : {"simple-file", "nested", "nested-line", "html", "html-extend"}) {
SUBCASE(test_name.c_str()) {
CHECK(env.render_file_with_json_file(test_name + "/template.txt", test_name + "/data.json") ==
env.load_file(test_name + "/result.txt"));