[Piglit] [PATCH 1/7] templates/index.mako: Convert to using functions

Dylan Baker baker.dylan.c at gmail.com
Thu Oct 17 15:09:37 CEST 2013


This is groundwork for moving more of the logic into mako and killing
the HTMLIndex class in summary.
---
 templates/index.mako | 77 ++++++++++++++++++++++++++++++++--------------------
 1 file changed, 47 insertions(+), 30 deletions(-)

diff --git a/templates/index.mako b/templates/index.mako
index e959a27..fec9672 100644
--- a/templates/index.mako
+++ b/templates/index.mako
@@ -1,3 +1,44 @@
+<%def name="new_row()">
+  <tr>
+</%def>
+
+<%def name="end_row()">
+  </tr>
+</%def>
+
+<%def name="group_row(hclass, indent, text)">
+  <td>
+    <div class="${hclass}" style="margin-left: ${indent}em">
+      <b>${text}</b>
+    </div>
+  </td>
+</%def>
+
+<%def name="test_row(hclass, indent, text)">
+  <td>
+    <div class="${hclass}" style="margin-left: ${indent}em">
+      ${text}
+    </div>
+  </td>
+</%def>
+
+<%def name="group_result(hclass, text)">
+  <td class="${hclass}">
+    <b>${text}</b>
+  </td>
+</%def>
+
+<%def name="test_result(hclass, href, text)">
+  <td class="${hclass}">
+  ## If the result is in the excluded results page list from
+  ## argparse, just print the text, otherwise add the link
+  % if hclass not in exclude:
+    <a href="${href}">${text}</a>
+  % else:
+    ${text}
+  % endif
+</%def>
+
 <?xml version="1.0" encoding="UTF-8"?>
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
@@ -37,41 +78,17 @@
       </colgroup>
       % for line in results:
         % if line['type'] == "newRow":
-        <tr>
+          ${new_row()}
         % elif line['type'] == "endRow":
-        </tr>
+          ${end_row()}
         % elif line['type'] == "groupRow":
-          <td>
-            <div class="${line['class']}" style="margin-left: ${line['indent']}em">
-              <b>${line['text']}</b>
-            </div>
-          </td>
+          ${group_row(line['class'], line['indent'], line['text'])}
         % elif line['type'] == "testRow":
-          <td>
-            <div class="${line['class']}" style="margin-left: ${line['indent']}em">
-              ${line['text']}
-            </div>
-          </td>
+          ${test_row(line['class'], line['indent'], line['text'])}
         % elif line['type'] == "groupResult":
-          <td class="${line['class']}">
-            <b>${line['text']}</b>
-          </td>
+          ${group_result(line['class'], line['text'])}
         % elif line['type'] == "testResult":
-          <td class="${line['class']}">
-          ## If the result is in the excluded results page list from
-          ## argparse, just print the text, otherwise add the link
-          % if line['class'] not in exclude:
-            <a href="${line['href']}">
-              ${line['text']}
-            </a>
-          % else:
-            ${line['text']}
-          % endif
-          </td>
-        % elif line['type'] == "subtestResult":
-          <td class="${line['class']}">
-            ${line['text']}
-          </td>
+          ${test_result(line['class'], line['href'], line['text'])}
         % elif line['type'] == "other":
           ${line['text']}
         % endif
-- 
1.8.1.5



More information about the Piglit mailing list