Commits

Anonymous committed fae79cf Draft

Initial commit of a minimal implementation of the ListContent macro.

  • Participants

Comments (0)

Files changed (7)

+syntax: glob
+
+*.pyc
+*.egg-info
+.project
+.pydevproject
+.settings

morewikimacros/__init__.py

+import macros

morewikimacros/macros.py

+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2012 Ryan J Ollos <ryan.j.ollos@gmail.com>
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution.
+
+from genshi.builder import tag
+from trac.util.translation import _
+from trac.versioncontrol.api import NoSuchNode, RepositoryManager
+from trac.wiki.formatter import system_message
+from trac.wiki.macros import WikiMacroBase
+
+class ListContent(WikiMacroBase):
+    
+    def expand_macro(self, formatter, name, content):
+        if content:
+            fqpath = content
+        else:
+            return system_message(_('Error: Invalid usage'),
+                                  _('Repository path must be specified as the fist argument'))
+
+        repos_mgr = RepositoryManager(self.env)
+        repos_name, repos, path = repos_mgr.get_repository_by_path(fqpath) #0.12+ only
+        path, rev = _split_path(path)
+        if repos.has_node(path, rev):
+            node = repos.get_node(path, rev)
+            entries = [n for n in node.get_entries()
+                       if n.is_viewable(formatter.req.perm)]
+            if not entries:
+                return system_message(_('Error: Invalid usage'),
+                                      _("Listing files is not yet supported."))
+        else:
+            rev = rev or repos.get_youngest_rev()
+            raise NoSuchNode(path, rev)
+
+        list_items = [tag.li(tag.a(e.path,href=formatter.req.href('browser', e.path)))
+                      for e in entries]
+        return tag.div(tag.ul(list_items))
+
+def _split_path(fqpath):
+    if '@' in fqpath:
+        path, rev = fqpath.split('@', 1)
+    else:
+        path, rev = fqpath, None
+    return path, rev
+
+
+class WikiPage(WikiMacroBase):
+    
+    def expand_macro(self, formatter, name, content):
+        return system_message(_("WikiPage macro is not yet implemented.")) 
+    

morewikimacros/tests/__init__.py

+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2011 Odd Simon Simonsen <oddsimons@gmail.com>
+# Copyright (C) 2012 Ryan J Ollos <ryan.j.ollos@gmail.com>
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution.
+
+import unittest
+
+def test_suite():
+    suite = unittest.TestSuite()
+    
+    import morewikimacros.tests.macros
+    suite.addTest(morewikimacros.tests.macros.test_suite())
+    
+    return suite
+
+# Start test suite directly from command line like so:
+#   $> PYTHONPATH=$PWD python tractags/tests/__init__.py
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')

morewikimacros/tests/macros.py

+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2011 Odd Simon Simonsen <oddsimons@gmail.com>
+# Copyright (C) 2012 Ryan J Ollos <ryan.j.ollos@gmail.com>
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution.
+#
+
+import unittest
+
+from trac.test import EnvironmentStub
+from trac.wiki.tests import formatter
+
+from morewikimacros.macros import ListContent
+
+LISTCONTENT_TEST_CASES = u"""
+============================== # ListContent
+[[ListContent]]
+------------------------------
+<p>
+</p><div class="system-message"><strong>Error: Invalid usage</strong><pre>Repository path must be specified as the fist argument</pre></div><p>
+</p>
+------------------------------
+"""
+
+def listcontent_setup(tc):
+    tc.env = EnvironmentStub(enable=['trac.*', 'morewikimacros.*'])
+
+def listcontent_teardown(tc):
+    tc.env.reset_db()
+
+def test_suite():
+    suite = unittest.TestSuite()
+    suite.addTest(formatter.suite(LISTCONTENT_TEST_CASES, listcontent_setup,
+                                  __file__, listcontent_teardown))
+    return suite
+
+if __name__ == '__main__':
+    unittest.main(defaultTest='test_suite')
+[egg_info]
+tag_build = dev
+tag_svn_revision = true
+#!/usr/bin/env python
+# -*- coding: utf-8 -*-
+#
+# Copyright (C) 2012 Ryan J Ollos <ryan.j.ollos@gmail.com>
+# All rights reserved.
+#
+# This software is licensed as described in the file COPYING, which
+# you should have received as part of this distribution.
+
+from setuptools import setup
+
+setup(
+    name = "MoreWikiMacros",
+    version = 0.1,
+    packages = ['morewikimacros'],
+    author = "Ryan J Ollos",
+    author_email = "ryan.j.ollos@gmail.com",
+    maintainer = "Ryan J Ollos",
+    maintainer_email = 'ryan.j.ollos@gmail.com',
+    description = "A collection of wiki macros that should be generally useful",
+    license = "BSD 3-Clause",
+    keywords = "trac macro uml plantuml embed include",
+    url = "http://trac-hacks.org/wiki/MoreWikiMacrosPlugin",
+    entry_points = {
+        "trac.plugins": [
+            "morewikimacros = morewikimacros"
+        ]
+    },
+    test_suite = 'morewikimacros.tests.test_suite',
+    tests_require = []
+)