chiark / gitweb /
new @argq expansion; more template fiddling
authorRichard Kettlewell <rjk@greenend.org.uk>
Fri, 16 May 2008 18:32:24 +0000 (19:32 +0100)
committerRichard Kettlewell <rjk@greenend.org.uk>
Fri, 16 May 2008 18:32:24 +0000 (19:32 +0100)
server/macros-disorder.c
templates/choose.tmpl

index 92fcb75..80eb476 100644 (file)
@@ -79,8 +79,8 @@ static int exp_url(int attribute((unused)) nargs,
 
 /* @arg{NAME}
  *
- * Expands to the CGI argument NAME, or the empty string if there is
- * no such argument.
+ * Expands to the UNQUOTED form of CGI argument NAME, or the empty string if
+ * there is no such argument.  Use @argq for a quick way to quote the argument.
  */
 static int exp_arg(int attribute((unused)) nargs,
                   char **args,
@@ -89,8 +89,24 @@ static int exp_arg(int attribute((unused)) nargs,
   const char *s = cgi_get(args[0]);
 
   if(s)
-    return sink_writes(output,
-                       cgi_sgmlquote(s)) < 0 ? -1 : 0;
+    return sink_writes(output, s) < 0 ? -1 : 0;
+  else
+    return 0;
+}
+
+/* @argq{NAME}
+ *
+ * Expands to the (quoted) form of CGI argument NAME, or the empty string if
+ * there is no such argument.  Use @arg for the unquoted argument.
+ */
+static int exp_argq(int attribute((unused)) nargs,
+                    char **args,
+                    struct sink *output,
+                    void attribute((unused)) *u) {
+  const char *s = cgi_get(args[0]);
+
+  if(s)
+    return sink_writes(output, cgi_sgmlquote(s)) < 0 ? -1 : 0;
   else
     return 0;
 }
@@ -651,7 +667,7 @@ static int exp_resolve(int attribute((unused)) nargs,
 static int exp_paused(int attribute((unused)) nargs,
                       char attribute((unused)) **args,
                       struct sink *output,
-                      void attribute((unused)) *u) {
+                     void attribute((unused)) *u) {
   dcgi_lookup(DCGI_PLAYING);
   return mx_bool_result(output, (dcgi_playing
                                  && dcgi_playing->state == playing_paused));
@@ -836,7 +852,8 @@ static int exp__files_dirs(int nargs,
     e[n].display = trackname_transform(type, tracks[n], "display");
   }
   qsort(e, ntracks, sizeof (struct entry), compare_entry);
-  /* Expand the subsiduary templates */
+  /* Expand the subsiduary templates.  We chuck in @sort and @display because
+   * it is particularly easy to do so. */
   for(n = 0; n < ntracks; ++n)
     if((rc = mx_expand(mx_rewritel(m,
                                    "index", make_index(n),
@@ -844,6 +861,8 @@ static int exp__files_dirs(int nargs,
                                    "track", tracks[n],
                                    "first", n == 0 ? "true" : "false",
                                    "last", n + 1 == ntracks ? "false" : "true",
+                                   "sort", e[n].sort,
+                                   "display", e[n].display,
                                    (char *)0),
                        output, u)))
       return rc;
@@ -860,6 +879,8 @@ static int exp__files_dirs(int nargs,
  * - @parity to "even" or "odd" alternately
  * - @first to "true" on the first track and "false" otherwise
  * - @last to "true" on the last track and "false" otherwise
+ * - @sort to the sort key for this track
+ * - @display to the UNQUOTED display string for this track
  *
  * RE is optional and if present is the regexp to match against.
  */
@@ -879,6 +900,8 @@ static int exp_tracks(int nargs,
  * - @parity to "even" or "odd" alternately
  * - @first to "true" on the first directory and "false" otherwise
  * - @last to "true" on the last directory and "false" otherwise
+ * - @sort to the sort key for this directory
+ * - @display to the UNQUOTED display string for this directory
  *
  * RE is optional and if present is the regexp to match against.
  */
@@ -892,6 +915,7 @@ static int exp_dirs(int nargs,
 /** @brief Register DisOrder-specific expansions */
 void dcgi_expansions(void) {
   mx_register("arg", 1, 1, exp_arg);
+  mx_register("argq", 1, 1, exp_argq);
   mx_register("enabled", 0, 0, exp_enabled);
   mx_register("error", 0, 0, exp_error);
   mx_register("image", 1, 1, exp_image);
index 10ccf22..0b08491 100644 (file)
@@ -26,124 +26,122 @@ USA
 @stdmenu{choose}
    <h1>@label:choose.title@</h1>
   
-  @#{always have the first-letter bar, if choosealpha enabled}@
-  @if{@eq{@label:sidebar.choosewhich@}{choosealpha}@}{
-
+  @if{@eq{@label{sidebar.choosewhich}}{choosealpha}}
+     {
    <p class=choosealpha>
     <a title="Directories starting with 'a'"
-    href="@url@?action=choose&#38;regexp=^(the )?a">A</a> |
+    href="@url?action=choose&#38;regexp=^(the )?a">A</a> |
     <a title="Directories starting with 'b'"
-    href="@url@?action=choose&#38;regexp=^(the )?b">B</a> |
+    href="@url?action=choose&#38;regexp=^(the )?b">B</a> |
     <a title="Directories starting with 'c'"
-    href="@url@?action=choose&#38;regexp=^(the )?c">C</a> |
+    href="@url?action=choose&#38;regexp=^(the )?c">C</a> |
     <a title="Directories starting with 'd'"
-    href="@url@?action=choose&#38;regexp=^(the )?d">D</a> |
+    href="@url?action=choose&#38;regexp=^(the )?d">D</a> |
     <a title="Directories starting with 'e'"
-    href="@url@?action=choose&#38;regexp=^(the )?e">E</a> |
+    href="@url?action=choose&#38;regexp=^(the )?e">E</a> |
     <a title="Directories starting with 'f'"
-    href="@url@?action=choose&#38;regexp=^(the )?f">F</a> |
+    href="@url?action=choose&#38;regexp=^(the )?f">F</a> |
     <a title="Directories starting with 'g'"
-    href="@url@?action=choose&#38;regexp=^(the )?g">G</a> |
+    href="@url?action=choose&#38;regexp=^(the )?g">G</a> |
     <a title="Directories starting with 'h'"
-    href="@url@?action=choose&#38;regexp=^(the )?h">H</a> |
+    href="@url?action=choose&#38;regexp=^(the )?h">H</a> |
     <a title="Directories starting with 'i'"
-    href="@url@?action=choose&#38;regexp=^(the )?i">I</a> |
+    href="@url?action=choose&#38;regexp=^(the )?i">I</a> |
     <a title="Directories starting with 'j'"
-    href="@url@?action=choose&#38;regexp=^(the )?j">J</a> |
+    href="@url?action=choose&#38;regexp=^(the )?j">J</a> |
     <a title="Directories starting with 'k'"
-    href="@url@?action=choose&#38;regexp=^(the )?k">K</a> |
+    href="@url?action=choose&#38;regexp=^(the )?k">K</a> |
     <a title="Directories starting with 'l'"
-    href="@url@?action=choose&#38;regexp=^(the )?l">L</a> |
+    href="@url?action=choose&#38;regexp=^(the )?l">L</a> |
     <a title="Directories starting with 'm'"
-    href="@url@?action=choose&#38;regexp=^(the )?m">M</a> |
+    href="@url?action=choose&#38;regexp=^(the )?m">M</a> |
     <a title="Directories starting with 'n'"
-    href="@url@?action=choose&#38;regexp=^(the )?n">N</a> |
+    href="@url?action=choose&#38;regexp=^(the )?n">N</a> |
     <a title="Directories starting with 'o'"
-    href="@url@?action=choose&#38;regexp=^(the )?o">O</a> |
+    href="@url?action=choose&#38;regexp=^(the )?o">O</a> |
     <a title="Directories starting with 'p'"
-    href="@url@?action=choose&#38;regexp=^(the )?p">P</a> |
+    href="@url?action=choose&#38;regexp=^(the )?p">P</a> |
     <a title="Directories starting with 'q'"
-    href="@url@?action=choose&#38;regexp=^(the )?q">Q</a> |
+    href="@url?action=choose&#38;regexp=^(the )?q">Q</a> |
     <a title="Directories starting with 'r'"
-    href="@url@?action=choose&#38;regexp=^(the )?r">R</a> |
+    href="@url?action=choose&#38;regexp=^(the )?r">R</a> |
     <a title="Directories starting with 's'"
-    href="@url@?action=choose&#38;regexp=^(the )?s">S</a> |
+    href="@url?action=choose&#38;regexp=^(the )?s">S</a> |
     <a title="Directories starting with 't'"
-    href="@url@?action=choose&#38;regexp=^(?!the [^t])t">T</a> |
+    href="@url?action=choose&#38;regexp=^(?!the [^t])t">T</a> |
     <a title="Directories starting with 'u'"
-    href="@url@?action=choose&#38;regexp=^(the )?u">U</a> |
+    href="@url?action=choose&#38;regexp=^(the )?u">U</a> |
     <a title="Directories starting with 'v'"
-    href="@url@?action=choose&#38;regexp=^(the )?v">V</a> |
+    href="@url?action=choose&#38;regexp=^(the )?v">V</a> |
     <a title="Directories starting with 'w'"
-    href="@url@?action=choose&#38;regexp=^(the )?w">W</a> |
+    href="@url?action=choose&#38;regexp=^(the )?w">W</a> |
     <a title="Directories starting with 'x'"
-    href="@url@?action=choose&#38;regexp=^(the )?x">X</a> |
+    href="@url?action=choose&#38;regexp=^(the )?x">X</a> |
     <a title="Directories starting with 'y'"
-    href="@url@?action=choose&#38;regexp=^(the )?y">Y</a> |
+    href="@url?action=choose&#38;regexp=^(the )?y">Y</a> |
     <a title="Directories starting with 'z'"
-    href="@url@?action=choose&#38;regexp=^(the )?z">Z</a> |
+    href="@url?action=choose&#38;regexp=^(the )?z">Z</a> |
     <a title="Directories starting with anything else"
-    href="@url@?action=choose&#38;regexp=^[^a-z]">*</a>
+    href="@url?action=choose&#38;regexp=^[^a-z]">*</a>
    </p>
-  }@
+}
+
+@# TODO navigation...
+
+   <div class=directories>
+    <div class=filesdirectories>
+     @dirs{@arg{dir}}{@arg{re}}{
+      <p class=entry>
+       <a href="@url?action=choose&#38;dir=@urlquote{@track}">
+        <img class=button src="@image{directory}" alt="">
+        @display
+       </a>
+      </p>}
+    </div>
+   </div>
 
-   @if{@ne{@arg:directory@}{}@}{
-   <p class=directoryname>@navigate{@arg:directory@}{/<a
-   href="@url@?action=choose&#38;directory=@urlquote{@fullname@}@">@basename@</a>}@:</p>
-   }@
+@define{sometracks}{template}{}
 
-   @if{@isdirectories@}{
-   <div class=directories><div class=filesdirectories>
-    <p class=heading>
-     @label:choose.directories@
-    </p>
-    @choose{directories}{
-    <p class=entry>
-     <a
-     href="@url@?action=choose&#38;directory=@urlquote{@file@}@"
-     title="@label:choose.directory@">
-     <img class=button
-      src="@image:directory@"
-      alt="">
-      @transform{@file@}{dir}{display}@
-     </a>
-    </p>
-    }@
-   </div></div>
-   }@
-   @if{@isfiles@}{
-   <div class=files><div class=filesdirectories>
-    <p class=heading>
-     @label:choose.files@
-    </p>
-    @choose{files}{
-    <p class=entry>
-    @right{prefs}{<a class=imgprefs
-     href="@url@?action=prefs&#38;0_file=@urlquote{@resolve{@file@}@}@"
-     ><img class=button
-      src="@image:edit@"
-      title="@label:choose.prefsverbose@"
-      alt="@label:choose.prefs@"></a>}@
-     <a
-     href="@url@?action=play&#38;file=@urlquote{@file@}@&#38;back=@urlquote{@thisurl@}@"
-     title="@label:choose.play@">@transform{@file@}{track}{display}@</a>
-     @if{@eq{@trackstate{@file@}@}{playing}@}{[<b>playing</b>]}@
-     @if{@eq{@trackstate{@file@}@}{queued}@}{[<b>queued</b>]}@
-    </p>
-    }@
-    <p class=all>
-     @right{prefs}{<a class=imgprefs
-     href="@url@?action=prefs&#38;directory=@urlquote{@arg:directory@}@&#38;back=@urlquote{@thisurl@}@"
-     ><img class=button 
-      src="@image:edit@"
-      title="@label:choose.allprefsverbose@"
-      alt="@label:choose.allprefs@"></a>}@
-     <a class=button href="@url@?action=play&#38;directory=@urlquote{@arg:directory@}@&#38;back=@urlquote{@thisurl@}@">
-      @label:choose.playall@
-     </a>
-    </p>
-   </div></div>
-   }@
+   <div class=files>
+    <div class=filesdirectories>
+     @dirs{@arg{dir}}{@arg{re}}{
+      <p class=entry>
+@define{sometracks}{template}{@template}@#
+       @rights{prefs}{
+        <a class=imgprefs
+           href="@url?action=prefs&#38;0_file=@urlquote{@resolve{@track}}">
+        <img class=button
+             src="@image{edit}"
+             title="@label:choose.prefsverbose@"
+             alt="@label:choose.prefs@">
+        </a>
+       }@#
+       <a href="@url?action=play&#38;file=@urlquote{@track}&#38;back=@urlquote{@thisurl}"
+          title="@label{choose.play}">
+        @display
+       </a>
+       @if{@eq{@trackstate{@track}}{playing}}
+          {[<b>playing</b>]}
+       @if{@eq{@trackstate{@track}}{queued}}
+          {[<b>queued</b>]}
+      </p>}
+      @sometracks{
+      <p class=all>
+        @right{prefs}{
+        <a class=imgprefs
+           href="@url?action=prefs&#38;dir=@urlquote{@arg{dir}}">
+         <img class=button
+              src="@image{edit}"
+              title="@label:choose.allprefsverbose@"
+              alt="@label:choose.allprefs@">
+        </a>}
+        <a class=button
+           href="@url?action=play&#38;dir=@urlquote{@arg{dir}}"&#38;back=@urlquote{@thisurl}">
+         @label{choose.playall}
+        </a>
+      </p>}
+    </div>
+   </div>
 
 @credits
  </body>