Commits

Miki Tebeka  committed 5630418

odd/even table rows

  • Participants
  • Parent commits f250252

Comments (0)

Files changed (2)

File shortie/html.go

         <b>Your Urls</b>
         <table class="urls">
             <tr><th>URL</th><th>Created</th><th>Hits</th></tr>
-			{{ range . }}
-			<!-- FIXME: odd/even -->
-            <tr>
-                <td title="{{ .Long | html }}">
-                    <a href="{{ .Long }}">{{ .Short }}</a>
-                </td>
-                <td>{{ .Created | strftime }}</td>
-                <td>{{ .Hits }}</td>
+			{{ range $idx, $url := . }}
+				<tr class="{{ $idx | oddeven }}">
+					<td title="{{ .Long | html }}">
+						<a href="{{ .Long }}">{{ .Short }}</a>
+					</td>
+					<td>{{ .Created | strftime }}</td>
+					<td>{{ .Hits }}</td>
             </tr>
             {{ end }}
         </table>

File shortie/shortie.go

 func init() {
 	var fmap = template.FuncMap{
 		"strftime": timeFormatter,
+		"oddeven" : oddEven,
 	}
 	// homeHTML is in html.go
 	homeTemplate = template.Must(template.New("home").Funcs(fmap).Parse(homeHTML))
 	return t.Format("2006-01-02 15:04")
 }
 
+// oddEven picks class for <tr> in homeTemplate.
+func oddEven(args ...interface{}) string {
+	idx, ok := args[0].(int)
+	if !ok {
+		return "ERR"
+	}
+	if idx % 2 == 0 {
+		return "odd"
+	}
+	return "even"
+}
+
 // hitHandler is handler for updating hits task.
 func hitHandler(w http.ResponseWriter, r *http.Request) {
 	ctx := appengine.NewContext(r)