Modify

Opened 15 years ago

Closed 15 years ago

#6890 closed defect (fixed)

support for trac 0.10?

Reported by: Daniel Abel Owned by: Roman Mohr
Priority: normal Component: TracBibPlugin
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

Is TracBibPlugin compatible with trac 0.10? It appears as such on the trac-hacks.org opening page (i.e. it has the 0.10 tag), but compatibility is not mentioned on the TracBibPlugin page, and the 0.10 svn branch is empty.

So, is 0.10 supported?

Attachments (0)

Change History (3)

comment:1 Changed 15 years ago by Roman Mohr

Status: newassigned

I never tried it.
When i did so today, it turned out that trac 0.10 does not know "parse_args", so a little bit of rewriting would be needed. I will have a look at it the next days.

So currently no support for 0.10.

comment:2 Changed 15 years ago by Daniel Abel

This diff apparently makes it work with trac 0.10: (apart from parse_args, the api of WikiMacroBase also changed, also, genshi is new in 0.11)

$ svn diff tracbib/tracbib.py
Index: tracbib/tracbib.py
===================================================================
--- tracbib/tracbib.py	(revision 365)
+++ tracbib/tracbib.py	(working copy)
@@ -1,9 +1,57 @@
 from trac.core import *
-from trac.wiki.api import IWikiMacroProvider, parse_args
+from trac.wiki.api import IWikiMacroProvider
+try:
+  from trac.wiki.api import parse_args
+except ImportError: # for trac 0.10:
+  import re
+  # following is from
+  # http://trac.edgewall.org/browser/trunk/trac/wiki/api.py
+  def parse_args(args, strict=True):
+      """Utility for parsing macro "content" and splitting them into arguments.
+
+      The content is split along commas, unless they are escaped with a
+      backquote (like this: \,).
+
+      :param args: macros arguments, as plain text
+      :param strict: if `True`, only Python-like identifiers will be
+                     recognized as keyword arguments
+
+      Example usage:
+
+      >>> parse_args('')
+      ([], {})
+      >>> parse_args('Some text')
+      (['Some text'], {})
+      >>> parse_args('Some text, mode= 3, some other arg\, with a comma.')
+      (['Some text', ' some other arg, with a comma.'], {'mode': ' 3'})
+      >>> parse_args('milestone=milestone1,status!=closed', strict=False)
+      ([], {'status!': 'closed', 'milestone': 'milestone1'})
+
+      """   
+      largs, kwargs = [], {}
+      if args:
+          for arg in re.split(r'(?<!\\),', args):
+              arg = arg.replace(r'\,', ',')
+              if strict:
+                  m = re.match(r'\s*[a-zA-Z_]\w+=', arg)
+              else:
+                  m = re.match(r'\s*[^=]+=', arg)
+              if m:
+                  kw = arg[:m.end()-1].strip()
+                  if strict:
+                      kw = unicode(kw).encode('utf-8')
+                  kwargs[kw] = arg[m.end():]
+              else:
+                  largs.append(arg)
+      return largs, kwargs
+
 from trac.wiki.macros import WikiMacroBase
 from trac.attachment import Attachment
 from trac.env import Environment
-from genshi.builder import tag
+try:
+  from genshi.builder import tag
+except ImportError: # for trac 0.10:
+  from trac.util.html import html as tag
 from trac.wiki.model import WikiPage
 from trac.wiki.formatter import WikiProcessor
 from trac.util.text import to_unicode
@@ -68,6 +116,9 @@
 class BibAddMacro(WikiMacroBase):
   implements(IWikiMacroProvider)
 
+  def render_macro(self, request,name,content):
+    return self.expand_macro(request,name,content)
+
   def expand_macro(self,formatter,name,content):
     args, kwargs = parse_args(content, strict=False)
     if len(args) != 1:
@@ -148,6 +199,9 @@
 
 class BibCiteMacro(WikiMacroBase):
   implements(IWikiMacroProvider)
+
+  def render_macro(self, request,name,content):
+    return self.expand_macro(request,name,content)
   
   def expand_macro(self,formatter,name,content):
 
@@ -174,6 +228,9 @@
 class BibNoCiteMacro(WikiMacroBase):
   implements(IWikiMacroProvider)
   
+  def render_macro(self, request,name,content):
+    return self.expand_macro(request,name,content)
+
   def expand_macro(self,formatter,name,content):
 
     args, kwargs = parse_args(content, strict=False)
@@ -198,6 +255,9 @@
 class BibRefMacro(WikiMacroBase):
   implements(IWikiMacroProvider)
 
+  def render_macro(self, request,name,content):
+    return self.expand_macro(request,name,content)
+
   def expand_macro(self,formatter,name,content):
     citelist = getattr(formatter, CITELIST,[])
     bibdb = getattr(formatter, BIBDB,{})

comment:3 Changed 15 years ago by Roman Mohr

Resolution: fixed
Status: assignedclosed

Thank you for sharing your patch. It's in the repository now..

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Roman Mohr.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.