#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# Django Markdownx documentation build configuration file, created by
# sphinx-quickstart on Fri Mar 10 22:41:38 2017.
#
# This file is execfile()d with the current directory set to its
# containing dir.
#
# Note that not all possible configuration values are present in this
# autogenerated file.
#
# All configuration values have a default; values that are commented out
# serve to show the default.

# If extensions (or modules to document with autodoc) are in another directory,
# add these directories to sys.path here. If the directory is relative to the
# documentation root, use os.path.abspath to make it absolute, like shown here.

from os import path
import sys
from datetime import datetime
from re import compile as re_compile, MULTILINE

sys.path.insert(0, path.abspath(path.join(path.pardir, path.pardir)))
sys.path.insert(0, path.abspath('_ext'))

# -- General configuration ------------------------------------------------

# Add any Sphinx extension module names here, as strings. They can be
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
# ones.
extensions = [
    'sphinx.ext.autodoc',
    'sphinx.ext.coverage',
    'sphinx.ext.mathjax',
    'sphinx.ext.viewcode',
    'sphinx.ext.githubpages',
    'classycode',
    'sphinxcontrib.autoanysrc',
    # 'edit_on_github'
]

templates_path = ['_templates']
html_theme_path = ['_themes']
html_static_path = ['_static']
source_suffix = '.rst'
pygments_style = 'sphinx'
html_theme = 'sphinx_rtd_theme'
language = None
exclude_patterns = []
todo_include_todos = False
html_theme_options = {}
htmlhelp_basename = 'DjangoMarkdownxdoc'
master_doc = 'index'

# sphinxcontrib-srclinks extension settings:
edit_on_github_project = 'adi-/django-markdownx'
edit_on_github_branch = 'master'

# General information about the project.
project = 'Django Markdownx'
copyright = '{:%Y} - Adi, Pouria Hadjibagheri'.format(datetime.now())
author = 'Adi, Pouria Hadjibagheri'


# Grouping the document tree into LaTeX files. List of tuples
# (source start file, target name, title,
#  author, documentclass [howto, manual, or own class]).
latex_documents = [
    (
        master_doc,
        'DjangoMarkdownx.tex',
        'Django Markdownx Documentation',
        'Adi, Pouria Hadjibagheri',
        'manual'
    ),
]


# -- Options for manual page output ---------------------------------------

# One entry per manual page. List of tuples
# (source start file, name, description, authors, manual section).
man_pages = [
    (
        master_doc,
        'djangomarkdownx',
        'Django Markdownx Documentation',
        [author],
        1
    )
]


# -- Options for Texinfo output -------------------------------------------

# Grouping the document tree into Texinfo files. List of tuples
# (source start file, target name, title, author,
#  dir menu entry, description, category)
texinfo_documents = [
    (
        master_doc,
        'DjangoMarkdownx',
        'Django Markdownx Documentation',
         author,
        'DjangoMarkdownx',
        'A comprehensive Markdown editor built for Django.',
         'Miscellaneous'
    ),
]


# -- Options for LaTeX output ---------------------------------------------

latex_elements = {
    # The paper size ('letterpaper' or 'a4paper').
    'papersize': 'a4paper',

    # The font size ('10pt', '11pt' or '12pt').
    'pointsize': '12pt',

    # Additional stuff for the LaTeX preamble.
    # 'preamble': '',

    # Latex figure (float) alignment
    # 'figure_align': 'htbp',
}


# The version info for the project you're documenting, acts as replacement for
# |version| and |release|, also used in various other places throughout the
# built documents.
#
# The short X.Y version.
doc_paths = path.split(path.dirname(__file__))[0]
init_file = path.join(doc_paths, path.pardir, 'markdownx', '__init__.py')
pattern = re_compile(r"^__version__.+[\'\"](?P<version>(.+))[\'\"][.\n]?$", MULTILINE)

with open(init_file, mode='r') as dt:
    found = pattern.search(dt.read())
    if found:
        _version = found.group('version')

        version = str.join('.', _version.split('.')[:2])

        # The full version, including alpha/beta/rc tags.
        release = str.join('.', _version.split('.')[2:])
