Ticket #6374 (closed enhancement: fixed)
Opened 5 years ago
Last modified 2 years ago
get rid of macros.html in favor of xi:include'd snippets
| Reported by: | Dave Gynn <dgynn@…> | Owned by: | rblank |
|---|---|---|---|
| Priority: | normal | Milestone: | 0.12 |
| Component: | rendering | Version: | devel |
| Severity: | normal | Keywords: | genshi needmajor |
| Cc: | mmitar@… | ||
| 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
Change History
Changed 5 years ago by Dave Gynn <dgynn@…>
- Attachment trac-site-macros.diff added
Changed 5 years ago by Dave Gynn <dgynn@…>
- Attachment trac-attachment-macros.diff added
comment:1 Changed 5 years ago by cboos
- Keywords genshi added
- Milestone set to 0.11
comment:2 Changed 5 years ago by cboos
- Component changed from general to rendering
- Owner changed from jonas to cboos
comment:3 Changed 5 years ago by Dave Gynn <dgynn@…>
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 Changed 4 years ago by cboos
Will perhaps make it for 0.11, but not for beta1.
In the meantime, I added a warning (r6251).
comment:5 Changed 4 years ago by cboos
- Milestone changed from 0.11 to 0.12
I guess this will have to wait a bit longer.
comment:6 Changed 3 years ago by cboos
- Keywords needmajor added
- Milestone changed from 0.13 to 0.12
Would be nice to get rid of macros.html…
comment:8 Changed 2 years ago by cboos
- Summary changed from [PATCH] Provide a cleaner way to override macros to get 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 Changed 2 years ago by rblank
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 Changed 2 years ago by rblank
- Resolution set to fixed
- Status changed from new to closed
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 Changed 2 years ago by rblank
- Owner changed from cboos to rblank
comment:12 follow-up: ↓ 13 Changed 2 years ago by 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?
comment:13 in reply to: ↑ 12 Changed 2 years ago by rblank
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.



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.