{% comment %}
 # -----------------------------------------------------------------------------
 #  ~/_includes/themes/j1/procedures/global/set_env_entry_document.proc
 #  Liquid PROCEDURE to setup the environment for an (Asciidoc) entry documents
 #  Initializes the all include paths for folders: images, documents and tables
 #
 #  https://jekyll-one.com
 #
 #  Copyright (C) 2019 Juergen Adams
 #
 #  J1 Template is licensed under the MIT License.
 #  See: https://github.com/jekyll-one/j1_template_mde/blob/master/LICENSE
 # -----------------------------------------------------------------------------
 #   Components procedure. Calculate the HTML code for a given button TYPE
 #   based on the button_data (hash) (e.g. taken from the panel configuration)
 #
 #    Usage:
 #      1)  capture the 'set_env_entry_document' variable by full path
 #      2)  include|configure the set_env_entry_document.proc procedure
 #
 #    Example:
 #      {% capture set_env_entry_document %}themes/{{site.template.name}}/procedures/global/set_env_entry_document.proc{%endcapture%}
 #      {% include {{set_env_entry_document}} init_folders=all %}
 #
 # -----------------------------------------------------------------------------
 # Test data:
 #  liquid_var:  {{ liquid_var | debug }}
 # -----------------------------------------------------------------------------
{% endcomment %}

{% comment %} TODO: For POSTS, currently the ASCIIDOC macro include:: does NOT work.
Path calculation needes to be fixed. Seems Jekyll is using different flavours
for page_path (post|pages). 
-------------------------------------------------------------------------------- {% endcomment %}


{% comment %} Liquid procedures
-------------------------------------------------------------------------------- {% endcomment %}
{% capture get_page_path %}themes/{{site.template.name}}/procedures/global/get_page_path.proc{% endcapture %}

{% comment %} Variables
-------------------------------------------------------------------------------- {% endcomment %}
{% assign folders = include.init_folders %}


{% comment %} Include directive (include::)
--------------------------------------------------------------------------------
// Note: The include directive looks like a >>block macro<< but it is a
// >>preprocessor directive<< like ifdef and ifeval. It gets processed
// before the lines are parsed into a document structure.
//
// If the path relative, the processor resolves the path using the following
// rules:
//
// If the include directive is used in the main (top-level) document,
// relative paths are resolved relative to the base directory. (The base
// directory defaults to the directory of the main document and can be
// overridden from the CLI or API).
//
// If the include directive is used in a file that has >>itself been included<<,
// the path is resolved relative to the including (i.e. current) file.

// NOTE: Calculation of Pathes
// Web sources are loaded by the Web Server. The location imagesdir
// is calculated relative to "web_root". Asciidoc resources are being
// collected by AsciiDoctor relative to "page_root"
-------------------------------------------------------------------------------- {% endcomment %}


{% comment %} Variables
-------------------------------------------------------------------------------- {% endcomment %}
{% if site.source.size %} {% assign source_dir = site.source %} {% else %} {% assign source_path = "." %} {% endif %}

{% include {{get_page_path}} %}

{% comment %} dot issue: Woraround - remove "./" from path if site.source = "."
              TODO: Improve Liquid scripts to manage the "dot issue"
-------------------------------------------------------------------------------- {% endcomment %}
{% capture page_root %}{{ page_path | strip | remove_first: './' }}{% endcapture %}
{% capture web_root %}{{ page_path  source_dir }}{% endcapture %}

:includedir:                            {{page_root}}/000_includes
:documentsdir:                          {includedir}/documents
:tabledir:                              {includedir}/tables

{% comment %} Moved imagesdir setting to the document
--------------------------------------------------------------------------------
{% if page.collection %}
  {% assign imagesdir = site.asciidoc_attributes.imagesdir %}
{% else %}
  :imagesdir:                             {{web_root}}/000_includes/images
{% endif %}
--------------------------------------------------------------------------------
{% endcomment %}