Commits

mitar committed b8452d9

Added some macros wrapping Django tags.

Comments (0)

Files changed (2)

cmsplugin_markup_tracwiki/macros.py

+from trac.wiki import macros
+
+from django import template
+from django.template import defaulttags
+
+class DjangoTagMacroBase(macros.WikiMacroBase):
+    def expand_macro(self, formatter, name, content):
+        tag = getattr(defaulttags, self.django_tag_name)
+        node = tag(template.Parser(''), template.Token(template.TOKEN_BLOCK, "%s %s" % (self.django_tag_name, content)))
+        return node.render(template.Context({}))
+
+    def get_macros(self):
+        yield self.django_tag_name
+
+class URLMacro(DjangoTagMacroBase):
+    """Wrapper around Django's `url` template tag.
+
+    For more information on how to use it and of its syntax please refer to
+    [http://docs.djangoproject.com/en/dev/ref/templates/builtins/#url Django documentation].
+
+    Using it with `as` does not really do anything useful.
+
+    Examples:
+
+    {{{
+        [[url(path.to.some_view v1 v2)]]
+        [[url(path.to.some_view arg1=v1 arg2=v2)]]
+    }}}
+    """
+
+    # TODO: Retain the same Django context through whole rendering of wiki content? So that "as" could work? But what then, it should be possible to output it somehow, too.
+
+    django_tag_name = 'url'
+
+class NowMacro(DjangoTagMacroBase):
+    """Wrapper around Django's `now` template tag.
+
+    For more information on how to use it and of its syntax please refer to
+    [http://docs.djangoproject.com/en/dev/ref/templates/builtins/#now Django documentation].
+
+    Format string should be quoted.
+
+    Examples:
+
+    {{{
+        [[now("jS F Y H:i")]]
+        [[now("jS o\\f F")]]
+    }}}
+    """
+ 
+    django_tag_name = 'now'

cmsplugin_markup_tracwiki/tracwiki.py

     'trac.wiki.macros.ImageMacro',
     'trac.wiki.macros.PageOutlineMacro',
     'cmsplugin_markup_tracwiki.tracwiki.DjangoResource',
+    'cmsplugin_markup_tracwiki.macros.URLMacro',
+    'cmsplugin_markup_tracwiki.macros.NowMacro',
 ]
 
 TRACWIKI_HEADER_OFFSET = 1
     def get_link_resolvers(self):
         yield ('cms', self._format_link)
 
-# TODO: Use content from filer for [[Image]] and attachments (attachments could be file and image plugins in the same placeholder)
+# TODO: Add a filer namespace (what should be the key by which to relate to the file?)
+# TODO: Make a macro similar to [[Image]] but which uses filer, but should also support thumbnail tag (or do another one for that?)
+# TODO: In admin some GUI way to select files/images from filer should be made (one to select (file) URL, the other to select [[Image]] macro), similar to how integration with rich-text editor is made
 # TODO: Relative links [..] should traverse Django CMS hierarchy
 # TODO: Make Trac and Django CMS caching interoperate (how does dynamic macros currently behave?)
 # TODO: Does request really have URL we want (for example in admin URL is not the URL of a resulting page)
-# TODO: Wrap some Django template tags into macros (url for example)
+# TODO: Do we really need to use href() or should we just use Django URLs directly (as we configure href() with Django base URL anyway)
+# TODO: When using django-reversion, add an option to compare versions of plugin content and display it in the same way as Trac does
 
 class Markup(object):
     name = 'Trac wiki'