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

The ``bokeh-jinja`` directive generates useful type information
for the property attribute, including cross links to the relevant
property types. Additionally, any per-attribute docstrings are
also displayed.

This directive takes the path to an attribute on a Bokeh
model class as an argument::

    .. bokeh-jinja:: bokeh.core.templates.FOO


    )absolute_importdivisionprint_functionunicode_literalsN)basename)SphinxError   )BokehDirective)JINJA_DETAILz\{\#(.+?)\#\})flags)BokehJinjaDirectivesetupc               @   s   e Zd ZdZdZdd ZdS )r   Tr   c          
   C   s   | j d }|dd\}}yt|}W n  tk
rH   td|  Y nX t||d }|d krjtd|  t|j	 }t
|}|r|d}nd }t|j}	tj||t||d krdnt||	t
d|d}
| |
dS )	Nr   .r   z*Unable to import Bokeh template module: %sz!Unable to find Bokeh template: %s )namemoduleZobjreprdocfilenametemplate_textz<bokeh-jinja>)Z	argumentsrsplit	importlibimport_moduleImportErrorr   getattropenr   readDOCPATmatchgroupr   r
   Zrenderreprtextwrapdedentsub_parse)selfZtemplate_pathZmodule_pathZtemplate_namer   templater   mr   r   Zrst_text r'   :lib/python3.7/site-packages/bokeh/sphinxext/bokeh_jinja.pyrunG   s.    

 
zBokehJinjaDirective.runN)__name__
__module____qualname__Zhas_contentZrequired_argumentsr)   r'   r'   r'   r(   r   B   s   r   c             C   s   |  ddt d S )Npyzbokeh-jinja)Zadd_directive_to_domainr   )Zappr'   r'   r(   r   f   s    r   )__doc__Z
__future__r   r   r   r   ZloggingZ	getLoggerr*   logr   os.pathr   rer    Zsphinx.errorsr   Zbokeh_directiver	   Z	templatesr
   compile	MULTILINEDOTALLr   __all__r   r   r'   r'   r'   r(   <module>   s   
$