ó
mÜJ]c           @` sï   d  Z  d d l m Z m Z m Z m Z d d l Z e j 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 d Z d e f d „  ƒ  YZ d „  Z e j d d e j e j BƒZ d S(   uË   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:

i    (   t   absolute_importt   divisiont   print_functiont   unicode_literalsN(   t   basename(   t   SphinxErrori   (   t   BokehDirective(   t   JINJA_DETAILu   BokehJinjaDirectiveu   setupt   BokehJinjaDirectivec           B` s-   e  Z e Z d  Z i d „  d 6Z d „  Z RS(   i   c         C` s   t  S(   N(   t   True(   t   x(    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_jinja.pyt   <lambda>H   t    u   noindexc         C` s\  |  j  d } | j d d ƒ \ } } y t j | ƒ } Wn t k
 rY t d | ƒ n Xt | | d  ƒ } | d  k r‰ t d | ƒ n  t | j	 ƒ j
 ƒ  } t j | ƒ } | rÅ | j d ƒ } n d  } t | j	 ƒ }	 t j d | d | d t | ƒ d	 |  j j d
 t ƒ d | d  k r"d n t j | ƒ d |	 d t j d | ƒ ƒ }
 |  j |
 d ƒ S(   Ni    u   .i   u*   Unable to import Bokeh template module: %su!   Unable to find Bokeh template: %st   namet   modulet   objreprt   noindexu   noindext   docu    t   filenamet   template_textu   <bokeh-jinja>(   t	   argumentst   rsplitt	   importlibt   import_modulet   ImportErrorR   t   getattrt   Nonet   openR   t   readt   _DOCPATt   matcht   groupR   R   t   rendert   reprt   optionst   gett   Falset   textwrapt   dedentt   subt   _parse(   t   selft   template_patht   module_patht   template_nameR   t   templateR   t   mR   R   t   rst_text(    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_jinja.pyt   runK   s0     	!(   t   __name__t
   __module__R	   t   has_contentt   required_argumentst   option_specR0   (    (    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_jinja.pyR   C   s
   c         C` s   |  j  d d t ƒ d S(   u+    Required Sphinx extension setup function. u   pyu   bokeh-jinjaN(   t   add_directive_to_domainR   (   t   app(    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_jinja.pyt   setupj   s    u   \{\#(.+?)\#\}t   flags(   u   BokehJinjaDirectiveu   setup(   t   __doc__t
   __future__R    R   R   R   t   loggingt	   getLoggerR1   t   logR   t   os.pathR   t   reR%   t   sphinx.errorsR   t   bokeh_directiveR   t	   templatesR   t   __all__R   R8   t   compilet	   MULTILINEt   DOTALLR   (    (    (    s:   lib/python2.7/site-packages/bokeh/sphinxext/bokeh_jinja.pyt   <module>   s   " '	