Permalink
Browse files

new GenshiMacro hack

  • Loading branch information...
0 parents commit 0e80b758efdd126cf46c27ff2e360b34129ff442 @ejucovy committed Apr 2, 2012
Showing with 124 additions and 0 deletions.
  1. +7 −0 .gitignore
  2. +28 −0 LICENSE.txt
  3. +1 −0 README.rst
  4. +49 −0 README.txt
  5. +12 −0 genshimacro/__init__.py
  6. +27 −0 setup.py
7 .gitignore
@@ -0,0 +1,7 @@
+*~
+*.pyc
+.#*
+#*
+*#
+*.egg-info
+dist/
28 LICENSE.txt
@@ -0,0 +1,28 @@
+Copyright (C) 2012 Ethan Jucovy
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+
+ 1. Redistributions of source code must retain the above copyright
+ notice, this list of conditions and the following disclaimer.
+ 2. Redistributions in binary form must reproduce the above copyright
+ notice, this list of conditions and the following disclaimer in
+ the documentation and/or other materials provided with the
+ distribution.
+ 3. The name of the author may not be used to endorse or promote
+ products derived from this software without specific prior
+ written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
+OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
+DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
+DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE
+GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
+IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
+OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN
+IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
1 README.rst
49 README.txt
@@ -0,0 +1,49 @@
+Genshi processor for wiki pages
+===============================
+
+Description
+-----------
+
+The GenshiMacro allows you to write and render Genshi templates directly
+in wiki pages with a new ``Genshi`` processor.
+
+Your templates will have access to the request as ``req``, which can be
+useful for tasks like URL generation, rendering form tokens for POST
+requests, and checking for a logged-in user.
+
+'''Note: no security considerations whatsoever went into the making of
+this plugin. It might be a terrible idea. If you happen to know that
+it is, please let me know.'''
+
+Configuration and Usage
+-----------------------
+
+To use the plugin, install it in your Trac environment and enable its
+components in ``trac.ini``::
+
+ [components]
+ genshimacro.* = enabled
+
+You can then write Genshi templates directly in wiki pages like so::
+
+ {{{
+ #!Genshi
+ <div xmlns:py="http://genshi.edgewall.org/">
+ <py:choose>
+ <py:when test="req.session.authenticated">
+ <form method="POST" action="${req.href.newticket()}">
+ <input type="text" name="field_summary" placeholder="My new ticket"
+ id="field-summary" />
+ <input type="hidden" name="__FORM_TOKEN" value="${req.form_token}" />
+ <input type="submit" />
+ </form>
+ </py:when>
+ <py:otherwise>
+ <b>To file a new ticket, you'll need to
+ <a href="${req.href.login()}">log in</a> or
+ <a href="${req.href.register()}">create an account</a>
+ first.</b>
+ </py:otherwise>
+ </py:choose>
+ </div>
+ }}}
12 genshimacro/__init__.py
@@ -0,0 +1,12 @@
+from genshi.template import MarkupTemplate
+from trac.core import *
+from trac.web.chrome import Chrome
+from trac.wiki.macros import WikiMacroBase
+
+class GenshiMacro(WikiMacroBase):
+
+ def expand_macro(self, formatter, name, text, args):
+ template = MarkupTemplate(text)
+ chrome = Chrome(self.env)
+ return template.generate(**chrome.populate_data(formatter.req, {}))
+
27 setup.py
@@ -0,0 +1,27 @@
+from setuptools import find_packages, setup
+
+version='0.1'
+
+try:
+ long_description = open("README.txt").read()
+except:
+ long_description = ''
+
+setup(name='trac-GenshiMacro',
+ version=version,
+ description="Write Genshi templates in Trac wiki pages",
+ long_description=long_description,
+ author='Ethan Jucovy',
+ author_email='ejucovy@gmail.com',
+ url='http://trac-hacks.org/wiki/GenshiMacro',
+ keywords='trac plugin',
+ license="BSD",
+ packages=find_packages(exclude=['ez_setup', 'examples', 'tests*']),
+ include_package_data=True,
+ zip_safe=False,
+ entry_points = """
+ [trac.plugins]
+ genshimacro = genshimacro
+ """,
+ )
+

0 comments on commit 0e80b75

Please sign in to comment.