incubator-bloodhound-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From g..@apache.org
Subject svn commit: r1351312 - in /incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard: layouts/templates/widget_macros.html web_ui.py
Date Mon, 18 Jun 2012 12:06:18 GMT
Author: gjm
Date: Mon Jun 18 12:06:17 2012
New Revision: 1351312

URL: http://svn.apache.org/viewvc?rev=1351312&view=rev
Log:
dashboard: changes to bh:args tag partising in widget XML markup - towards #45 (from olemis)

Modified:
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/templates/widget_macros.html
    incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/templates/widget_macros.html
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/templates/widget_macros.html?rev=1351312&r1=1351311&r2=1351312&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/templates/widget_macros.html
(original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/layouts/templates/widget_macros.html
Mon Jun 18 12:06:17 2012
@@ -89,7 +89,7 @@
   <py:match path="bh:widget">
     <py:choose test="">
       <py:when test="bhdb"
-          py:with="wnm = unicode(select('@urn')); args = unicode(select('bh:args/text()'))
or {}; altlinks = unicode(select('@altlinks')) != 'false'; ctxtnav = unicode(select('@ctxtnav'))
!= 'false';">
+          py:with="wnm = unicode(select('@urn')); args = select('bh:args/bh:arg') or {};
altlinks = unicode(select('@altlinks')) != 'false'; ctxtnav = unicode(select('@ctxtnav'))
!= 'false';">
         ${widget_container(bhdb.expand_widget(context, dict(args=[wnm, None, {'args': args}],
altlinks=altlinks, ctxtnav=ctxtnav)))}
       </py:when>
       <py:otherwise>

Modified: incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py
URL: http://svn.apache.org/viewvc/incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py?rev=1351312&r1=1351311&r2=1351312&view=diff
==============================================================================
--- incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py (original)
+++ incubator/bloodhound/trunk/bloodhound_dashboard/bhdashboard/web_ui.py Mon Jun 18 12:06:17
2012
@@ -32,6 +32,7 @@ import re
 from uuid import uuid4
 
 from genshi.builder import tag
+from genshi.core import Stream
 from trac.core import Component, implements
 from trac.config import Option, IntOption
 from trac.mimeview.api import Context
@@ -329,8 +330,12 @@ class DashboardChrome:
         :param widget: Widget definition
         """
         dbmod = DashboardModule(self.env)
-        if isinstance(widget['args'], basestring):
-            widget['args'] = _json.loads(widget['args'])
+        options = widget['args'][2]
+        argsdef = options.get('args')
+        if isinstance(argsdef, basestring):
+            options['args'] = _json.loads(argsdef)
+        elif isinstance(argsdef, Stream):
+            options['args'] = parse_args_tag(argsdef)
         return dbmod.expand_widget_data(
                     context.req,
                     {'widgets' : { 0 : widget }}
@@ -340,34 +345,30 @@ class DashboardChrome:
 #    Stream processors
 #------------------------------------------------------
 
-def parse_widgets_markup(stream):
-    """Parse Genshi Markup for a set of widgets
-    """
-    s = iter(stream)
-
-    # Check that stream starts by opening bh:widgets tag
-    token, data, pos = s.next()
-    assert token == 'START'
-    assert data[0].namespace == XMLNS_DASHBOARD_UI
-    assert data[1].localname == 'widgets'
-
-    # Continue parsing bh:w tag
-    def find(_s, tkn, ns, localname):
-        for token, data, pos in _s:
-            if token == tkn and data[0].namespace != ns \
-                    and data[1].localname != localname:
-                return token, data, pos
-        else:
-            return None
-
-    i = find(s, 'START', XMLNS_DASHBOARD_UI, 'widget')
-
-    # TODO: Finish parsing widgets markup
-
-    #if i is not None:
-    #    i = find()
-
-def parse_widget_markup(stream):
-    """Parse Genshi Markup for a single widget
+def parse_args_tag(stream):
+    """Parse Genshi Markup for widget arguments
     """
+    args = {}
+    inside = False
+    argnm = ''
+    argvalue = ''
+    for kind, data, _ in stream:
+        if kind == Stream.START:
+            qname, attrs = data
+            if qname.namespace == XMLNS_DASHBOARD_UI \
+                    and qname.localname == 'arg':
+                if inside :
+                    raise RuntimeError('Nested bh:arg tag')
+                else:
+                    argnm = attrs.get('name')
+                    argvalue  = ''
+                    inside = True
+        elif kind == Stream.TEXT:
+            argvalue += data
+        elif kind == Stream.END:
+            if qname.namespace == XMLNS_DASHBOARD_UI \
+                    and qname.localname == 'arg':
+                args[argnm] = argvalue
+                inside = False
+    return args
 



Mime
View raw message