matusnovak/doxybook2

.tmpl file include

victorgram opened this issue · 13 comments

When including a custom .tmpl file like this {% include "my_custom_tmpl_file" %}
The renderer failes with the following message:
Exception at Renderer.cpp:143 Failed to parse template 'kind_nonclass' error [inja.exception.file_error] failed accessing file at 'my_custom_tmpl_file'

Hi @victorgram

I have redesigned the template loading system. It is now more robust and loading custom templates should be fine. I have released the changes in the releases/tag/v1.1.0 release. Let me know now if it works for you.

hi @matusnovak
It seems, it is still not working, unless I doing something wrong?

Do you get the same error?

Using templates is easy, just add --templates <dir path> to the command line, nothing more.

Since v1.1.0 the executable will list the templates that are loaded, right at the beginning of stdout, something like this:

$ doxybook2.exe --input ... --output ... --config ... --templates C:\Projects\doxybook2\example\hugo-learn\.doxybook\templates\

Using lookup template path: 'C:\Projects\doxybook2\example\hugo-learn\.doxybook\templates\'
Parsing template: 'meta' from default
Parsing template: 'header' from file: 'C:\Projects\doxybook2\example\hugo-learn\.doxybook\templates\header.tmpl'
Parsing template: 'index' from default
Parsing template: 'footer' from default
Parsing template: 'index_namespaces' from default
Parsing template: 'index_classes' from default
Parsing template: 'index_files' from default
Parsing template: 'index_examples' from default
Parsing template: 'breadcrumbs' from default
Parsing template: 'class_members_tables' from default
Parsing template: 'class_members_inherited_tables' from default
Parsing template: 'details' from default
Parsing template: 'member_details' from default
Parsing template: 'class_members_details' from default
Parsing template: 'kind_class' from default
Parsing template: 'index_pages' from default
Parsing template: 'index_groups' from default
Parsing template: 'kind_page' from default
Parsing template: 'nonclass_members_tables' from default
Parsing template: 'nonclass_members_details' from default
Parsing template: 'kind_file' from default
Parsing template: 'kind_nonclass' from default
Loading...
... rest of the log ...

Do you get the Parsing template: '<name>' from file: <file> line? The default means that the template being loaded is from the src/Doxybook/DefaultTemplates.cpp.

If possible, could you provide a minimal example?

I use the --templates option. We have pulled out all the default .tmpl files, since we have changed them quite a bit to fit our desired styling.
The files are all loaded correctly and shown in the output, as you showed above, with their exact filepath. All except an additional custom .tmpl file that has been created.

Therefore neither {% include "custom_template_name" %} or {{ render ("custom_template_name", data) }} works

I think I have managed to finally fix it. Could you try branch named fix-loading-custom-templates and let me know if it works for you? If you need a pre-compiled binary for this branch for testing let me know.

One small difference. When using {% include "<name>" %} you must use the filename with an extension, for example: {% include "custom_template_name.tmpl" %}. The same goes for the render function: {{ render("custom_template_name.tmpl", data) }}

The include behavior is handled by inja library and I can't change that.

A pre-compiled binary for windows would be nice :)

Just tested this, sadly only {% include "custom_template_name.tmpl" %} worked, but {{ render("custom_template_name.tmpl", data) }} did not.

I can't reproduce that problem. Maybe I am doing something else than you.

I am doing the following:

  1. Download the zip file from my previous comment and extract bin\doxybook.exe to my C:\Users\Matus\Desktop.
  2. Run doxygen inside of the example folder in this repository, just to get some xml files. Copy the xml files into an xml folder C:\Users\Matus\Desktop\xml.
  3. Create empty C:\Users\Matus\Desktop\out folder.
  4. Create another empty C:\Users\Matus\Desktop\templates folder.
  5. Create C:\Users\Matus\Desktop\templates\meta.tmpl (meta template is used by the header template for optional extra markdown metadata) with the following contents:
{% include "custom_template_name.tmpl" %}
{{ render("custom_template_name.tmpl", 123) }}
  1. Create another C:\Users\Matus\Desktop\templates\custom_template_name.tmpl file with the following contents:
key: Hello World!
  1. Run:
cd C:\Users\Matus\Desktop
doxybook2.exe --input .\xml --output .\out --templates .\templates
  1. The output classes, namespaces, etc. have the following in their markdown:
---
title: Engine::Assets
key: Hello World!
key: Hello World!
---

It appears twice because the custom_template_name is included and rendered.

Hi @matusnovak!

I'm a colleague of @victorgram and am taking over the responsibility for this issue.

So I am still facing issues with the render method, but I am unsure what's actually going wrong, it almost seems naming based?

If I add test.tmpl and render it with {{ render("test.tmpl", child) }} it works fine.

If I afterwards add test2.tmpl and edit the render call to {{ render("test2.tmpl", child) }}, it no longer works:

Exception at Renderer.cpp:337 Render template 'kind_nonclass' error Exception at Renderer.cpp:344 Template test2.tmpl not found

If I look at the output, test2.tmpl is not loaded:

[13:00:21]   Using lookup template path: 'support\3rdparty\doxybook2\templates\'
[13:00:21]   Parsing template: 'meta' from file: 'support\3rdparty\doxybook2\templates\meta.tmpl'
[13:00:21]   Parsing template: 'header' from file: 'support\3rdparty\doxybook2\templates\header.tmpl'
[13:00:21]   Parsing template: 'index' from file: 'support\3rdparty\doxybook2\templates\index.tmpl'
[13:00:21]   Parsing template: 'footer' from file: 'support\3rdparty\doxybook2\templates\footer.tmpl'
[13:00:21]   Parsing template: 'index_namespaces' from file: 'support\3rdparty\doxybook2\templates\index_namespaces.tmpl'
[13:00:21]   Parsing template: 'index_classes' from file: 'support\3rdparty\doxybook2\templates\index_classes.tmpl'
[13:00:21]   Parsing template: 'index_files' from file: 'support\3rdparty\doxybook2\templates\index_files.tmpl'
[13:00:21]   Parsing template: 'index_examples' from file: 'support\3rdparty\doxybook2\templates\index_examples.tmpl'
[13:00:21]   Parsing template: 'breadcrumbs' from file: 'support\3rdparty\doxybook2\templates\breadcrumbs.tmpl'
[13:00:21]   Parsing template: 'class_members_tables' from file: 'support\3rdparty\doxybook2\templates\class_members_tables.tmpl'
[13:00:21]   Parsing template: 'class_members_inherited_tables' from file: 'support\3rdparty\doxybook2\templates\class_members_inherited_tables.tmpl'
[13:00:21]   Parsing template: 'details' from file: 'support\3rdparty\doxybook2\templates\details.tmpl'
[13:00:21]   Parsing template: 'member_details' from file: 'support\3rdparty\doxybook2\templates\member_details.tmpl'
[13:00:21]   Parsing template: 'class_members_details' from file: 'support\3rdparty\doxybook2\templates\class_members_details.tmpl'
[13:00:21]   Parsing template: 'kind_class' from file: 'support\3rdparty\doxybook2\templates\kind_class.tmpl'
[13:00:21]   Parsing template: 'index_pages' from file: 'support\3rdparty\doxybook2\templates\index_pages.tmpl'
[13:00:21]   Parsing template: 'index_groups' from file: 'support\3rdparty\doxybook2\templates\index_groups.tmpl'
[13:00:21]   Parsing template: 'kind_page' from file: 'support\3rdparty\doxybook2\templates\kind_page.tmpl'
[13:00:21]   Parsing template: 'nonclass_members_tables' from file: 'support\3rdparty\doxybook2\templates\nonclass_members_tables.tmpl'
[13:00:21]   Parsing template: 'nonclass_members_details' from file: 'support\3rdparty\doxybook2\templates\nonclass_members_details.tmpl'
[13:00:21]   Parsing template: 'kind_file' from file: 'support\3rdparty\doxybook2\templates\kind_file.tmpl'
[13:00:21]   Parsing template: 'kind_nonclass' from file: 'support\3rdparty\doxybook2\templates\kind_nonclass.tmpl'
[13:00:21]   Parsing template: 'test' from file: 'support\3rdparty\doxybook2\templates\test.tmpl'

So I am kind of confused as to what's going on :) Do you get the same results?

Hi @krillboi

Sorry for a late reply. There was a typo (return instead of continue) which definitely caused the problem and only some templates (in your case test.tmpl) to load.

I have fixed it and published it as releases/tag/v1.1.3.

I have also updated the readme to reflect the changes that have happened since the beginning of this issue (changes to the template system in 1.1.0 and up, also what has been said in here) and more information about the template system overall: https://github.com/matusnovak/doxybook2#templates.

It works @matusnovak, thanks for you help! :)

I am glad it works now :)