Modify

Opened 16 years ago

Closed 7 years ago

#4004 closed enhancement (fixed)

Wiki formatted content from repository

Reported by: kgabor@… Owned by: Ryan J Ollos
Priority: normal Component: IncludeMacro
Severity: normal Keywords:
Cc: Trac Release: 0.11

Description

I'd like to include some dynamic table content on wiki pages. These files are stored in subversion repository and most easily are formatted as Trac wiki tables. (generated from CSV files) I checked IncludeMacro and it seems that wiki content can be included only from other wiki pages but not from external source or repository files. Thanks.

Attachments (0)

Change History (7)

comment:1 Changed 16 years ago by Noah Kantrowitz

Resolution: worksforme
Status: newclosed

Use the MIME type text/x-trac-wiki.

comment:2 Changed 7 years ago by anonymous

I have Trac 1.0.9 and TracIncludeMacro 3.1.0 and I have exactly the same problem as described in this ticket's description - I have a file in repository (hg) containing wiki-formatted table, for example:

xy.wiki.txt

|| a || b ||
|| 1 || 2 ||

and I try to include it with:

[[Include(source:abc/xy.wiki.txt, text/x-trac-wiki)]]

but it shows only the "wiki source" (exactly as above) not a formatted table. I even tried enabling "render_unsafe_content", but it changes nothing.

And there is nothing relevant in trac's log, except for:

...
2017-08-11 16:26:30,151 Trac[formatter] DEBUG: Executing Wiki macro Include by provider <includemacro.macros.IncludeMacro object at 0x7fdc3c126b10>
...

comment:3 Changed 7 years ago by anonymous

Resolution: worksforme
Status: closedreopened

comment:4 Changed 7 years ago by anonymous

I made a temporary "hack" to make it work - I know it's not a proper fix, but it solved my problem - here's a diff against 3.1.0 version, maybe it may help someone:

--- 3.1.0/includemacro/macros.py 2017-04-01 11:20:11.000000000 +0200
+++ hack/includemacro/macros.py 2017-08-11 17:38:22.000000000 +0200
@@ -3,6 +3,7 @@
 # Copyright (C) 2007-2008 Noah Kantrowitz <noah@coderanger.net>
 # Copyright (C) 2012 Ryan J Ollos <ryan.j.ollos@gmail.com>
 # Copyright (C) 2014 Steffen Hoffmann <hoff.st@web.de>
 # All rights reserved.
 #
 # This software is licensed as described in the file COPYING, which
@@ -50,11 +51,14 @@
         args = [x.strip() for x in content.split(',')]
         if len(args) == 1:
             args.append(None)
-        elif len(args) != 2:
+            args.append(None)
+        elif len(args) == 2:
+            args.append(None)
+        elif len(args) != 3:
             return system_message('Invalid arguments "%s"' % content)
 
         # Pull out the arguments.
-        source, dest_format = args
+        source, dest_format, raw = args
         try:
             source_format, source_obj = source.split(':', 1)
         except ValueError:  # If no : is present, assume its a wiki page.
@@ -139,7 +148,7 @@
             if 'FILE_VIEW' not in formatter.perm:
                 return ''
             out, ctxt, dest_format = self._get_source(formatter, source_obj,
-                                                      dest_format)
+                                                      dest_format, raw)
         elif source_format == 'ticket':
             if ':' in source_obj:
                 ticket_num, source_obj = source_obj.split(':', 1)
@@ -204,7 +213,7 @@
 
     # Private methods
 
-    def _get_source(self, formatter, source_obj, dest_format):
+    def _get_source(self, formatter, source_obj, dest_format, raw):
         repos_mgr = RepositoryManager(self.env)
         try:  # 0.12+
             repos_name, repos, source_obj = \
@@ -222,8 +231,14 @@
         if content:
             out = content.read()
             if dest_format is None:
-                dest_format = node.content_type or get_mimetype(path, out)
-            ctxt = Context.from_request(formatter.req, 'source', path)
+                if raw is None:
+                    dest_format = node.content_type or get_mimetype(path, out)
+                else:
+                    dest_format = 'text/x-trac-wiki'
+            if raw is not None:
+                ctxt = Context.from_request(formatter.req, 'wiki', path)
+            else:
+                ctxt = Context.from_request(formatter.req, 'source', path)
 
         return out, ctxt, dest_format

comment:5 Changed 7 years ago by Ryan J Ollos

Owner: changed from Noah Kantrowitz to Ryan J Ollos
Status: reopenedaccepted

comment:6 Changed 7 years ago by Ryan J Ollos

In 17156:

TracIncludeMacro 3.2.0dev: Use web_context

Refs #4004.

comment:7 Changed 7 years ago by Ryan J Ollos

Resolution: fixed
Status: acceptedclosed

In 17157:

TracIncludeMacro 3.2.0dev: Fix regression in r15552

The regression prevented specifying the mimetype
when rendering a file from the repository.

Closes #4004, Refs #12778.

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.