mirror of
https://github.com/pantor/inja.git
synced 2026-02-17 09:03:58 +00:00
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:
11
test/data/html-extend/base.txt
Normal file
11
test/data/html-extend/base.txt
Normal 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>
|
||||
12
test/data/html-extend/data.json
Normal file
12
test/data/html-extend/data.json
Normal 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."
|
||||
}
|
||||
3
test/data/html-extend/inter.txt
Normal file
3
test/data/html-extend/inter.txt
Normal file
@@ -0,0 +1,3 @@
|
||||
{% extends "base.txt" %}
|
||||
{% block title %}Inter {{ author }}{% endblock %}
|
||||
{% block body %}<main>Intermediate Content</main>{% endblock %}
|
||||
11
test/data/html-extend/result.txt
Normal file
11
test/data/html-extend/result.txt
Normal 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>
|
||||
7
test/data/html-extend/template.txt
Normal file
7
test/data/html-extend/template.txt
Normal 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 %}
|
||||
@@ -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"));
|
||||
|
||||
Reference in New Issue
Block a user