U
    /e|                     @  s   d Z ddlmZ ddlZeeZddlZddlZddl	Z	ddl
mZ ddlmZ ddlmZ ddlmZ dd	lmZ d
ZG dd deZdd ZejdejejB dZdS )a   Automatically document Bokeh Jinja2 templates.

This directive takes the module path to an attribute name that defines a Jinja2
template:

.. code-block:: rest

    .. bokeh-jinja:: bokeh.core.templates.FILE

Any template parameters will be displayed and the template source code will
be rendered in a collapsible code block. For example, the usage above will
generate the following output:

    .. bokeh-jinja:: bokeh.core.templates.FILE
        :noindex:

    )annotationsN)basename)SphinxError   )PARALLEL_SAFE)BokehDirective)JINJA_DETAIL)BokehJinjaDirectivesetupc                   @  s(   e Zd ZdZdZddd iZdd ZdS )	r	   Tr   noindexc                 C  s   dS )NT )xr   r   ?/tmp/pip-unpacked-wheel-f5fndrjf/bokeh/sphinxext/bokeh_jinja.py<lambda>K       zBokehJinjaDirective.<lambda>c                 C  s   | j d }|dd\}}zt|}W n" tk
rJ   td|  Y nX t||d }|d krntd|  t|j	 }t
|}|r|dnd }t|j}	tj||t|| jdd|d krdnt||	t
d|d	}
| |
d
S )Nr   .r   z(Unable to import Bokeh template module: zUnable to find Bokeh template: r   F )namemoduleZobjreprr   docfilenametemplate_textz<bokeh-jinja>)	argumentsrsplit	importlibimport_moduleImportErrorr   getattropenr   read_DOCPATmatchgroupr   r   renderreproptionsgettextwrapdedentsubparse)selfZtemplate_pathmodule_pathZtemplate_namer   templater   mr   r   Zrst_textr   r   r   runN   s.    




zBokehJinjaDirective.runN)__name__
__module____qualname__Zhas_contentZrequired_argumentsZoption_specr/   r   r   r   r   r	   F   s    r	   c                 C  s   |  ddt tS )z+ Required Sphinx extension setup function. pyzbokeh-jinja)Zadd_directive_to_domainr	   r   )Zappr   r   r   r
   m   s    r
   z\{\#(.+?)\#\})flags)__doc__
__future__r   logging	getLoggerr0   logr   rer'   os.pathr   Zsphinx.errorsr   r   r   Zbokeh_directiver   Z	templatesr   __all__r	   r
   compile	MULTILINEDOTALLr    r   r   r   r   <module>   s   
'
