Ticket #2801 (closed enhancement: fixed)

Opened 5 years ago

Last modified 10 months ago

CSV Support for 0.11

Reported by: sagacis@gmail.com Assigned to: rjollos
Priority: normal Component: CsvMacro
Severity: normal Keywords:
Cc: g1itch Trac Release: 0.11

Description

I changed the file slightly to make it work as a plugin for 0.11, as seen below.

from trac.wiki.macros import WikiMacroBase
from trac.util import escape
import csv

class CsvMacro(WikiMacroBase):

    def get_macros(self):
        yield 'CSV'

    def get_macro_description(self, name):
       return inspect.getdoc(CsvMacro)

    def expand_macro(self, formatter, name, txt):
        sniffer = csv.Sniffer()
        txt = txt.encode('ascii', 'replace')
        reader = csv.reader(StringIO(txt), sniffer.sniff(txt))
        formatter.out.write('<table class="wiki">\n')
        for row in reader:
            formatter.out.write('<tr>')
            for col in row:
                formatter.out.write('<td>%s</td>' % escape(col))
            formatter.out.write('</tr>\n')
        formatter.out.write('</table>\n')

Attachments

CSV-0.11.zip (1.3 kB) - added by kennethxu on 09/29/08 00:26:17.
As installable plugin
CSV.py (1.0 kB) - added by rjollos on 07/29/12 03:56:20.
CSV_0.11.py (0.7 kB) - added by rjollos on 07/29/12 03:56:38.

Change History

08/31/08 08:19:45 changed by marianp@el.onet.pl

In code above on begin missing:

from StringIO import StringIO

08/31/08 09:40:57 changed by marianp@el.onet.pl

And finally a this moment for 0.11 and 0.12dev:

from trac.wiki.macros import WikiMacroBase
from trac.util import escape
from StringIO import StringIO
import csv

class CsvMacro(WikiMacroBase):
    """
    Display CSV data in a table. Simply copy and paste the CSV data into the macro body and hope for the best.

    Example:
    {{{
    {{{
    #!CSV
    123	123	123	123
    234	234	234	234
    }}}
    }}}
    Renders as

    || 123 || 123 || 123 || 123 ||
    || 234 || 234 || 234 || 234 ||
     """
       
    def get_macros(self):
        yield 'CSV'

    def expand_macro(self, formatter, name, txt):
        sniffer = csv.Sniffer()
        txt = txt.encode('ascii', 'replace')
        reader = csv.reader(StringIO(txt), sniffer.sniff(txt))
        formatter.out.write('<table class="wiki">\n')
        for row in reader:
            formatter.out.write('<tr>')
            for col in row:
                formatter.out.write('<td>%s</td>' % escape(col))
            formatter.out.write('</tr>\n')
        formatter.out.write('</table>\n')

09/28/08 23:57:14 changed by kennethxu

Somehow I still couldn't get 0.11 to pickup the macro that I added to the plugins directory. So again I packed it as a real plugin and attached to the ticket, you can install it using:

easy_install http://trac-hacks.org/attachment/ticket/2801/CSV-0.11.zip?format=raw

09/29/08 00:26:17 changed by kennethxu

  • attachment CSV-0.11.zip added.

As installable plugin

(in reply to: ↑ description ; follow-up: ↓ 5 ) 06/09/10 23:03:43 changed by g1itch

  • cc set to g1itch.

Replying to sagacis@gmail.com:

So why don't you commit this code into repository? This plugin works good even for trac-0.12.

(in reply to: ↑ 4 ) 06/10/10 16:25:46 changed by anonymous

Replying to g1itch:

Replying to sagacis@gmail.com: So why don't you commit this code into repository? This plugin works good even for trac-0.12.

Because he doesn't have permission to commit most likely!

06/14/10 03:10:36 changed by anonymous

Yup. I don't have access and submitted that plugin over two years ago. Feel free to commit, modify or otherwise use that code.

07/29/12 03:56:20 changed by rjollos

  • attachment CSV.py added.

07/29/12 03:56:38 changed by rjollos

  • attachment CSV_0.11.py added.

07/29/12 03:57:19 changed by rjollos

  • status changed from new to assigned.
  • owner changed from athomas to rjollos.

Added two files that were attached to the project's wiki page.

07/29/12 03:58:32 changed by rjollos

  • status changed from assigned to closed.
  • resolution set to fixed.

(In [11827]) Fixes #2801: Added macro that supports Trac 0.11.


Add/Change #2801 (CSV Support for 0.11)




Change Properties
Action