Olemis Lang avatar Olemis Lang committed 5bed975

First working version of `WikiHistory` and `ConfigOption` macros

Comments (0)

Files changed (13)

trac-dev/_project/_project.ini

 
 [project]
-name = Package name (mandatory)
-license = Comma-separated list of target licence file(s) (mandatory)
-topmod = Name of top-level module (mandatory)
-component = Trac component name identifying the project (mandatory)
-tracver = Comma-separated list of Trac versions supported. (mandatory)
-demourl = URL where a demo iluustrates the features in action (optional)
-summary = Describe the project *BRIEFLY*. (mandatory)
-desc = Not so concise description. (mandatory)
-folder = Root folder for the plugin source code in VCS (mandatory)
-
-[deps/PackageName]
-home = Home page of external project (mandatory)
-topmod = Name of top-level imported module (mandatory)
-since = Version since when dependency was intoduced (optional)
-verinfo = Tested or potentially working versions (optional)
-details = Explain dependency relationship using WikiFormatting (optional)
+name = TracBasicMacros
+license = Apache
+topmod = tracbm
+component = trac-basic-macros
+tracver = 0.11
+demourl = 
+summary = Simple but useful Trac macros
+desc = Expand Trac capabilities by embed simple snippets in wiki pages using simple macros.
+folder = tracbm
 
 [categories]
 c1 = Environment :: Plugins
 c14 = Topic :: Software Development :: Bug Tracking
 c15 = Topic :: Software Development :: Libraries :: Application Frameworks
 c16 = Topic :: Software Development :: Libraries :: Python Modules
-c0 = Add your own

trac-dev/tracbm/CHANGES

+
+What's new in version 1.0.0
+---------------------------
+
+- XXX

trac-dev/tracbm/COPYRIGHT

+
+                                 Apache License
+                           Version 2.0, January 2004
+                        http://www.apache.org/licenses/
+
+   TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+   1. Definitions.
+
+      "License" shall mean the terms and conditions for use, reproduction,
+      and distribution as defined by Sections 1 through 9 of this document.
+
+      "Licensor" shall mean the copyright owner or entity authorized by
+      the copyright owner that is granting the License.
+
+      "Legal Entity" shall mean the union of the acting entity and all
+      other entities that control, are controlled by, or are under common
+      control with that entity. For the purposes of this definition,
+      "control" means (i) the power, direct or indirect, to cause the
+      direction or management of such entity, whether by contract or
+      otherwise, or (ii) ownership of fifty percent (50%) or more of the
+      outstanding shares, or (iii) beneficial ownership of such entity.
+
+      "You" (or "Your") shall mean an individual or Legal Entity
+      exercising permissions granted by this License.
+
+      "Source" form shall mean the preferred form for making modifications,
+      including but not limited to software source code, documentation
+      source, and configuration files.
+
+      "Object" form shall mean any form resulting from mechanical
+      transformation or translation of a Source form, including but
+      not limited to compiled object code, generated documentation,
+      and conversions to other media types.
+
+      "Work" shall mean the work of authorship, whether in Source or
+      Object form, made available under the License, as indicated by a
+      copyright notice that is included in or attached to the work
+      (an example is provided in the Appendix below).
+
+      "Derivative Works" shall mean any work, whether in Source or Object
+      form, that is based on (or derived from) the Work and for which the
+      editorial revisions, annotations, elaborations, or other modifications
+      represent, as a whole, an original work of authorship. For the purposes
+      of this License, Derivative Works shall not include works that remain
+      separable from, or merely link (or bind by name) to the interfaces of,
+      the Work and Derivative Works thereof.
+
+      "Contribution" shall mean any work of authorship, including
+      the original version of the Work and any modifications or additions
+      to that Work or Derivative Works thereof, that is intentionally
+      submitted to Licensor for inclusion in the Work by the copyright owner
+      or by an individual or Legal Entity authorized to submit on behalf of
+      the copyright owner. For the purposes of this definition, "submitted"
+      means any form of electronic, verbal, or written communication sent
+      to the Licensor or its representatives, including but not limited to
+      communication on electronic mailing lists, source code control systems,
+      and issue tracking systems that are managed by, or on behalf of, the
+      Licensor for the purpose of discussing and improving the Work, but
+      excluding communication that is conspicuously marked or otherwise
+      designated in writing by the copyright owner as "Not a Contribution."
+
+      "Contributor" shall mean Licensor and any individual or Legal Entity
+      on behalf of whom a Contribution has been received by Licensor and
+      subsequently incorporated within the Work.
+
+   2. Grant of Copyright License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      copyright license to reproduce, prepare Derivative Works of,
+      publicly display, publicly perform, sublicense, and distribute the
+      Work and such Derivative Works in Source or Object form.
+
+   3. Grant of Patent License. Subject to the terms and conditions of
+      this License, each Contributor hereby grants to You a perpetual,
+      worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+      (except as stated in this section) patent license to make, have made,
+      use, offer to sell, sell, import, and otherwise transfer the Work,
+      where such license applies only to those patent claims licensable
+      by such Contributor that are necessarily infringed by their
+      Contribution(s) alone or by combination of their Contribution(s)
+      with the Work to which such Contribution(s) was submitted. If You
+      institute patent litigation against any entity (including a
+      cross-claim or counterclaim in a lawsuit) alleging that the Work
+      or a Contribution incorporated within the Work constitutes direct
+      or contributory patent infringement, then any patent licenses
+      granted to You under this License for that Work shall terminate
+      as of the date such litigation is filed.
+
+   4. Redistribution. You may reproduce and distribute copies of the
+      Work or Derivative Works thereof in any medium, with or without
+      modifications, and in Source or Object form, provided that You
+      meet the following conditions:
+
+      (a) You must give any other recipients of the Work or
+          Derivative Works a copy of this License; and
+
+      (b) You must cause any modified files to carry prominent notices
+          stating that You changed the files; and
+
+      (c) You must retain, in the Source form of any Derivative Works
+          that You distribute, all copyright, patent, trademark, and
+          attribution notices from the Source form of the Work,
+          excluding those notices that do not pertain to any part of
+          the Derivative Works; and
+
+      (d) If the Work includes a "NOTICE" text file as part of its
+          distribution, then any Derivative Works that You distribute must
+          include a readable copy of the attribution notices contained
+          within such NOTICE file, excluding those notices that do not
+          pertain to any part of the Derivative Works, in at least one
+          of the following places: within a NOTICE text file distributed
+          as part of the Derivative Works; within the Source form or
+          documentation, if provided along with the Derivative Works; or,
+          within a display generated by the Derivative Works, if and
+          wherever such third-party notices normally appear. The contents
+          of the NOTICE file are for informational purposes only and
+          do not modify the License. You may add Your own attribution
+          notices within Derivative Works that You distribute, alongside
+          or as an addendum to the NOTICE text from the Work, provided
+          that such additional attribution notices cannot be construed
+          as modifying the License.
+
+      You may add Your own copyright statement to Your modifications and
+      may provide additional or different license terms and conditions
+      for use, reproduction, or distribution of Your modifications, or
+      for any such Derivative Works as a whole, provided Your use,
+      reproduction, and distribution of the Work otherwise complies with
+      the conditions stated in this License.
+
+   5. Submission of Contributions. Unless You explicitly state otherwise,
+      any Contribution intentionally submitted for inclusion in the Work
+      by You to the Licensor shall be under the terms and conditions of
+      this License, without any additional terms or conditions.
+      Notwithstanding the above, nothing herein shall supersede or modify
+      the terms of any separate license agreement you may have executed
+      with Licensor regarding such Contributions.
+
+   6. Trademarks. This License does not grant permission to use the trade
+      names, trademarks, service marks, or product names of the Licensor,
+      except as required for reasonable and customary use in describing the
+      origin of the Work and reproducing the content of the NOTICE file.
+
+   7. Disclaimer of Warranty. Unless required by applicable law or
+      agreed to in writing, Licensor provides the Work (and each
+      Contributor provides its Contributions) on an "AS IS" BASIS,
+      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+      implied, including, without limitation, any warranties or conditions
+      of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+      PARTICULAR PURPOSE. You are solely responsible for determining the
+      appropriateness of using or redistributing the Work and assume any
+      risks associated with Your exercise of permissions under this License.
+
+   8. Limitation of Liability. In no event and under no legal theory,
+      whether in tort (including negligence), contract, or otherwise,
+      unless required by applicable law (such as deliberate and grossly
+      negligent acts) or agreed to in writing, shall any Contributor be
+      liable to You for damages, including any direct, indirect, special,
+      incidental, or consequential damages of any character arising as a
+      result of this License or out of the use or inability to use the
+      Work (including but not limited to damages for loss of goodwill,
+      work stoppage, computer failure or malfunction, or any and all
+      other commercial damages or losses), even if such Contributor
+      has been advised of the possibility of such damages.
+
+   9. Accepting Warranty or Additional Liability. While redistributing
+      the Work or Derivative Works thereof, You may choose to offer,
+      and charge a fee for, acceptance of support, warranty, indemnity,
+      or other liability obligations and/or rights consistent with this
+      License. However, in accepting such obligations, You may act only
+      on Your own behalf and on Your sole responsibility, not on behalf
+      of any other Contributor, and only if You agree to indemnify,
+      defend, and hold each Contributor harmless for any liability
+      incurred by, or claims asserted against, such Contributor by reason
+      of your accepting any such warranty or additional liability.
+
+   END OF TERMS AND CONDITIONS
+
+   APPENDIX: How to apply the Apache License to your work.
+
+      To apply the Apache License to your work, attach the following
+      boilerplate notice, with the fields enclosed by brackets "[]"
+      replaced with your own identifying information. (Don't include
+      the brackets!)  The text should be enclosed in the appropriate
+      comment syntax for the file format. We also recommend that a
+      file or class name and description of purpose be included on the
+      same "printed page" as the copyright notice for easier
+      identification within third-party archives.
+
+   Copyright [yyyy] [name of copyright owner]
+
+   Licensed under the Apache License, Version 2.0 (the "License");
+   you may not use this file except in compliance with the License.
+   You may obtain a copy of the License at
+
+       http://www.apache.org/licenses/LICENSE-2.0
+
+   Unless required by applicable law or agreed to in writing, software
+   distributed under the License is distributed on an "AS IS" BASIS,
+   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+   See the License for the specific language governing permissions and
+   limitations under the License.

trac-dev/tracbm/MANIFEST.in

+
+include CHANGES COPYRIGHT NOTICE README TODO

trac-dev/tracbm/NOTICE

+
+Below you will find an example NOTICE file. Modify its contents as 
+needed.
+
+This package includes a verbatim copy of `gviz_api` module 
+(version 1.0.0). This has been done so as to ease the installation 
+process and provide the means to fall-back to this implementation if 
+`gviz_api` is not installed in the target deployment environment.
+Herinafter you will also find a verbatim copy of the contents of the 
+README file distributed with the aformentioned module.
+
+==============================
+Copyright (C) 2008 Google Inc.
+
+Licensed under the Apache License, Version 2.0 (the "License");
+you may not use this file except in compliance with the License.
+You may obtain a copy of the License at
+
+     http://www.apache.org/licenses/LICENSE-2.0
+
+Unless required by applicable law or agreed to in writing, software
+distributed under the License is distributed on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+See the License for the specific language governing permissions and
+limitations under the License.
+
+Installing the library:
+  python ./setup.py install
+  (You might need root privileges to do this)
+
+Testing the library:
+  python ./setup.py test
+
+==============================
+
+By installing TracGViz plugin, you will have a completely functional 
+instance of `gviz_api` (version 1.0.0) module. The maintainers of 
+this package ARE NOT RESPONSIBLE of providing the latest version 
+of this module in newer versions, since this has been done as 
+a last recourse alternative. If a newer (or any other) version is 
+already installed in your system, it will be used instead. However 
+the authors and maintainers WILL NOT ensure that the current plugin 
+implementation will be compatible with successive versions of 
+`gviz_api` and ARE NOT responsible if future contributions included 
+in the aforementioned module turn out to be incompatible with the 
+current implementation.
+
+Google Visualization API, and iGoogle Gadgets  are technologies 
+offered by Google Inc. in the form of a Software as a Service (SaaS) 
+platform. If you are using TracGViz plugin, make sure you have 
+already read and agreed the related Terms of Use of these services 
+and/or End-User License Agreement (EULA).
+
+Youtube is a registered trademark owned by Google Inc.
+
+All other trademarks and labels are a property of their respective 
+owners. The authors and maintainers of TracGViz plugin 
+ARE NOT RESPONSIBLE if the usage given to this package violates any 
+of the aformentioned statements, or if any end-user violates 
+any other COPYRIGHT statements.

trac-dev/tracbm/README

+
+= Simple but useful Trac macros =
+
+Expand Trac capabilities by embedding simple snippets in wiki pages using simple macros.
+
+== !ToDo ==
+
+Outstanding tasks are :
+
+[[TicketQuery(component=trac-basic-macros&priority=major, format=list, rows=id|summary)]]
+
+== Dependencies ==
+
+This plugin depends on the following components to be installed:
+
+  - None yet.
+
+== Installation ==
+
+This plugin has been tested with 
+[http://trac.edgewall.org/ Trac]  [http://trac.edgewall.org/wiki/0.11 0.11] . 
+
+The first step to make it work is to [wiki:TracPlugins install this plugin] 
+either for a particular environment or otherwise make it available to
+all the environments:
+
+{{{
+$ easy_install /path/to/unpacked/TracBasicMacros-x.y.z.zip
+}}}
+
+,, where ''x.y.z'' is the version of the plugin,,
+
+... or alternately ...
+
+{{{
+$ easy_install TracBasicMacros
+}}}
+
+In case of having internet connection and access to 
+[http://pypi.python.org/pypi PyPI] or a simlar repository, both these 
+methods '''should''' automatically retrieve the [#Dependencies external 
+dependencies] from there.
+
+== Configuration ==
+
+In order to enable [wiki:/En/Devel/TracBasicMacros TracBasicMacros] plugin, 
+the only thing to do is to add the following lines to [wiki:TracIni trac.ini].
+
+{{{
+[components]
+tracbm.* = enabled
+}}}
+
+== Bug / feature requests ==
+
+Existing bugs and feature requests for [wiki:/En/Devel/TracBasicMacros TracBasicMacros] are
+[query:status=new|assigned|reopened&component=trac-basic-macros here].
+If you have any issues, please create a [/newticket?component=trac-basic-macros new ticket].
+
+

trac-dev/tracbm/TODO

+
+Outstanding tasks
+-----------------
+
+- XXX

trac-dev/tracbm/setup.cfg

+[egg_info]
+tag_build = 
+tag_date = 0
+tag_svn_revision = 0
+
+[sdist]
+formats = gztar,bztar,ztar,tar,zip

trac-dev/tracbm/setup.py

+#!/usr/bin/env python
+
+# Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+
+try:
+    from setuptools import setup
+except ImportError:
+    from distutils.core import setup
+
+from tracbm.__init__ import __doc__ as DESC
+
+versions = [
+    (1, 0, 0),
+    ]
+    
+latest = '.'.join(str(x) for x in versions[-1])
+
+status = {
+            'planning' :  "Development Status :: 1 - Planning",
+            'pre-alpha' : "Development Status :: 2 - Pre-Alpha",
+            'alpha' :     "Development Status :: 3 - Alpha",
+            'beta' :      "Development Status :: 4 - Beta",
+            'stable' :    "Development Status :: 5 - Production/Stable",
+            'mature' :    "Development Status :: 6 - Mature",
+            'inactive' :  "Development Status :: 7 - Inactive"
+         }
+dev_status = status["alpha"]
+
+cats = [
+    dev_status,
+    
+      "Environment :: Plugins", 
+      "Environment :: Web Environment", 
+      "Framework :: Trac", 
+      "Intended Audience :: Developers", 
+      "Intended Audience :: Information Technology", 
+      "Intended Audience :: Other Audience", 
+      "Intended Audience :: System Administrators", 
+      "License :: OSI Approved :: Apache Software License", 
+      "Operating System :: OS Independent", 
+      "Programming Language :: Python", 
+      "Programming Language :: Python :: 2.5", 
+      "Topic :: Internet :: WWW/HTTP :: Dynamic Content :: CGI Tools/Libraries", 
+      "Topic :: Internet :: WWW/HTTP :: HTTP Servers", 
+      "Topic :: Internet :: WWW/HTTP :: WSGI", 
+      "Topic :: Software Development :: Bug Tracking", 
+      "Topic :: Software Development :: Libraries :: Application Frameworks", 
+      "Topic :: Software Development :: Libraries :: Python Modules", 
+    ]
+
+# Be compatible with older versions of Python
+from sys import version
+if version < '2.2.3':
+    from distutils.dist import DistributionMetadata
+    DistributionMetadata.classifiers = None
+    DistributionMetadata.download_url = None
+
+# Add the change log to the package description.
+chglog = None
+try:
+    from os.path import dirname, join
+    chglog = open(join(dirname(__file__), "CHANGES"))
+    DESC+= ('\n\n' + chglog.read())
+finally:
+    if chglog:
+        chglog.close()
+
+DIST_NM = 'TracBasicMacros'
+PKG_INFO = {'tracbm' : ('tracbm',                     # Package dir
+                            # Package data
+                            ['../CHANGES', '../TODO', '../COPYRIGHT', 
+                              '../NOTICE', '../README'],
+                          ), 
+            }
+
+ENTRY_POINTS = r"""
+               [trac.plugins]
+               tracbm = tracbm
+               """
+
+setup(
+	name=DIST_NM,
+	version=latest,
+	description=DESC.split('\n', 1)[0],
+	author='Olemis Lang',
+	author_email='olemis+trac@gmail.com',
+	maintainer='Olemis Lang',
+	maintainer_email='olemis+trac@gmail.com',
+	url='https://opensvn.csie.org/traccgi/swlcu/wiki/En/Devel/%s' % (DIST_NM,),
+	download_url='http://pypi.python.org/packages/2.5/%s/%s/%s-%s-py2.5.egg' % \
+	                              (DIST_NM[0], DIST_NM, DIST_NM, latest,),
+	requires = ['trac',  'trac', ],
+  install_requires = [
+      'setuptools>=0.6b1',
+      'Trac>=0.11',
+  ],
+	package_dir = dict([p, i[0]] for p, i in PKG_INFO.iteritems()),
+	packages = PKG_INFO.keys(),
+	package_data = dict([p, i[1]] for p, i in PKG_INFO.iteritems()),
+	include_package_data=True,
+	provides = ['%s (%s)' % (p, latest) for p in PKG_INFO.keys()],
+	obsoletes = ['%s (>=%s.0.0, <%s)' % (p, versions[-1][0], latest) \
+	              for p in PKG_INFO.keys()],
+	entry_points = ENTRY_POINTS,
+	classifiers = cats,
+	long_description= DESC
+	)

trac-dev/tracbm/tracbm/__init__.py

+#!/usr/bin/env python
+# -*- coding: UTF-8 -*-
+
+# Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+
+r"""Simple but useful Trac macros
+
+Expand Trac capabilities by embed simple snippets in wiki pages using simple macros.
+
+Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
+Licensed under the Apache License
+"""
+__author__ = 'Olemis Lang'
+
+# Ignore errors to avoid Internal Server Errors
+from trac.core import TracError
+TracError.__str__ = lambda self: unicode(self).encode('ascii', 'ignore')
+
+try:
+    from tracbm.config import *
+    from tracbm.wiki import *
+    msg = 'Ok'
+except Exception, exc:
+#    raise
+    msg = "Exception %s raised: '%s'" % (exc.__class__.__name__, str(exc))

trac-dev/tracbm/tracbm/config.py

+
+# Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+
+r"""Insert configuration options in wiki pages
+
+Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
+Licensed under the Apache License
+"""
+__author__ = 'Olemis Lang'
+
+from trac.core import TracError
+from trac.resource import Resource
+from trac.util.datefmt import format_datetime, localtz
+from trac.util.text import to_unicode
+from trac.wiki.api import IWikiMacroProvider, WikiSystem, parse_args
+from trac.wiki.macros import WikiMacroBase
+from trac.wiki.model import WikiPage
+
+from genshi.builder import Element, tag
+
+class ConfigOptionMacro(WikiMacroBase):
+    r"""Insert configuration options in Wiki pages
+    
+    Usage is as follows.
+    
+    [[ConfigOption(section, name, type=option_type, sep=char)]]
+    
+    ''section'' :  the section in trac.ini (mandatory)
+    ''name'' :     option name (mandatory)
+    ''type'' :     if this keyword argument is present then 
+                   the value will be rendered using an
+                   appropriate format according to the option 
+                   type. Supported values are `text` (default),
+                   `bool`, `int`, `list`, `path`, `extension`.
+    ''sep'' :      list separator (otional, ignored if 
+                   `type`! = `list`)
+    """
+    def expand_macro(self, formatter, name, content):
+        # TODO: Implement `type` and `sep` options
+        # TODO: Permissions for sections and individual options
+        args, kw = parse_args(content)
+        opt_type, sep = [kw.get(k) for k in ('type', 'sep')]
+        try :
+            value = self.env.config.get(args[0], args[1])
+        except IndexError :
+            raise TracError('Section and option name are both needed')
+        else :
+            return value
+

trac-dev/tracbm/tracbm/wiki.py

+
+# Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
+#
+#   Licensed under the Apache License, Version 2.0 (the "License");
+#   you may not use this file except in compliance with the License.
+#   You may obtain a copy of the License at
+#
+#       http://www.apache.org/licenses/LICENSE-2.0
+#
+#   Unless required by applicable law or agreed to in writing, software
+#   distributed under the License is distributed on an "AS IS" BASIS,
+#   WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#   See the License for the specific language governing permissions and
+#   limitations under the License.
+
+
+r"""Display information about wiki pages
+
+Copyright 2009-2011 Olemis Lang <olemis at gmail.com>
+Licensed under the Apache License
+"""
+__author__ = 'Olemis Lang'
+
+from trac.core import TracError
+from trac.resource import Resource
+from trac.util.datefmt import format_datetime, localtz
+from trac.util.text import to_unicode
+from trac.wiki.api import IWikiMacroProvider, WikiSystem, parse_args
+from trac.wiki.macros import WikiMacroBase
+from trac.wiki.model import WikiPage
+
+from genshi.builder import Element, tag
+
+class WikiHistoryMacro(WikiMacroBase):
+    r"""Embed information about wiki changelog in wiki pages.
+    If invoked without keyword arguments then full 
+    changelog is shown inside a table with columns 
+    `Fecha`, `Version`, `Descripcion, `Autor`. Please  
+    read below for further details.
+    
+    Usage is as follows (all fields are optional).
+    
+    [[WikiHistory(pagename, version, attr=attr_name, cols=columns)]]
+    
+    ''pagename'' : the name of target Wiki page. If missing or empty 
+                   and a wiki page is being rendered then it defaults to 
+                   the current wiki page. If the page being rendered 
+                   doesn't belong in the Wiki then 'WikiStart' is used instead.
+    ''version'' :  consider changes prior to (and including) this version
+    ''attr'' :     if this keyword argument is present then only the value 
+                   of the version attribute identified by `attr_name` is 
+                   rendered in textual form (and `cols` argument is ignored)
+                   Supported values are `time`, `version`, 
+                   `comment`, and `author`
+    ''cols'' :     colon separated list of identifiers used to select 
+                   specific columns (order matters). Identifiers are 
+                   the same supported for `attr` parameter.
+    """
+    def expand_macro(self, formatter, name, content):
+        args, kw = parse_args(content)
+        attr, cols = [kw.get(k) for k in ('attr', 'cols')]
+        resource = formatter.context.resource
+        is_wiki = isinstance(resource, Resource) and resource.realm == 'wiki'
+        try :
+            pagename = args[0]
+        except IndexError :
+            if not is_wiki :
+                raise TracError('You must specify page name in this context')
+            page = WikiPage(self.env, resource, version=resource.version)
+        else :
+            pagename = pagename or (is_wiki and resource.id or 'WikiStart')
+            version = (args[1:2] or [None])[0]
+            page = WikiPage(self.env, pagename, version=version)
+        ATTR_LABELS = [u'Version', u'Fecha', u'Autor', u'Descripcion',]
+        ALL_ATTRS = ['version', 'time', 'author', 'comment']
+        
+        def format_verinfo(value, attridx):
+            return {
+                       1 : lambda x : tag.i(format_datetime(x, '%d/%m/%Y %H:%M:%S', tzinfo=localtz)), 
+                       0 : lambda x : tag.b(to_unicode(x, 'utf-8')), 
+                       3 : lambda x : to_unicode(x or '(No comments)', 'utf-8'),
+                       2 : lambda x : tag.i(to_unicode(x, 'utf-8')),
+                   }.get(attridx, lambda x : tag.i('Atributo desconocido') ) (value)
+        
+        if attr is None :
+            if cols :
+                cols = [ALL_ATTRS.index(x) for x in cols.split(':') if x in ALL_ATTRS ]
+            else :
+                cols = xrange(len(ALL_ATTRS))
+            def ver_row(verinfo):
+                return tag.tr([verinfo[c] for c in cols])
+            return tag.table(
+                            [tag.tr(
+                                    [tag.th(tag.i(h))
+                                        for h in (ATTR_LABELS[c] for c in cols)]
+                                   )] +
+                            [tag.tr(
+                                        [
+                                            tag.td(format_verinfo(x[c], c))
+                                                for c in cols]
+                                    ) for x in page.get_history()], 
+                            class_='wiki', align='center')
+        else :
+            try :
+                attridx = ALL_ATTRS.index(attr)
+            except ValueError :
+                raise TracError('Invalid attribute name %s' % (attr,))
+            else :
+                return format_verinfo(getattr(page, attr, None), attridx)
+
Add a comment to this file

trac-dev/tracbm/void/__init__.py

Empty file added.

Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.