Edgewall Software
Modify

Opened 12 years ago

Closed 10 years ago

Last modified 5 years ago

#6374 closed enhancement (fixed)

get rid of macros.html in favor of xi:include'd snippets

Reported by: Dave Gynn <dgynn@…> Owned by: Remy Blank
Priority: normal Milestone: 0.12
Component: rendering Version: devel
Severity: normal Keywords: genshi needmajor
Cc: mmitar@… Branch:
Release Notes:
API Changes:

Description

I needed a way to modify the generated list of attachments in 0.11. Currently the best way to do that seems to be to put a customized version of macros.html in a site's templates directory. I'd prefer not to fork that whole file for a minor change. What I'd rather do is override the macro definitions before they are called.

One solution to this is to add a site_macros.html file, similar to the site.html file used by layout.html. site_macros.html could be included by macros.html and allow a site to override and customize the macro. I've attached a patch to do that simple include.

Additionally, the current show_one_attachment() macro is nested in list_of_attachments() which makes it difficult to override. I've attached a second patch that reorganizes the macro definitions so you can override just show_one_attachment() by itself.

Either or both of these patches will make it easier to customize the output of the macros.

Attachments (2)

trac-site-macros.diff (560 bytes ) - added by Dave Gynn <dgynn@…> 12 years ago.
trac-attachment-macros.diff (1.5 KB ) - added by Dave Gynn <dgynn@…> 12 years ago.

Download all attachments as: .zip

Change History (19)

by Dave Gynn <dgynn@…>, 12 years ago

Attachment: trac-site-macros.diff added

by Dave Gynn <dgynn@…>, 12 years ago

Attachment: trac-attachment-macros.diff added

comment:1 by Christian Boos, 12 years ago

Keywords: genshi added
Milestone: 0.11

Well, actually what we're going to do is to remove the macros completely and use instead snippets to be <py:include>d. It could also make your use case (overriding) easier to achieve, even if in that specific case (override the show_one_attachment part), a template filter might be more appropriate (have a look at source:trunk/sample-plugins/ticket_clone.py@6153).

cmlenz told me that he's even considering removing the <py:def> altogether in future Genshi releases.

It might be nice to get this done before 0.11, so people wouldn't expect the macros to be there, or at the very least add a warning there…

We need a "rendering" component, btw.

comment:2 by Christian Boos, 12 years ago

Component: generalrendering
Owner: changed from Jonas Borgström to Christian Boos

comment:3 by Dave Gynn <dgynn@…>, 12 years ago

Great. Breaking up the macros into includes would make things easier to override.

I had thought about using a template filter, or <py:match> to modify the content after it had been generated. But specifically with attachments there isn't a good path to match to get the rendered list of attachments.

If the H3 and UL for the attachments on the wiki page were wrapped in a <div id="attachmentlist"> it would be easier to do that. The "not compact" attachment list does have a div with id="attachments" but it comes after the <h2>Attachments</h2>.

What would be the best way to get more structural XHTML markup information available for Genshi filters to act against?

comment:4 by Christian Boos, 12 years ago

Will perhaps make it for 0.11, but not for beta1.

In the meantime, I added a warning (r6251).

comment:5 by Christian Boos, 12 years ago

Milestone: 0.110.12

I guess this will have to wait a bit longer.

comment:6 by Christian Boos, 10 years ago

Keywords: needmajor added
Milestone: 0.130.12

Would be nice to get rid of macros.html…

comment:7 by Mitar, 10 years ago

Cc: mmitar@… added

+1

comment:8 by Christian Boos, 10 years ago

Summary: [PATCH] Provide a cleaner way to override macrosget rid of macros.html in favor of xi:include'd snippets

Note that as we get more templates, we should probably increase the default Genshi template loader cache size.

comment:9 by Remy Blank, 10 years ago

The default size of the template cache was increased from 25 to 128 in [9251]. We currently have 65 templates on trunk, and the cache gets quickly filled to 50 or so just by clicking around in my test environment. Considering most people install at least a few plugins, 128 seems like a reasonable value (it's maybe a bit high, but I would be surprised if templates took that much memory, and people with memory constraints can easily lower the value).

Next I'll see if I can reasonably get rid of macros.html altogether.

comment:10 by Remy Blank, 10 years ago

Resolution: fixed
Status: newclosed

Removed all uses of the macros in macros.html and macros.rss in [9260]. The files are kept for backward compatibility (until 0.13), and <xi:include> the snippets (a very nice idea by osimons).

comment:11 by Remy Blank, 10 years ago

Owner: changed from Christian Boos to Remy Blank

comment:12 by Mitar, 10 years ago

So now it is enough just to change one small snippet, for example to change generated list of attachments, and not complete macros.html? And one can change this snippet by overriding it with a custom version with a file in templates dir?

in reply to:  12 comment:13 by Remy Blank, 10 years ago

Replying to Mitar:

So now it is enough just to change one small snippet, for example to change generated list of attachments, and not complete macros.html? And one can change this snippet by overriding it with a custom version with a file in templates dir?

Yes, this should be the case. Please let us know if that doesn't work for you.

in reply to:  10 comment:14 by Ryan J Ollos, 5 years ago

Replying to rblank:

Removed all uses of the macros in macros.html and macros.rss in [9260]. The files are kept for backward compatibility (until 0.13), and <xi:include> the snippets (a very nice idea by osimons).

In comment:15:ticket:11494 I've proposed to remove the files for Trac 1.1.2.

comment:15 by Christian Boos, 5 years ago

Looks like [12889] could have left a prevnext_nav.html snippet behind…

in reply to:  15 ; comment:16 by Ryan J Ollos, 5 years ago

Replying to cboos:

Looks like [12889] could have left a prevnext_nav.html snippet behind…

Is that used by a plugin? I thought it should be replaced by: trunk/trac/web/chrome.py@13203:221#L212.

in reply to:  16 comment:17 by Christian Boos, 5 years ago

Replying to rjollos:

Replying to cboos:

Looks like [12889] could have left a prevnext_nav.html snippet behind…

Is that used by a plugin? I thought it should be replaced by: trunk/trac/web/chrome.py@13203:221#L212.

You're right, this should probably do… the only thing we'll lose in the SpamFilter (#11807) is the prev/next links duplicated at the bottom of the page.

Modify Ticket

Change Properties
Set your email in Preferences
Action
as closed The owner will remain Remy Blank.
The resolution will be deleted. Next status will be 'reopened'.
to as closed The owner will be changed from Remy Blank to the specified user.

Add Comment


E-mail address and name can be saved in the Preferences .
 
Note: See TracTickets for help on using tickets.