Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

mako template refactoring to use functions.

  • Loading branch information...
commit 6c203e48b4085cda892139b187afef25ae7102ed 1 parent 31fe1fc
eduardo naufel schettino authored December 27, 2012
26  nikola/data/themes/default/templates/index.tmpl
... ...
@@ -1,4 +1,5 @@
1 1
 ## -*- coding: utf-8 -*-
  2
+<%namespace name="helper" file="index_helper.tmpl"/>
2 3
 <%inherit file="base.tmpl"/>
3 4
 <%block name="content">
4 5
     % for post in posts:
@@ -9,28 +10,9 @@
9 10
         </small></h1>
10 11
         <hr>
11 12
         ${post.text(lang, index_teasers)}
12  
-        <p>
13  
-        %if disqus_forum:
14  
-            <a href="${post.permalink()}#disqus_thread">Comments</a>
15  
-        %endif
  13
+        ${helper.html_disqus_link(post)}
16 14
         </div>
17 15
     % endfor
18  
-    <div>
19  
-<ul class="pager">
20  
-  %if prevlink:
21  
-    <li class="previous">
22  
-        <a href="${prevlink}">&larr; ${messages[lang]["Newer posts"]}</a>
23  
-    </li>
24  
-  %endif
25  
-  %if nextlink:
26  
-    <li class="next">
27  
-        <a href="${nextlink}">${messages[lang]["Older posts"]} &rarr;</a>
28  
-    </li>
29  
-  %endif
30  
-</ul>
31  
-
32  
-    </div>
33  
-    %if disqus_forum:
34  
-       <script type="text/javascript">var disqus_shortname="${disqus_forum}";(function(){var a=document.createElement("script");a.async=true;a.type="text/javascript";a.src="http://"+disqus_shortname+".disqus.com/count.js";(document.getElementsByTagName("HEAD")[0]||document.getElementsByTagName("BODY")[0]).appendChild(a)}());</script>
35  
-    %endif
  16
+    ${helper.html_pager()}
  17
+    ${helper.html_disqus_script()}
36 18
 </%block>
31  nikola/data/themes/default/templates/index_helper.tmpl
... ...
@@ -0,0 +1,31 @@
  1
+<%def name="html_pager()">
  2
+<div>
  3
+<ul class="pager">
  4
+  %if prevlink:
  5
+    <li class="previous">
  6
+        <a href="${prevlink}">&larr; ${messages[lang]["Newer posts"]}</a>
  7
+    </li>
  8
+  %endif
  9
+  %if nextlink:
  10
+    <li class="next">
  11
+        <a href="${nextlink}">${messages[lang]["Older posts"]} &rarr;</a>
  12
+    </li>
  13
+  %endif
  14
+</ul>
  15
+</div>
  16
+</%def>
  17
+
  18
+
  19
+<%def name="html_disqus_link(post)">
  20
+    <p>
  21
+    %if disqus_forum:
  22
+        <a href="${post.permalink()}#disqus_thread">Comments</a>
  23
+    %endif
  24
+</%def>
  25
+
  26
+
  27
+<%def name="html_disqus_script()">
  28
+    %if disqus_forum:
  29
+       <script type="text/javascript">var disqus_shortname="${disqus_forum}";(function(){var a=document.createElement("script");a.async=true;a.type="text/javascript";a.src="http://"+disqus_shortname+".disqus.com/count.js";(document.getElementsByTagName("HEAD")[0]||document.getElementsByTagName("BODY")[0]).appendChild(a)}());</script>
  30
+    %endif
  31
+</%def>
28  nikola/data/themes/default/templates/post.tmpl
@@ -3,30 +3,14 @@
3 3
 <%inherit file="base.tmpl"/>
4 4
 <%block name="content">
5 5
     <div class="postbox">
6  
-    <h1><a href='${permalink}'>${title}</a></h1>
7  
-    % if link:
8  
-            <p><a href='${link}'>${messages[lang]["Original site"]}</a></p>
9  
-    % endif
  6
+    ${helper.html_title()}
10 7
     <hr>
11 8
     <small>
12  
-        ${messages[lang]["Posted"]}: ${post.date.strftime(date_format)}&nbsp;&nbsp;|&nbsp;&nbsp;
13  
-
14  
-        %if len(translations) > 1:
15  
-            %for langname in translations.keys():
16  
-                %if langname != lang:
17  
-                    <a href="${post.permalink(langname)}">${messages[langname][u"Read in English"]}</a>
18  
-                    &nbsp;&nbsp;|&nbsp;&nbsp;
19  
-                %endif
20  
-            %endfor
21  
-        %endif
22  
-
23  
-        <a href="${post.pagenames[lang]+".txt"}">${messages[lang]["Source"]}</a>
24  
-        %if post.tags:
25  
-            &nbsp;&nbsp;|&nbsp;&nbsp;${messages[lang]["More posts about"]}
26  
-            %for tag in post.tags:
27  
-                <a href="${_link("tag", tag, lang)}"><span class="badge badge-info">${tag}</span></a>
28  
-            %endfor
29  
-        %endif
  9
+        ${messages[lang]["Posted"]}: ${post.date.strftime(date_format)}
  10
+        ${helper.html_translations()}
  11
+        &nbsp;&nbsp;|&nbsp;&nbsp;
  12
+        <a href="${post.pagenames[lang]+'.txt'}">${messages[lang]["Source"]}</a>
  13
+        ${helper.html_tags()}
30 14
     </small>
31 15
     <hr>
32 16
     ${post.text(lang)}
30  nikola/data/themes/default/templates/post_helper.tmpl
... ...
@@ -1,3 +1,32 @@
  1
+<%def name="html_title()">
  2
+    <h1>${title}</h1>
  3
+    % if link:
  4
+            <p><a href='${link}'>${messages[lang]["Original site"]}</a></p>
  5
+    % endif
  6
+</%def>
  7
+
  8
+
  9
+<%def name="html_translations()">
  10
+    %if len(translations) > 1:
  11
+        %for langname in translations.keys():
  12
+            %if langname != lang:
  13
+                &nbsp;&nbsp;|&nbsp;&nbsp;
  14
+                <a href="${post.permalink(langname)}">${messages[langname]["Read in English"]}</a>
  15
+            %endif
  16
+        %endfor
  17
+    %endif
  18
+</%def>
  19
+
  20
+
  21
+<%def name="html_tags()">
  22
+    %if post.tags:
  23
+        &nbsp;&nbsp;|&nbsp;&nbsp;${messages[lang]["More posts about"]}
  24
+        %for tag in post.tags:
  25
+            <a href="${_link('tag', tag, lang)}"><span class="badge badge-info">${tag}</span></a>
  26
+        %endfor
  27
+    %endif
  28
+</%def>
  29
+
1 30
 
2 31
 <%def name="html_disqus()">
3 32
     %if disqus_forum:
@@ -8,6 +37,7 @@
8 37
     %endif
9 38
 </%def>
10 39
 
  40
+
11 41
 <%def name="html_pager()">
12 42
     <ul class="pager">
13 43
     %if post.prev_post:
22  nikola/data/themes/site/templates/post.tmpl
@@ -3,28 +3,12 @@
3 3
 <%inherit file="base.tmpl"/>
4 4
 <%block name="content">
5 5
     <div class="postbox">
6  
-    <h1>${title}</h1>
7  
-    % if link:
8  
-            <p><a href='${link}'>${messages[lang]["Original site"]}</a></p>
9  
-    % endif
  6
+    ${helper.html_title()}
10 7
     <hr>
11 8
     <small>
12 9
         ${messages[lang]["Posted"]}: ${post.date.strftime(date_format)}
13  
-
14  
-        %if len(translations) > 1:
15  
-            %for langname in translations.keys():
16  
-                %if langname != lang:
17  
-                    &nbsp;&nbsp;|&nbsp;&nbsp;
18  
-                    <a href="${post.permalink(langname)}">${messages[langname]["Read in English"]}</a>
19  
-                %endif
20  
-            %endfor
21  
-        %endif
22  
-        %if post.tags:
23  
-            &nbsp;&nbsp;|&nbsp;&nbsp;${messages[lang]["More posts about"]}
24  
-            %for tag in post.tags:
25  
-                <a href="${_link("tag", tag, lang)}"><span class="badge badge-info">${tag}</span></a>
26  
-            %endfor
27  
-        %endif
  10
+        ${helper.html_translations()}
  11
+        ${helper.html_tags()}
28 12
     </small>
29 13
     <hr>
30 14
     ${post.text(lang)}

0 notes on commit 6c203e4

Please sign in to comment.
Something went wrong with that request. Please try again.