Emmanuel Blot wrote:
> ...
> We should try to make upgrades "smoother" as Trac is now widely used.
> I think open source aficionados are likely to forgive this kind of
> glitch, while it is less acceptable for enterprise-grade
> installations.
>
Well, once we have the setuptools stuff in place, we could also add an
option for enabling a strict dependency check, so that only the plugins
explicitly designed for a given version will be enabled. I've no idea
yet about how this could be done, though.
> I hope we can provide an adapter for the old macro API before
> releasing 0.11 (+ the warning in log files to ask admins to upgrade
> the macros).
>
Patch attached. Would that be OK?
-- Christian
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups "Trac
Development" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/trac-dev?hl=en
-~----------~----~----~----~------~----~------~--~---
Index: trac/admin/console.py
===================================================================
--- trac/admin/console.py (revision 4612)
+++ trac/admin/console.py (working copy)
@@ -1115,7 +1115,7 @@
}}}
"""
- def render_macro(self, req, name, content):
+ def format_macro(self, formatter, name, content):
if content:
try:
arg = content.split(' ', 1)[0]
Index: trac/wiki/api.py
===================================================================
--- trac/wiki/api.py (revision 4612)
+++ trac/wiki/api.py (working copy)
@@ -74,6 +74,8 @@
class IWikiMacroProvider(Interface):
"""Extension point interface for components that provide Wiki macros."""
+ deprecated_methods = ['render_macro']
+
def get_macros():
"""Return an iterable that provides the names of the provided macros."""
@@ -81,13 +83,19 @@
"""Return a plain text description of the macro with the specified name.
"""
- def render_macro(formatter, name, content):
- """Return the HTML output of the macro.
+ def render_macro(req, name, content):
+ """Return the HTML output of the macro (deprecated)"""
- Since 0.11: first argument is a Formatter instead of a Request.
+ def parse_macro(parser, name, content):
+ """Called after the wiki text containing the call has been parsed.
+
+ (new in 0.11)
"""
+ def format_macro(formatter, name, content):
+ """Called by the formatter when rendering the parsed wiki text."""
+
class IWikiSyntaxProvider(Interface):
def get_wiki_syntax():
Index: trac/wiki/tests/formatter.py
===================================================================
--- trac/wiki/tests/formatter.py (revision 4612)
+++ trac/wiki/tests/formatter.py (working copy)
@@ -17,31 +17,31 @@
class HelloWorldMacro(WikiMacroBase):
"""A dummy macro used by the unit test."""
- def render_macro(self, req, name, content):
+ def format_macro(self, formatter, name, content):
return 'Hello World, args = ' + content
class DivHelloWorldMacro(WikiMacroBase):
"""A dummy macro returning a div block, used by the unit test."""
- def render_macro(self, req, name, content):
+ def format_macro(self, formatter, name, content):
return '<div>Hello World, args = %s</div>' % content
class DivCodeMacro(WikiMacroBase):
"""A dummy macro returning a div block, used by the unit test."""
- def render_macro(self, req, name, content):
+ def format_macro(self, formatter, name, content):
return '<div class="code">Hello World, args = %s</div>' % content
class DivCodeElementMacro(WikiMacroBase):
"""A dummy macro returning a div block, used by the unit test."""
- def render_macro(self, req, name, content):
+ def format_macro(self, formatter, name, content):
return html.DIV('Hello World, args = ', content, class_="code")
class NoneMacro(WikiMacroBase):
"""A dummy macro returning `None`, used by the unit test."""
- def render_macro(self, req, name, content):
+ def format_macro(self, formatter, name, content):
return None
class SampleResolver(Component):
Index: trac/wiki/intertrac.py
===================================================================
--- trac/wiki/intertrac.py (revision 4612)
+++ trac/wiki/intertrac.py (working copy)
@@ -57,7 +57,7 @@
def get_macro_description(self, name):
return "Provide a list of known InterTrac prefixes."
- def render_macro(self, req, name, content):
+ def format_macro(self, formatter, name, content):
intertracs = {}
for key, value in self.config.options('intertrac'):
idx = key.rfind('.') # rsplit only in 2.4
Index: trac/wiki/formatter.py
===================================================================
--- trac/wiki/formatter.py (revision 4612)
+++ trac/wiki/formatter.py (working copy)
@@ -61,7 +61,10 @@
for macro_provider in formatter.wiki.macro_providers:
for macro_name in macro_provider.get_macros():
if self.name == macro_name:
- self.processor = self._macro_processor
+ if hasattr(macro_provider, 'format_macro'):
+ self.processor = self._macro_processor
+ else:
+ self.processor = self._legacy_macro_processor
self.macro_provider = macro_provider
break
if not self.processor:
@@ -99,10 +102,17 @@
# generic processors
+ def _legacy_macro_processor(self, text): # TODO: remove in 0.12
+ self.env.log.warning('Executing pre-0.11 Wiki macro %s by provider %s'
+ % (self.name, self.macro_provider))
+ return self.macro_provider.render_macro(self.formatter.req, self.name,
+ text)
+
def _macro_processor(self, text):
self.env.log.debug('Executing Wiki macro %s by provider %s'
% (self.name, self.macro_provider))
- return self.macro_provider.render_macro(self.formatter, self.name, text)
+ return self.macro_provider.format_macro(self.formatter, self.name,
+ text)
def _mimeview_processor(self, text):
return Mimeview(self.env).render(self.formatter.context,
Index: trac/wiki/macros.py
===================================================================
--- trac/wiki/macros.py (revision 4612)
+++ trac/wiki/macros.py (working copy)
@@ -54,10 +54,19 @@
"""Return the subclass's docstring."""
return inspect.getdoc(self.__class__)
- def render_macro(self, formatter, name, content):
+ def parse_macro(self, parser, name, content):
raise NotImplementedError
+ def format_macro(self, formatter, name, content):
+ # -- TODO: remove in 0.12
+ if hasattr(self, 'render_macro'):
+ self.log.warning('Executing pre-0.11 Wiki macro %s by provider %s'
+ % (name, self.__class__))
+ return self.render_macro(formatter.req, name, content)
+ # --
+ raise NotImplementedError
+
class TitleIndexMacro(WikiMacroBase):
"""Inserts an alphabetic list of all wiki pages into the output.
@@ -73,7 +82,7 @@
SPLIT_RE = re.compile(r"( |/|[0-9])")
- def render_macro(self, formatter, name, content):
+ def format_macro(self, formatter, name, content):
args, kw = parse_args(content)
prefix = args and args[0] or None
format = kw.get('format', '')
@@ -130,7 +139,7 @@
recently changed pages to be included in the list.
"""
- def render_macro(self, formatter, name, content):
+ def format_macro(self, formatter, name, content):
prefix = limit = None
if content:
argv = [arg.strip() for arg in content.split(',')]
@@ -203,7 +212,7 @@
the right side of the other content.
"""
- def render_macro(self, formatter, name, content):
+ def format_macro(self, formatter, name, content):
min_depth, max_depth = 1, 6
title = None
inline = 0
@@ -282,7 +291,7 @@
<[EMAIL PROTECTED]>''
"""
- def render_macro(self, formatter, name, content):
+ def format_macro(self, formatter, name, content):
# args will be null if the macro is called without parenthesis.
if not content:
return ''
@@ -396,7 +405,7 @@
macros if the `PythonOptimize` option is enabled for mod_python!
"""
- def render_macro(self, formatter, name, content):
+ def format_macro(self, formatter, name, content):
from trac.wiki.formatter import system_message
wikimacros = formatter.context('wiki', 'WikiMacros')
@@ -429,7 +438,7 @@
options whose section and name start with the filters are output.
"""
- def render_macro(self, formatter, name, filter):
+ def format_macro(self, formatter, name, filter):
from trac.config import Option
filter = filter or ''
@@ -480,7 +489,7 @@
('TracNotification', 'Notification'),
]
- def render_macro(self, formatter, name, args):
+ def format_macro(self, formatter, name, args):
curpage = formatter.context.id
# Provision for multilingual TOC (e.g. TranslateRu/TracGuide ...)
Index: trac/wiki/interwiki.py
===================================================================
--- trac/wiki/interwiki.py (revision 4612)
+++ trac/wiki/interwiki.py (working copy)
@@ -133,7 +133,7 @@
def get_macro_description(self, name):
return "Provide a description list for the known InterWiki prefixes."
- def render_macro(self, req, name, content):
+ def format_macro(self, formatter, name, content):
from trac.util import sorted
from trac.util.html import html as _
interwikis = []