Commits

Andriy Kornatskyy committed 0de4ef7

Added updated mako templates to use inline preprocessor.

  • Participants
  • Parent commits da24234

Comments (0)

Files changed (6)

File demos/template/content/templates-mako/shared/master.html

                     <h1><a href="${path_for('default')}">My Site</a></h1>
                 </div>
                 <div id="logindisplay">
-                    <%include file="snippet/menu-signin.html"/>
-                    <%include file="snippet/menu-locale.html"/>
+                    <%inline file="/shared/snippet/menu-signin.html"/>
+                    <%inline file="/shared/snippet/menu-locale.html"/>
                 </div>
                 <div id="menucontainer">
-                    <%include file="snippet/menu-header.html"/>
+                    <%inline file="/shared/snippet/menu-header.html"/>
                 </div>
             </div>
             <div id="main">
                 <div id="footer">Version ${__version__}</div>
             </div>
         </div>
-        <%include file="snippet/script.html"/>
+        <%inline file="/shared/snippet/script.html"/>
         <%block name="script"/>
     </body>
 </html>

File demos/template/content/templates-mako/shared/snippet/menu-header.html

-<%page cached="True" cache_key="${(route_args.route_name in \
-('home', 'about') and route_args.route_name or '') + route_args.locale}" />
+<%block cached="True" cache_key="${route_args.locale + 'menu-header' + \
+(route_args.route_name in ('home', 'about') and route_args.route_name or '')}">
 
 <%def name="menu_item(route_name, title)">
 % if route_name == route_args.route_name:
     ${menu_item('home', 'Home')}
     ${menu_item('about', 'About')}
 </ul>
+</%block>

File demos/template/content/templates-mako/shared/snippet/menu-locale.html

-<%page cached="True" cache_time="900"
-    cache_key="${route_args.route_name}" />
+<%block cached="True" cache_time="900"
+    cache_key="${'menu-locale' + route_args.route_name}">
+
 <i><a href="${path_for(route_args.route_name, locale='en')}"
         >English</a> | <a
         href="${path_for(route_args.route_name, locale='ru')}"
         >Russian</a></i>
+</%block>

File demos/template/content/templates-mako/shared/snippet/menu-signin.html

-<%page cached="True" cache_time="900"
-    cache_key="${(principal and principal.alias or '') + route_args.locale}" />
+<%block cached="True" cache_time="900"
+    cache_key="${route_args.locale + 'menu-signin' + (principal and principal.alias or '')}">
+
 % if principal:
 Welcome <b>${principal.alias | h}</b>!
 [<a href="${path_for('signout')}">Sign out</a>]
 % else:
 [<a href="${path_for('signin')}">Sign in</a>]
 % endif
+</%block>

File demos/template/content/templates-mako/shared/snippet/script.html

-<%page cached="True" />
+<%block cached="True" cache_key="script">
+
 <script src="${path_for('static', path='js/jquery-1.7.1.min.js')}"
     type="text/javascript"></script>
 <script src="${path_for('static', path='js/core.js')}"
     type="text/javascript"></script>
 <script src="${path_for('static', path='js/autocomplete.js')}"
     type="text/javascript"></script>
+</%block>

File demos/template/src/config.py

 #template_engine = os.getenv('TEMPLATE_ENGINE', 'mako')
 template_engine = os.getenv('TEMPLATE_ENGINE', 'tenjin')
 if template_engine == 'mako':
+    from wheezy.html.ext.mako import inline_preprocessor
     from wheezy.html.ext.mako import whitespace_preprocessor
     from wheezy.html.ext.mako import widget_preprocessor
     from wheezy.web.templates import MakoTemplate
 
+    directories = ['content/templates-mako']
     render_template = MakoTemplate(
             module_directory=config.get('mako', 'module-directory'),
             filesystem_checks=config.getboolean('mako', 'filesystem-checks'),
-            directories=['content/templates-mako'],
+            directories=directories,
             cache_factory=cache_factory,
+            default_filters=[],
+            imports=['s = unicode'],
             preprocessor=[
+                inline_preprocessor(directories, enabled=True),
                 widget_preprocessor,
                 whitespace_preprocessor,
             ])