I've written a couple of wiki macros and was going to include them on the MacroBazaar wiki page:
http://projects.edgewall.com/trac/wiki/MacroBazaar but it is not editable right now. I'm sending them to the list to ask if someone with the right privileges can include them. The description of the macros is included on the code. Greetings, Sergio. -- Sergio Talens-Oliag <[EMAIL PROTECTED]> <http://people.debian.org/~sto/> Key fingerprint = 29DF 544F 1BD9 548C 8F15 86EF 6770 052B B8C1 FA69
# ------------
# Trac Add-ons
# ------------
# Module: wiki-macros
# File: IncludeSVNFile.py
# Author: Sergio Talens-Oliag <[EMAIL PROTECTED]>
# Copyright: (c) 2006 Sergio Talens-Oliag <[EMAIL PROTECTED]>
# SVN Id: $Id: IncludeSVNFile.py 19 2006-03-27 16:40:31Z sto $
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
# ---------------------
# -*- coding: utf-8 -*-
# ---------------------
"""
Trac Wiki-Macro that takes the PATH of a svn file (relative to the svn root)
and includes it on a wiki page parsed as in the 'browser' view.
The macro takes two arguments separated by commas, the PATH and an optional
mime-type that will be used instead of the one guessed by get_mimetype.
Examples:
- This will include the formated python file:
[[IncludeSVNFile(/tools/trac/wiki-macros/IncludeSVNFile.py)]]
- This will include the same file formated as a plain text file
[[IncludeSVNFile(/tools/trac/wiki-macros/IncludeSVNFile.py,text/plain)]]
"""
from trac import util
from trac.mimeview import Mimeview, get_mimetype
from StringIO import StringIO
def execute(hdf, args, env):
path = None
mime_type = None
buf = StringIO()
# Process args
args = args.replace('\'', '\'\'')
argv = [arg.strip() for arg in args.split(',')]
if len(argv) > 0:
path = argv[0]
if len(argv) > 1:
mime_type = argv[1]
# Get svn node
try:
repos = env.get_repository()
node = repos.get_node(path)
except Exception, e:
raise util.TracError(\
'The string "%s" doesn\'t seem to be a valid SVN path.\n' \
'The error was: "%s"' % (path, e))
# Parse file
if node != None:
try:
mimeview = Mimeview(env)
if not mime_type:
mime_type = node.content_type
if not mime_type or mime_type == 'application/octet-stream':
mime_type = get_mimetype(node.name) or mime_type or 'text/plain'
content = node.get_content().read(mimeview.max_preview_size())
buf.write(mimeview.render(None, mime_type, content))
except Exception, e:
raise util.TracError(\
'Error parsing file "%s" of type "%s".\n'
'The error was: "%s"' % (path, mime_type, e))
return buf.getvalue()
# ------
# SVN Id: $Id: IncludeSVNFile.py 19 2006-03-27 16:40:31Z sto $
# ------------
# Trac Add-ons
# ------------
# Module: wiki-macros
# File: PrjLink.py
# Author: Sergio Talens-Oliag <[EMAIL PROTECTED]>
# Copyright: (c) 2006 Sergio Talens-Oliag <[EMAIL PROTECTED]>
# SVN Id: $Id: PrjLink.py 22 2006-03-27 19:09:35Z sto $
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License along
# with this program; if not, write to the Free Software Foundation, Inc.,
# 51 Franklin St, Fifth Floor, Boston MA 02110-1301 USA
# ---------------------
# -*- coding: utf-8 -*-
# ---------------------
"""
Wiki Macro to build links relative to the project Base URL.
It is useful to build links to things like login and logout or other areas
generated using Plugins.
The macro accepts two arguments separated by commas, the first one is the PATH
relative to the project base_url and the second one is the anchor text (if it
is not present the PATH is used as anchor text).
"""
import string
def execute(hdf, txt, env):
base_url = env.href.base
if txt != None:
args = txt.split(' ', 1)
rel_url = args[0]
if len(args) > 1:
link_txt = args[1]
else:
link_txt = args[0]
link = '<a href="%s/%s">%s</a>' % (base_url, rel_url, link_txt)
else:
link = '<a href="%s/">%s</a>' % (baseurl, '/')
return link
# ------
# SVN Id: $Id: PrjLink.py 22 2006-03-27 19:09:35Z sto $
signature.asc
Description: Digital signature
_______________________________________________ Trac mailing list [email protected] http://lists.edgewall.com/mailman/listinfo/trac
