Modify

Opened 17 years ago

Closed 12 years ago

Last modified 11 years ago

#2801 closed enhancement (fixed)

CSV Support for 0.11

Reported by: sagacis@… Owned by: Ryan J Ollos
Priority: normal Component: CsvMacro
Severity: normal Keywords:
Cc: Dmitri 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 (3)

CSV-0.11.zip (1.3 KB) - added by Kenneth Xu 16 years ago.
As installable plugin
CSV.py (1.0 KB) - added by Ryan J Ollos 12 years ago.
CSV_0.11.py (763 bytes) - added by Ryan J Ollos 12 years ago.

Download all attachments as: .zip

Change History (11)

comment:1 Changed 16 years ago by marianp@…

In code above on begin missing:

from StringIO import StringIO

comment:2 Changed 16 years ago by marianp@…

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')

comment:3 Changed 16 years ago by Kenneth Xu

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/raw-attachment/ticket/2801/CSV-0.11.zip
Last edited 11 years ago by Ryan J Ollos (previous) (diff)

Changed 16 years ago by Kenneth Xu

Attachment: CSV-0.11.zip added

As installable plugin

comment:4 in reply to:  description ; Changed 14 years ago by Dmitri

Cc: Dmitri added; anonymous removed

Replying to sagacis@gmail.com:

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

comment:5 in reply to:  4 Changed 14 years ago 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!

comment:6 Changed 14 years ago 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.

Changed 12 years ago by Ryan J Ollos

Attachment: CSV.py added

Changed 12 years ago by Ryan J Ollos

Attachment: CSV_0.11.py added

comment:7 Changed 12 years ago by Ryan J Ollos

Owner: changed from Alec Thomas to Ryan J Ollos
Status: newassigned

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

comment:8 Changed 12 years ago by Ryan J Ollos

Resolution: fixed
Status: assignedclosed

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

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Ryan J Ollos.
The resolution will be deleted. Next status will be 'reopened'.

Add Comment


E-mail address and name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.