wikitablemacro-0.3/0000755000000000000000000000000013206316763013056 5ustar rootrootwikitablemacro-0.3/README.txt0000644000000000000000000000107712065042127014551 0ustar rootroot================= Wiki Table Plugin ================= This plugin allows you to query the Trac database with a SQL query and display the results as a table in a wiki page. Usage:: {{{ #!SQLTable SELECT count(id) as 'Number of Tickets' FROM ticket }}} This will create a table with one row and one column. You can obviously create more complex queries as you wish. Installation ------------ Install as normal, using easy_install or 'python setup.py install'. Then add this to trac.ini:: [components] wikitable.* = enabledwikitablemacro-0.3/setup.cfg0000644000000000000000000000003513204422454014666 0ustar rootroot#[egg_info] #tag_build = dev wikitablemacro-0.3/COPYING0000644000000000000000000000272312511341364014106 0ustar rootrootCopyright (C) 2008 Martin Aspeli Copyright (C) 2012-2015 Ryan J Ollos 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. wikitablemacro-0.3/setup.py0000644000000000000000000000167513204422454014572 0ustar rootroot#!/usr/bin/env python # -*- coding: utf-8 -*- # # Copyright (C) 2008 Martin Aspeli # Copyright (C) 2012-2015 Ryan J Ollos # 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='WikiTableMacro', author='Martin Aspeli', author_email='optilude@gmail.com', maintainer='Ryan J Ollos', maintainer_email='ryan.j.ollos@gmail.com', description='Trac plugin for drawing a table from a SQL query in wiki text', url='https://trac-hacks.org/wiki/WikiTableMacro', version='0.3', license='3-Clause BSD', packages=['wikitable'], package_data={'wikitable': ['htdocs/css/*.css']}, entry_points={ 'trac.plugins': [ 'wikitable.table = wikitable.table', 'wikitable.scalar = wikitable.scalar' ] }, ) wikitablemacro-0.3/wikitable/0000755000000000000000000000000013204422454015022 5ustar rootrootwikitablemacro-0.3/wikitable/__init__.py0000644000000000000000000000007212511341364017132 0ustar rootrootimport pkg_resources pkg_resources.require('Trac >= 1.0') wikitablemacro-0.3/wikitable/table.py0000644000000000000000000000451013204422454016463 0ustar rootroot# -*- coding: utf-8 -*- # # Copyright (C) 2008 Martin Aspeli # Copyright (C) 2012-2015 Ryan J Ollos # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. # from trac.core import implements from trac.db.api import get_column_names from trac.web.chrome import ITemplateProvider, add_stylesheet from trac.wiki.formatter import format_to_html, system_message from trac.wiki.macros import WikiMacroBase from trac.util.text import exception_to_unicode, to_unicode from trac.util.translation import _ from trac.util.html import html as tag class SQLTable(WikiMacroBase): """Draw a table from a SQL query in a wiki page. Examples: {{{ {{{ #!SQLTable SELECT count(id) as 'Number of Tickets' FROM ticket }}} }}} """ implements(ITemplateProvider) # ITemplateProvider methods def get_templates_dirs(self): return [] def get_htdocs_dirs(self): from pkg_resources import resource_filename return [('wikitable', resource_filename(__name__, 'htdocs'))] # IWikiMacroBase methods def expand_macro(self, formatter, name, content): def format(item): if item is None: item = "//(NULL)//" elif item in (True, False): item = str(item).upper() elif not isinstance(item, basestring): item = to_unicode(item) return format_to_html(self.env, formatter.context, item) try: with self.env.db_query as db: cursor = db.cursor() cursor.execute(content) rows = cursor.fetchall() cols = get_column_names(cursor) except self.env.db_exc.DatabaseError, e: return system_message(_("Invalid SQL"), exception_to_unicode(e)) add_stylesheet(formatter.req, 'wikitable/css/wikitable.css') return tag.table(tag.thead(tag.tr(tag.th(c) for c in cols)), tag.tbody(tag.tr((tag.td(format(c)) for c in row), class_='even' if idx % 2 else 'odd') for idx, row in enumerate(rows)), class_='listing wikitable') wikitablemacro-0.3/wikitable/scalar.py0000644000000000000000000000236213204422454016644 0ustar rootroot# -*- coding: utf-8 -*- # # Copyright (C) 2008 Martin Aspeli # Copyright (C) 2012-2105 Ryan J Ollos # All rights reserved. # # This software is licensed as described in the file COPYING, which # you should have received as part of this distribution. # from trac.web.chrome import add_stylesheet from trac.wiki.formatter import system_message from trac.wiki.macros import WikiMacroBase from trac.util.html import html as tag from trac.util.text import exception_to_unicode from trac.util.translation import _ class SQLScalar(WikiMacroBase): """Output a number from a scalar (1x1) SQL query. Examples: {{{ {{{ #!SQLScalar SELECT count(id) as 'Number of Tickets' FROM ticket }}} }}} """ # IWikiMacroBase methods def expand_macro(self, formatter, name, content): try: rows = self.env.db_query(content) except self.env.db_exc.DatabaseError, e: return system_message(_("Invalid SQL"), exception_to_unicode(e)) else: value = rows[0][0] if len(rows) else "(NULL)" add_stylesheet(formatter.req, 'wikitable/css/wikitable.css') return tag.span(value, class_='wikiscalar') wikitablemacro-0.3/wikitable/htdocs/0000755000000000000000000000000012542111007016277 5ustar rootrootwikitablemacro-0.3/wikitable/htdocs/css/0000755000000000000000000000000012542111007017067 5ustar rootrootwikitablemacro-0.3/wikitable/htdocs/css/wikitable.css0000644000000000000000000000013412542111007021552 0ustar rootroottable.wikitable { width: auto; } table.wikitable td p { margin-top: 0; margin-bottom: 0; }