1. Julian Rosse
  2. Sleepy

Source

Sleepy / sleepy / templates / sleepy / util.mako

<%def
        name="ga( code,
                  domain=None )">
    <script>
      var _gaq = _gaq || [];
      _gaq.push( [ '_setAccount',
                   '${ code }' ] );
      % if domain:
        _gaq.push( [ '_setDomainName',
                     '${ domain }' ] );
      % endif
      _gaq.push( [ '_trackPageview' ] );
      ( function() {
        var ga = document
                  .createElement( 'script' );
        ga.type = 'text/javascript';
        ga.async = true;
        ga.src = ( 'https:' == document
                                .location
                                .protocol ?
                    'https://ssl' :
                    'http://www' )
                  + '.google-analytics.com/ga.js';
        var s = document
                 .getElementsByTagName( 'script' )
                 [ 0 ];
        s.parentNode
         .insertBefore( ga,
                        s );
      } )();
    </script>
</%def>
<%def
        cached="True"
        cache_key="sleepy.versioned_css.${ name }"
        name="css( name='' )">
    <%
        if not name:
            name = c.page.name
    %>
    % if name == "jquery.mobile":
        <link
                rel="stylesheet"
                href="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.css"
                type="text/css" />
    % else:
        <%!
            from glob import glob
            from os import listdir
            from os.path import join
            import re
        %>
        % if config.get( "sleepy.versioned_css" ):
            <%
                _filename_re = re.compile( """
                                            . *
                                           """
                                            + name
                                            + """
                                               -
                                               (
                                                \d + )
                                               \.css
                                              """,
                                           re.X )
                matches = [ _filename_re
                             .match( stylesheet )
                             .group( 1 )
                             for stylesheet
                             in listdir( join( config[ "pylons.paths" ]
                                                     [ "static_files" ],
                                                "css" ))
                             if _filename_re.match( stylesheet ) ]
                if len( matches ):
                    max_version = max( matches )
                    name = ( name
                              + "-"
                              + str( max_version ))
            %>
        % endif
        <link
                rel="stylesheet"
                href="/css/${ name }.css"
                type="text/css" />
    % endif
</%def>
<%def
        name="typekit( kit )">
    <script>
        TypekitConfig = {
            kitId: '${ kit }',
            scriptTimeout: 3000
        };
        (function() {
            $('html').addClass('wf-loading');
            var t = setTimeout(function() {
                $('html').removeClass('wf-loading').addClass('wf-inactive');
                }, TypekitConfig.scriptTimeout);
            $.ajax({
                url: '//use.typekit.com/' + TypekitConfig.kitId + '.js',
                dataType: 'script',
                cache: true,
                success: function() {
                    clearTimeout(t);
                    try { Typekit.load(TypekitConfig); } catch (e) {}
                }
            });
        })();
    </script>
</%def>
<%def
        name="script( name=None )">
    % if name == "jquery":
        % if debug:
            <script
                    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.js"></script>
        % else:
            <script
                    src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script>
        % endif
    % elif name == "jquery-ui":
        % if debug:
            <script
                    src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.js"></script>
        % else:
            <script
                    src="https://ajax.googleapis.com/ajax/libs/jqueryui/1.8.18/jquery-ui.min.js"></script>
        % endif
    % elif name == "jquery.mobile":
        % if debug:
            <script
                    src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.js"
                    type="text/javascript"></script>
        % else:
            <script
                    src="http://code.jquery.com/mobile/1.0.1/jquery.mobile-1.0.1.min.js"
                    type="text/javascript"></script>
        % endif
    % elif name and 0 < name.find( "://" ) < 6:
        <script
                src="${ name }"
                type="text/javascript"></script>
    % else:
        <script
                src="/js/${ name or c.page.name }.js"
                type="text/javascript"></script>
    % endif
</%def>
<%def
        name="lorem_ipsum( count=1 )">
    % for num in range( count ):
            Lorem ipsum dolor sit amet, consectetur adipisicing
            elit, sed do eiusmod tempor incididunt ut labore et
            dolore magna aliqua. Ut enim ad minim veniam, quis
            nostrud exercitation ullamco laboris nisi ut aliquip
            ex ea commodo consequat. Duis aute irure dolor in
            reprehenderit in voluptate velit esse cillum dolore
            eu fugiat nulla pariatur. Excepteur sint occaecat
            cupidatat non proident, sunt in culpa qui officia
            deserunt mollit anim id est laborum.
    % endfor
</%def>
<%def
        name="ago( entry,
                   name,
                   link )">
    <a
            href="${ link }"
            class="feedLink"><img
                class="${ name }Icon icon"
                src="/images/${ name }_icon.png" /><span
                class="feedDate">Posted ${ entry.ago }</span></a>
</%def>
<%def
        name="favicon( image )">
    <link
            rel="shortcut icon"
            href="/images/${ image }" />
</%def>
<%def
        name="span_first( text )">
    <%
        words = text.split()
    %>
    <span
            class="first">${ words[ 0 ] }</span>
    <span
            class="rest">${ " ".join( words[ 1 : ] ) }</span>
</%def>