ó
Ä—5Wc           @   sž   d  Z  d d l Z d d l Z d d l Z d d l Z d d d „  ƒ  YZ d „  Z d „  Z d „  Z d „  Z	 d	 „  Z
 d
 d d
 d „ Z d d d d „ Z d S(   s¹  
Contains the function
  def concat_js( root_dir, output_js, output_cs = "", tmp_dir = ".gen" ):
  
which permits to compile and concatenate coffescript, js and css files present in root_dir or sub directories in output_...

It looks for dependencies in order to include files in the right order.

By default, if a .coffee or a .css contains "img/*.png" or "img/*.png", the string is replaced by an online representation (meaning that the files in img won't be needed)

It returns a list of dependencies if expressed as "# lib ..." or "# dep ..." in the source files. It is used to look which file is needed by which file but is not used to look for external files or to add files in the package.
iÿÿÿÿNt   Filec           B   s   e  Z d  „  Z d d „ Z RS(   c         C   s  | |  _  | |  _ d |  _ g  |  _ g  |  _ xÒ t | ƒ j ƒ  D]¾ } t j d | ƒ } | rz |  j j	 | j
 d ƒ ƒ n  t j d | ƒ } | r® |  j j	 | j
 d ƒ ƒ n  | j d ƒ r@ t j d | ƒ } | rþ |  j j	 | j
 d ƒ j ƒ  d ƒ qþ q@ q@ Wd  S(   Niÿÿÿÿs   [#/] dep[ ]*(.*)[ ]*$i   s   [#/] lib[ ]*(.*)[ ]*$s   .coffees   extends (.*)(   t   namet   baset   proft   depet   libst   filet	   readlinest   ret   searcht   appendt   groupt   endswitht   strip(   t   selfR   R   t   lt   rt   i(    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt   __init__#   s     					i    c         C   st   |  j  | k  rp | |  _  xU |  j D]G } | |  j k r= q" n  t | | ƒ } | r" | j | | d ƒ q" q" Wn  d  S(   Ni   (   R   R   R   t	   find_filet   update_prof_rec(   R   t   filesR   t   dt   c(    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyR   4   s    	(   t   __name__t
   __module__R   R   (    (    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyR    "   s   	c         C   s(   x! |  D] } | j  | k r | Sq Wd S(   Ni    (   R   (   R   R   R   (    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyR   ?   s    c         C   sÖ   g  } t  j j |  ƒ rƒ xŠ t  j |  ƒ D]T \ }  } } xB | D]: } | d d k rZ q> n  | j t |  d | | ƒ ƒ q> Wq( Wn" | j t |  t  j j |  ƒ ƒ ƒ x | D] } | j | ƒ q¬ Wt | d d „  ƒS(   Ni    t   .t   /t   keyc         S   s   |  j  S(   N(   R   (   t   x(    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt   <lambda>S   s    (	   t   ost   patht   isdirt   walkR
   R    t   basenameR   t   sorted(   t   roott   rest   dirsR   t   f(    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt	   get_filesF   s    )"c         C   sš  x“t  | ƒ j ƒ  D]} t j d | ƒ } | rå | j d ƒ } | j d ƒ } | j d ƒ } | j d ƒ } | j d ƒ }	 t j d | d | ƒ j ƒ  }
 | d	 k r² d
 } n  |  j | | d | d |
 | |	 d ƒ q n  t j d | ƒ } | r…| j d ƒ } | j d ƒ } | j d ƒ } | j d ƒ }	 t j d | d | ƒ j ƒ  }
 |  j | | d |
 | |	 d ƒ q n  |  j | ƒ q Wd  S(   Ns)   ^(.*)(["\'])(img/.*\.(png|jpg))["\'](.*)$i   i   i   i   i   s   base64 -w 0 R   t   jpgt   jpegs   data:image/s   ;base64,s   
s#   ^(.*)(["\'])(img/.*\.gif)["\'](.*)$s   data:image/gif;base64,(	   R   R   R   R	   R   R   t   popent   readt   write(   t   outt   inpt   root_dirR   R   t   begt   guit   imgt   typt   endt   b(    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt   app_codeV   s.    !	-!%c         C   s(   |  GHt  j |  ƒ r$ t j d ƒ n  d  S(   Ni   (   R   t   systemt   syst   exit(   t   cmd(    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt   exec_cmd|   s    c         C   sq   t  j |  d ƒ } xX t d t | ƒ ƒ D]A } t  j | d | !d ƒ } t j j | ƒ s( t j | ƒ q( q( Wd  S(   NR   i   i    (	   t   stringt   splitt   ranget   lent   joinR   R    t   existst   mkdir(   R   R   t   nt   newdir(    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt	   mkdir_for‚   s
    t    s   .genc         C   së  t  | ƒ s |  } n  d  } d  } t j j | ƒ sC t j | ƒ n  g  } xkt |  ƒ D]]} | r*| j j d ƒ r*| d  k rœ t	 | ƒ t
 | d ƒ } n  | d | j j d d ƒ }	 t j j |	 ƒ t k sø t j j | j ƒ t j j |	 ƒ k rt d | d | j ƒ n  t | |	 | ƒ q*n  | rƒ| j j d ƒ rƒ| d  k rjt	 | ƒ t
 | d ƒ } n  t | | j | ƒ qƒn  x- | j D]" }
 |
 | k r| j |
 ƒ qqWqV W| d  k rÏd G| GHn  | d  k rçd	 G| GHn  | S(
   Ns   .coffeet   wR   s   .jss
   coffee -o s    -b --compile s   .csss   js output ->s   css output ->(   RA   t   NoneR   R    RC   RD   R)   R   R   RG   R   R   t   replacet   Falset   getmtimeR=   R8   R   R
   (   R1   t	   output_jst	   output_cst   tmp_dirt   base_imgt   out_jst   out_csR   R   t   js_srcR   (    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt	   concat_jsŠ   s>    	
?
t   testst   gens   ../c         C   s|  xut  j |  ƒ D]d} | d d k r, q n  | j d ƒ sA q n  | j d d ƒ } | d | } | d } | d } t |  d | | d |  ƒ} | j | d ƒ t | d	 ƒ }	 d
 G| GH|	 d IJ|	 d IJ|	 d | d IJ|	 d IJxV | D]N }
 |
 j d ƒ r|	 d |
 d IJn  |
 j d ƒ rò |	 d |
 d IJqò qò W|	 d IJ|	 d | d IJ|	 d IJ|	 d IJq Wd  S(   Ni    R   s   .coffeeRH   R   s   .jss   .htmlRQ   RI   s   html ouput ->s   <html> s	     <head> s       <title>__s
   __</title>s       s   .csss        <link type="text/css" href="s   " rel="stylesheet"/>s(       <script type="text/javascript" src="s   "></script>s     <body onload="s   ()"> s
     </body> s   </html>(   R   t   listdirR   RK   RU   R
   R   (   t	   tests_dirt   base_dirt   pref_jst   pt   rat   bat   jst   htR   t   htmlR   (    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt
   make_tests¸   s4    

	




(    (   t   __doc__R   R   R:   R>   R    R   R)   R8   R=   RG   RU   Rb   (    (    (    s2   /var/www/SpinalDoc/models-manager/bin/concat_js.pyt   <module>   s   0			&		.