From 7bdd14ad52db994ef0052672e48e5d2f5de7f254 Mon Sep 17 00:00:00 2001 From: csatari Date: Thu, 23 Feb 2017 04:04:10 +0100 Subject: [PATCH] Dynamic setting of header markup As the top level header in index.rst and get_started.rst depends on cookiecutter.service the length of the header markups should also depend on the length of cookiecutter.service. Unfortunatelly I was not able to figure out how to include the macro from a different template, so there is a copy-paste there. Change-Id: Iff2255f10690f23de270b84c1bd0cd7de3c611a3 Signed-off-by: csatari --- .../source/get_started.rst | 14 ++++++++++---- {{cookiecutter.directory_name}}/source/index.rst | 13 ++++++++++--- 2 files changed, 20 insertions(+), 7 deletions(-) diff --git a/{{cookiecutter.directory_name}}/source/get_started.rst b/{{cookiecutter.directory_name}}/source/get_started.rst index e07748c..0b1a052 100644 --- a/{{cookiecutter.directory_name}}/source/get_started.rst +++ b/{{cookiecutter.directory_name}}/source/get_started.rst @@ -1,7 +1,13 @@ -========================= -{{cookiecutter.service}} service overview -========================= - +{%- macro set_header_markup(header_text_length) -%} +{%- set servicelength = cookiecutter.service|length -%} +{%- for _ in range(0, servicelength + header_text_length) -%}={%- endfor -%} +{%- endmacro -%} +{%- macro set_header(header_text) -%} +{{ set_header_markup(header_text|length) }} +{{cookiecutter.service}}{{header_text}} +{{ set_header_markup(header_text|length) }} +{%- endmacro -%} +{{ set_header(" service overview") }} The {{cookiecutter.service}} service provides... The {{cookiecutter.service}} service consists of the following components: diff --git a/{{cookiecutter.directory_name}}/source/index.rst b/{{cookiecutter.directory_name}}/source/index.rst index 01d4936..af7a9cd 100644 --- a/{{cookiecutter.directory_name}}/source/index.rst +++ b/{{cookiecutter.directory_name}}/source/index.rst @@ -1,6 +1,13 @@ -===================== -{{cookiecutter.service}} service -===================== +{%- macro set_header_markup(header_text_length) -%} +{%- set servicelength = cookiecutter.service|length -%} +{%- for _ in range(0, servicelength + header_text_length) -%}={%- endfor -%} +{%- endmacro -%} +{%- macro set_header(header_text) -%} +{{ set_header_markup(header_text|length) }} +{{cookiecutter.service}}{{header_text}} +{{ set_header_markup(header_text|length) }} +{%- endmacro -%} +{{ set_header(" service") }} .. toctree:: :maxdepth: 2