Opened 12 years ago
Closed 11 years ago
#11126 closed enhancement (fixed)
Some templates could override layout (and theme) stylesheets with own stylesheets
Reported by: | Owned by: | ||
---|---|---|---|
Priority: | normal | Milestone: | 1.1.2 |
Component: | rendering | Version: | 1.0.1 |
Severity: | trivial | Keywords: | layout template stylesheet css |
Cc: | Branch: | ||
Release Notes: |
All stylesheets are added using |
||
API Changes: |
|
||
Internal Changes: |
Description
Some templates put css stylesheets after layout stylesheets. That means that templates stylesheets can override styles defined in themes. Other templates add their own stylesheets through add_stylesheet
. In this way layout stylesheets are written in head
tag after them (so they override styles). I think that the last behavior is the valid one (and the first one is due to changes not yet committed).
Templates that I can see with ¿old behavior?:
- /trac/prefs/templates/prefs_pygments.html
- trac/templates/about.html
- trac/templates/error.html
- trac/templates/diff_view.html
- trac/ticket/templates/milestone_delete.html
- trac/ticket/templates/milestone_edit.html
I have attached a patch that change some (error.html
and prefs_pygments.html
are too complex for me) of these templates to add_stylesheet
behavior.
Attachments (2)
Change History (17)
by , 12 years ago
Attachment: | layout.patch added |
---|
comment:1 by , 12 years ago
Type: | defect → enhancement |
---|
I'm deeply wrong. Add stylesheet in template doesn't conflict with official way to use themes. Only affects when using ThemeEnginePlugin. I've changed Type form bug to enhancement since is not a bug (but I hope that the change can be accepted). Sorry for that.
comment:2 by , 12 years ago
Cc: | added |
---|
comment:3 by , 11 years ago
Cc: | removed |
---|---|
Milestone: | → next-dev-1.1.x |
Owner: | set to |
Status: | new → assigned |
follow-ups: 6 9 comment:5 by , 11 years ago
As far as I can see, the advantages to using add_stylesheet
rather than putting a link directly in the template are:
- Stylesheets will always be loaded before scripts.
- Using
add_stylsheet
offers the potential for manipulation inpost_process_request
. - Consistency in the codebase, and the majority of the codebase seems to use
add_stylesheet
.
I've tried out the suggested changes and made a few additional changes (log:rjollos.git:t11126). There is a problem with change to the Pygments preferences page in Chrome 31 - the page never renders in the browser. Everything seems normal in Firefox 26.
comment:6 by , 11 years ago
I think the changes in [1e14ab0f/rjollos.git] are API Changes for such a usage.
add_stylesheet(req, 'fooplugin/css/base.css', 'text/css', 'screen print')
comment:7 by , 11 years ago
I hadn't worried about that since the changes are targeted to the trunk, but I can drop that changeset if you think it would be better.
comment:8 by , 11 years ago
Okay. The usage of add_stylesheet
without keyword arguments is rare. I've searched and the same usage in trac-hacks doesn't exist.
by , 11 years ago
Attachment: | pygments_styles_transfer.png added |
---|
comment:9 by , 11 years ago
Replying to rjollos:
There is a problem with change to the Pygments preferences page in Chrome 31 - the page never renders in the browser. Everything seems normal in Firefox 26.
The issued seemed to be that monokai.css
and pastie.css
weren't being transferred.
After reinstalling Pygments the issue seems to be resolved. I'm not sure if it was installed in development mode originally.
comment:10 by , 11 years ago
Milestone: | next-dev-1.1.x → 1.1.2 |
---|
comment:11 by , 11 years ago
As a side-note, the page source is much easier to read after the following change, which results in line breaks after each link
element:
-
trac/templates/layout.html
diff --git a/trac/templates/layout.html b/trac/templates/layout.html index 9d3316e..97d2ff4 100644
a b 21 21 </script><![endif]--> 22 22 <py:if test="chrome.links"> 23 23 <py:for each="rel, links in chrome.links.items()"> 24 <link rel="${rel}" py:for="link in links" py:attrs="link" /> 24 <py:for each="link in links" py:with="type = link.pop('type', None)"> 25 <link rel="${rel}" type="${type}" py:attrs="link" /> 26 </py:for> 25 27 </py:for> 26 28 </py:if> 27 29 <py:if test="not defined('trac_error_rendering') and 'SEARCH_VIEW' in perm"
As an example, here is the relevant content from the Syntax Highlighting preferences page before and after the change:
<link rel="stylesheet" type="text/css" href="/tracdev/chrome/common/css/trac.css" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/autumn.css" title="Autumn" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/borland.css" title="Borland" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/bw.css" title="Bw" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/colorful.css" title="Colorful" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/default.css" title="Default" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/emacs.css" title="Emacs" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/friendly.css" title="Friendly" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/fruity.css" title="Fruity" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/manni.css" title="Manni" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/monokai.css" title="Monokai" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/murphy.css" title="Murphy" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/native.css" title="Native" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/pastie.css" title="Pastie" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/perldoc.css" title="Perldoc" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/rrt.css" title="Rrt" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/tango.css" title="Tango" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/trac.css" title="Trac" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/vim.css" title="Vim" /><link rel="stylesheet" type="text/css" href="/tracdev/pygments/vs.css" title="Vs" /><link rel="stylesheet" type="text/css" href="/tracdev/chrome/common/css/prefs.css" /> <link rel="shortcut icon" type="image/x-icon" href="/tracdev/chrome/common/trac.ico" />
<link rel="stylesheet" type="text/css" href="/tracdev/chrome/common/css/trac.css" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/autumn.css" title="Autumn" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/borland.css" title="Borland" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/bw.css" title="Bw" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/colorful.css" title="Colorful" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/default.css" title="Default" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/emacs.css" title="Emacs" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/friendly.css" title="Friendly" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/fruity.css" title="Fruity" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/manni.css" title="Manni" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/monokai.css" title="Monokai" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/murphy.css" title="Murphy" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/native.css" title="Native" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/pastie.css" title="Pastie" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/perldoc.css" title="Perldoc" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/rrt.css" title="Rrt" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/tango.css" title="Tango" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/trac.css" title="Trac" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/vim.css" title="Vim" /> <link rel="stylesheet" type="text/css" href="/tracdev/pygments/vs.css" title="Vs" /> <link rel="stylesheet" type="text/css" href="/tracdev/chrome/common/css/prefs.css" />
Should I make that change?
follow-up: 13 comment:12 by , 11 years ago
Why is it using type = link.pop('type', None)
? That would change the items of req.chrome.links
. I don't think template should change data of the template.
Either one of each link element with/without newline will be fine.
-
trac/templates/layout.html
diff --git a/trac/templates/layout.html b/trac/templates/layout.html index 9d3316e..2f1d0f1 100644
a b 21 21 </script><![endif]--> 22 22 <py:if test="chrome.links"> 23 23 <py:for each="rel, links in chrome.links.items()"> 24 <link rel="${rel}" py:for="link in links" py:attrs="link" /> 24 <py:for each="link in links"> 25 <link rel="${rel}" py:attrs="link" /> 26 </py:for> 25 27 </py:for> 26 28 </py:if> 27 29 <py:if test="not defined('trac_error_rendering') and 'SEARCH_VIEW' in perm" id="search">
comment:13 by , 11 years ago
Replying to jomae:
Why is it using
type = link.pop('type', None)
? That would change the items ofreq.chrome.links
. I don't think template should change data of the template.
Oh, sorry about that, I didn't intend to include the py:with
in the patch. It was just due to some experimenting earlier when trying to figure out why the template wouldn't render (comment:9), so I had a dirty working copy when creating the patch in comment:11.
comment:14 by , 11 years ago
Changes committed to trunk in [12352:12353].
comment:15 by , 11 years ago
Resolution: | → fixed |
---|---|
Status: | assigned → closed |
Modify some templates to converge to
add_stylesheet
behavior