î
2!ìVQ  ã               @   sc   d  d l  m Z d  d l m Z d  d l m Z d  d l m Z m Z Gd d „  d e e ƒ Z	 d S)é    )Únodes)Ú	Extension)ÚTemplateSyntaxError)ÚOUTPUT_FILEÚCompressorMixinc               @   s[   e  Z d  Z e d g ƒ Z d d „  Z d d „  Z d d „  Z d d	 „  Z d
 d „  Z	 d S)ÚCompressorExtensionÚcompressc             C   sQ  t  | j ƒ j } | j ƒ  } t | t j ƒ rE t j | j ƒ } n  | g } | d j	 |  j
 k rŒ t d d j |  j
 j ƒ  ƒ | ƒ ‚ n  | j j d ƒ rá | j ƒ  } t | t j ƒ r÷ t j | j ƒ } | j | ƒ q÷ n | j t j d ƒ ƒ | j d g d d ƒ} | j j d	 | j	 ƒ t j |  j d
 | ƒ g  g  | ƒ j | ƒ S)Nr   zcompress kind may be one of: %sz, ÚcommaÚfilezname:endcompressZdrop_needleTzname:Ú_compress_normal)ÚnextÚstreamÚlinenoZparse_expressionÚ
isinstancer   ÚNameZConstÚnameÚvalueZcompressorsr   ÚjoinÚkeysZskip_ifÚappendZparse_statementsZ	CallBlockZcall_methodZ
set_lineno)ÚselfÚparserr   ZkindargÚargsZmodeargÚbody© r   úI/tmp/pip-build-0sboevxh/django-compressor/compressor/contrib/jinja2ext.pyÚparse   s&    	zCompressorExtension.parsec             C   s   |  j  | | | d ƒ S)NT)Ú	_compress)r   ÚkindÚmodeÚcallerr   r   r   Ú_compress_forced(   s    z$CompressorExtension._compress_forcedc             C   s   |  j  | | | d ƒ S)NF)r   )r   r   r   r    r   r   r   r   +   s    z$CompressorExtension._compress_normalc             C   s;   | p	 t  } | ƒ  } i | d 6} |  j | | | d | ƒS)NÚoriginal_contentÚforced)r   Zrender_compressed)r   r   r   r    r#   r"   Úcontextr   r   r   r   .   s
    	
zCompressorExtension._compressc             C   s   | d S)Nr"   r   )r   r$   r   r   r   Úget_original_content6   s    z(CompressorExtension.get_original_contentN)
Ú__name__Ú
__module__Ú__qualname__ÚsetÚtagsr   r!   r   r   r%   r   r   r   r   r      s   r   N)
Zjinja2r   Z
jinja2.extr   Zjinja2.exceptionsr   Z compressor.templatetags.compressr   r   r   r   r   r   r   Ú<module>   s   