B
    @\z                 @   s   d Z ddlmZmZmZmZ ddlZeeZ	ddl
mZ ddlmZ ddlmZmZmZmZm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mZ ddlmZm Z m!Z! dZ"dd Z#di fddZ$dddZ%dS )z: Generate various HTML elements from Bokeh render items.

    )absolute_importdivisionprint_functionunicode_literalsN)string_types   )serialize_json)_envDOC_JSFILEMACROSPLOT_DIV)DEFAULT_TITLE)settings)bundle_all_models)make_id)encode_utf8escape   )wrap_in_onloadwrap_in_safelywrap_in_script_tag)div_for_render_itemhtml_page_for_render_itemsscript_for_render_itemsc             C   s   t j| tdS )z Render an HTML div for a Bokeh render item.

    Args:
        item (RenderItem):
            the item to create a div for

    Returns:
        str

    )docmacros)r   renderr   )item r   3lib/python3.7/site-packages/bokeh/embed/elements.pyr   8   s    r   c             C   s   |dkrt }| \}}t }tt|dd}	t|	d|}	t }
|
t||7 }
t|
}
| }|t	||||	|
 |t
td t|dkr|d d |d	< |d	 j|d
< ddd |D |d< |dkrt
}nt|trtd| }||}t|S )a   Render an HTML page from a template and Bokeh render items.

    Args:
        bundle (tuple):
            a tuple containing (bokehjs, bokehcss)

        docs_json (JSON-like):
            Serialized Bokeh Documen t

        render_items (RenderItems)
            Specific items to render from the document and where

        title (str or None)
            A title for the HTML page. If None, DEFAULT_TITLE is used

        template (str or Template or None, optional) :
            A Template to be used for the HTML page. If None, FILE is used.

        template_variables (dict, optional):
            Any Additional variables to pass to the template

    Returns:
        str

    NF)quotezapplication/json)titlebokeh_js	bokeh_cssZplot_scriptdocsbaser   r   r%   r   r   roots
c             s   s   | ]}t |V  qd S )N)r   ).0r   r   r   r    	<genexpr>}   s    z-html_page_for_render_items.<locals>.<genexpr>Zplot_divz{% extends base %}
)r   r   r   r   r   r   r   copyupdatedictr   r   lenr'   join
isinstancer   r	   Zfrom_stringr   r   )Zbundle	docs_jsonrender_itemsr"   templateZtemplate_variablesr#   r$   Zjson_idZjsonZscriptcontextZhtmlr   r   r    r   E   s8    


r   c             C   s~   t | trd|  }n0t| dd}t|dd}|dd}d| d }tj|td	d
 |D dd||d}tjsvt	|}t
|S )z

    z)document.getElementById('%s').textContentF)Zpretty)')r!   \z\\r5   c             S   s   g | ]}|  qS r   )Zto_json)r)   r   r   r   r    
<listcomp>   s    z+script_for_render_items.<locals>.<listcomp>)r1   r2   app_pathabsolute_url)r0   r   r   r   replacer
   r   r   Zdevr   r   )Zdocs_json_or_idr2   r8   r9   r1   Zjsr   r   r    r      s    

r   )NN)&__doc__Z
__future__r   r   r   r   ZloggingZ	getLogger__name__logZsixr   Zcore.json_encoderr   Zcore.templatesr	   r
   r   r   r   Zdocument.documentr   r   Zutil.compilerr   Zutil.serializationr   Zutil.stringr   r   Zwrappersr   r   r   __all__r   r   r   r   r   r   r    <module>	   s    
	B