Commits

Anonymous committed fc782d2

[svn] fixed HtmlGenshiLexer, added more analyse_text methods and updated example file for genshi

  • Participants
  • Parent commits 6ff114a
  • Branches trunk

Comments (0)

Files changed (2)

File pygments/lexers/templates.py

             (r'[^<\$]+', Other),
             (r'(<\?python)(.*?)(\?>)',
              bygroups(Comment.Preproc, using(PythonLexer), Comment.Preproc)),
+            # yield style and script blocks as Other
+            (r'<\s*(script|style)\s*.*?>.*?<\s*/\1\s*>', Other),
             (r'<\s*py:[a-zA-Z0-9]+', Name.Tag, 'pytag'),
             (r'<\s*[a-zA-Z0-9:]+', Name.Tag, 'tag'),
             include('variable'),
         super(HtmlGenshiLexer, self).__init__(HtmlLexer, GenshiMarkupLexer,
                                               **options)
 
+    def analyse_text(text):
+        rv = 0.0
+        if re.search('\$\{.*?\}', text) is not None:
+            rv += 0.2
+        if re.search('py:(.*?)=["\']', text) is not None:
+            rv += 0.2
+        return rv + HtmlLexer.analyse_text(text) - 0.01
+
 
 class GenshiLexer(DelegatingLexer):
     name = 'Genshi'
         super(GenshiLexer, self).__init__(XmlLexer, GenshiMarkupLexer,
                                           **options)
 
+    def analyse_text(text):
+        rv = 0.0
+        if re.search('\$\{.*?\}', text) is not None:
+            rv += 0.2
+        if re.search('py:(.*?)=["\']', text) is not None:
+            rv += 0.2
+        return rv + XmlLexer.analyse_text(text) - 0.01
+
 
 class RhtmlLexer(DelegatingLexer):
     name = 'RHTML'

File tests/examplefiles/genshi_example.html

     PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
 <html xmlns="http://www.w3.org/1999/xhtml"
-    xmlns:py="http://genshi.edgewall.org/"
-    xmlns:xi="http://www.w3.org/2001/XInclude">
+      xmlns:py="http://genshi.edgewall.org/"
+      xmlns:xi="http://www.w3.org/2001/XInclude">
   <xi:include href="layout.html" />
-  <xi:include href="macros.html" />
   <head>
-    <title>$path</title>
+    <title>$title</title>
+    <script type="text/javascript">
+      $(document).ready(function() {
+        $("#group").change(function() {
+          $("#groupdesc").enable(this.selectedIndex != 0)
+        }).change();
+      });
+    </script>
   </head>
 
   <body>
     <div id="ctxtnav" class="nav">
-      <ul>
-        <li class="first"><a href="${href.changeset(rev, created_path)}">Last Change</a></li>
-        <li class="last"><a href="${href.log(path, rev=rev)}">Revision Log</a></li>
+      <ul py:if="report_href">
+        <li class="first"><a href="$report_href">Available Reports</a></li>
+        <li class="last">Custom Query</li>
       </ul>
     </div>
 
-    <div id="searchable">
-      <div id="content" class="browser">
+    <py:def function="num_matches(v)">
+      <span class="numrows">(${v or 'No'} match${v != 1 and 'es' or ''})</span>
+    </py:def>
 
-        <h1>${browser_path_links(path_links)}</h1>
+    <div id="content" class="query">
+      <h1>$title ${num_matches(len(tickets))}</h1>
 
-        <div id="jumprev">
-          <form action="" method="get">
-            <div>
-              <label for="rev">View revision:</label>
-              <input type="text" id="rev" name="rev" value="$rev" size="6" />
-            </div>
-          </form>
-        </div>
+      <form id="query" method="post" action="${href.query}">
+        <fieldset id="filters">
+          <legend>Filters</legend>
+          <table summary="Query filters">
+            <tbody>
+              <tr style="height: 1px"><td colspan="4"></td></tr>
+            </tbody>
+            <py:for each="field_name, field in fields.iteritems()">
+              <py:for each="constraint_name, constraint in constraints.iteritems()">
+                <tbody py:if="field_name == constraint_name"
+                  py:with="multiline = field.type in ('select', 'text')">
+                  <py:for each="constraint_idx, constraint_value in enumerate(constraint['values'])">
+                    <tr class="${field_name}" py:if="multiline or constraint_idx == 0">
+                      <py:choose test="constraint_idx">
+                        <py:when test="0">
+                          <th scope="row"><label>$field.label</label></th>
+                          <td py:if="field.type not in ('radio', 'checkbox')" class="mode">
+                            <select name="${field_name}_mode">
+                              <option py:for="mode in modes[field.type]" value="$mode.value"
+                                selected="${mode.value == constraint.mode and 'selected' or None}">$mode.name
+                              </option>
+                            </select>
+                          </td>
+                        </py:when>
+                        <py:otherwise><!--! not the first line of a multiline constraint -->
+                          <th colspan="2"><label>or</label></th>
+                        </py:otherwise>
+                      </py:choose>
 
-        <py:if test="dir">
-          <table class="listing" id="dirlist">
-            <thead>
-              <tr>
-                <py:def function="sortable_th(order, desc, class_, title)">
-                  <th class="$class_${order == class_ and (desc and ' desc' or ' asc') or ''}">
-                    <a title="Sort by $class_${order == class_ and not desc and
-                                               ' (descending)' or ''}"
-                      href="${href.browser(path, rev=rev, order=class_,
-                      desc=(class_ == order and not desc and 1 or None))}">$title</a>
-                  </th>
-                </py:def>
-                ${sortable_th(dir.order, dir.desc, 'name', 'Name')}
-                ${sortable_th(dir.order, dir.desc, 'size', 'Size')}
-                <th class="rev">Rev</th>
-                ${sortable_th(dir.order, dir.desc, 'date', 'Age')}
-                <th class="change">Last Change</th>
+                      <td class="filter" colspan="${field.type in ('radio', 'checkbox') and 2 or None}"
+                        py:choose="field.type">
+
+                        <py:when test="'select'">
+                          <select name="${constraint_name}">
+                            <option></option>
+                            <option py:for="option in field.options"
+                              selected="${option == constraint_value and 'selected' or None}">$option
+                            </option>
+                          </select>
+                        </py:when>
+
+
+                        <py:when test="'radio'">
+                          <py:for each="option in field.options">
+                            <input type="checkbox" id="${field_name}_$option" name="${field_name}"
+                              value="$option"
+                              checked="${any([(value == option) == (constraint.mode == '')
+                                              for value in constraint['values']]) and 'checked' or None}" />
+                            <label for="${field_name}_$option">${option or 'none'}</label>
+                          </py:for>
+                        </py:when>
+
+                        <py:when test="'checkbox'">
+                          <input type="radio" id="${field_name}_on" name="$field_name" value="1"
+                                 checked="${constraint.mode != '!' or None}" />
+                          <label for="${field_name}_on">yes</label>
+                          <input type="radio" id="${field_name}_off" name="$field_name" value="0"
+                                 checked="${constraint.mode == '!' or None}" />
+                          <label for="${field_name}_off">no</label>
+                        </py:when>
+
+                        <py:when test="'text'">
+                          <input type="text" name="${field_name}" value="$constraint_value" size="42" />
+                        </py:when>
+
+                      </td>
+                      <td class="actions"
+                        py:with="rm_idx = multiline and idx or len(constraint['values'])-1">
+                        <input type="submit" name="rm_filter_${field_name}${
+                          field.type != 'radio' and '_%d' % rm_idx or ''}" value="-" />
+                      </td>
+                    </tr>
+                  </py:for>
+                </tbody>
+              </py:for>
+            </py:for>
+
+            <tbody>
+              <tr class="actions">
+                <td class="actions" colspan="4" style="text-align: right">
+                  <label for="add_filter">Add filter</label>&nbsp;
+                  <select name="add_filter" id="add_filter">
+                    <option></option>
+                    <option py:for="field_name, field in fields.iteritems()"
+                            value="$field_name"
+                            disabled="${(field.type == 'radio' and
+                                         constraints[field_name] and
+                                         len(constraints[field_name])) or None}">
+                      ${field.label}
+                    </option>
+                  </select>
+                  <input type="submit" name="add" value="+" />
+                </td>
               </tr>
-            </thead>
-            <tbody>
-              <py:if test="chrome.links.up">
-                <tr class="even">
-                  <td class="name" colspan="5">
-                    <a class="parent" title="Parent Directory" href="${chrome.links.up[0].href}">../</a>
-                  </td>
-                </tr>
-              </py:if>
-              <py:for each="idx, entry in enumerate(dir.entries)">
-                <py:with vars="change = dir.changes[entry.rev]">
-                  <tr class="${idx % 2 and 'even' or 'odd'}">
-                    <td class="name">
-                      <a class="${entry.kind}"
-                        title="${entry.kind == 'dir' and 'Browse Directory' or 'View File'}"
-                        href="${href.browser(entry.path, rev=rev)}">$entry.name</a>
-                    </td>
-                    <td class="size">${sizeinfo(entry.size)}</td>
-                    <td class="rev">
-                      <a title="View Revision Log"
-                        href="${href.log(entry.path, rev=rev)}">$entry.rev</a>
-                    </td>
-                    <td class="age">${dateinfo(change.date_seconds)}</td>
-                    <!--! FIXME: use 'date' and therefore replace 'date' by 'date_seconds'
-                                 in trac.versioncontrol.web_ui.util.get_changes -->
-                    <td class="change">
-                      <span class="author">$change.author:</span>
-                      <span class="change">$change.message</span>
-                    </td>
-                  </tr>
-                </py:with>
-              </py:for>
             </tbody>
           </table>
-        </py:if>
+        </fieldset>
 
-        <table py:if="props or file" id="info" summary="Revision info">
-          <tr py:if="file">
-            <th scope="col">
-              Revision <a href="${href.changeset(rev)}">$rev</a>, ${sizeinfo(file.size)}
-              (checked in by $file.author, ${dateinfo(file.date)} ago)
-            </th>
-          </tr>
-          <tr py:if="file">
-            <td class="message">$file.message</td>
-          </tr>
-          <tr py:if="props">
-            <td colspan="2">
-              <ul class="props">
-                <li py:for="prop in props">
-                  Property <strong>$prop.name</strong> set to <em><code>$prop.value</code></em>
-                </li>
-              </ul>
-            </td>
-          </tr>
-        </table>
+        <p class="option">
+          <label for="group">Group results by</label>
+          <select name="group" id="group">
+            <option></option>
+            <option py:for="field_name, field in fields.iteritems()"
+                    py:if="field.type in ('select', 'radio') or field_name == 'owner'"
+                    selected="${field_name == query.group or None}"
+                    value="${field_name}">${field.label}</option>
+          </select>
+          <input type="checkbox" name="groupdesc" id="groupdesc"
+                 checked="${query.groupdesc or None}" />
+          <label for="groupdesc">descending</label>
+        </p>
 
-        ${preview_file(file.preview)} <!--! a <div id="preview"> containing the rendered file preview -->
+        <p class="option">
+          <input type="checkbox" name="verbose" id="verbose"
+                 checked="${query.verbose or None}" />
+          <label for="verbose">Show full description under each result</label>
+        </p>
 
-        <div id="help">
-          <strong>Note:</strong> See <a href="${href.wiki('TracBrowser')}">TracBrowser</a>
-          for help on using the browser.
+        <div class="buttons">
+          <input type="hidden" name="order" value="$query.order" />
+          <input py:if="desc" type="hidden" name="desc" value="1" />
+          <input type="submit" name="update" value="Update" />
         </div>
+        <hr />
+      </form>
 
-        <div id="anydiff">
-          <form action="${href.diff_form()}" method="get">
-            <div class="buttons">
-              <input type="hidden" name="new_path" value="$path" />
-              <input type="hidden" name="old_path" value="$path" />
-              <input type="hidden" name="new_rev" value="$rev" />
-              <input type="hidden" name="old_rev" value="$rev" />
-              <input type="submit" value="View changes..." title="Select paths and revs for Diff" />
-            </div>
-          </form>
-        </div>
+      <script type="text/javascript">
+        var properties={
+        <py:for each="idx, (field_name, field) in enumerate(fields.items())">
+          $field_name: { type: "$field.type", label: "$field.label"
+          <py:if test="field.options">, options: [
+            <py:for each="idx, option in enumerate(field.options)">"$option"<py:if
+                test="idx &lt; len(field.options)-1">,</py:if>
+            </py:for>]
+          </py:if>}<py:if test="idx &lt; len(fields)-1">,</py:if>
+        </py:for>
+        };
+        var modes = {
+        <py:for each="idx, (type_name, type_modes) in enumerate(modes.items())">
+          $type_name: [
+          <py:for each="idx, mode in enumerate(type_modes)">
+            {text: "$mode.name", value: "$mode.value" }<py:if
+              test="idx &lt; len(type_modes)-1">,</py:if>
+          </py:for>
+            ]<py:if test="idx &lt; len(modes)-1">,</py:if>
+        </py:for>
+        };
+        initializeFilters();
+      </script>
 
+      <xi:include href="query_div.html" />
+
+      <div id="help">
+        <strong>Note:</strong> See <a href="${href.wiki('TracQuery')}">TracQuery</a>
+        for help on using queries.
       </div>
+
     </div>
   </body>
 </html>