#11129 closed enhancement (fixed)
Handle CSS as text/css type
Reported by: | Owned by: | Ryan J Ollos | |
---|---|---|---|
Priority: | normal | Milestone: | 1.1.2 |
Component: | general | Version: | |
Severity: | normal | Keywords: | |
Cc: | ethan.jucovy@…, Christian Boos, olemis+trac@… | Branch: | |
Release Notes: | |||
API Changes: |
The rendering |
||
Internal Changes: |
Description
I have a plugin that implements IRequestHandler
and returns CSS from process_request
like:
def process_request(self, req): myColors = [ ('a', '#3a3'), ('b', '#fff'), ('c', '#ada'), ('d', '#888') ] ... return 'myplugin.css', {'myColors': myColors}, 'text/css'
but the CSS doesn't get the correct mime type without patching chrome.py
as attached.
Attachments (3)
Change History (29)
by , 12 years ago
Attachment: | chrome.diff added |
---|
follow-up: 2 comment:1 by , 12 years ago
Cc: | added |
---|
This would be helpful for me too — I also have a plugin that renders CSS from a template using a request handler, which doesn't work properly without this patch.
follow-up: 3 comment:2 by , 11 years ago
This seems harmless enough. Any objections?
Replying to ethan.jucovy@…:
This would be helpful for me too — I also have a plugin that renders CSS from a template using a request handler, which doesn't work properly without this patch.
Which plugin? I'd just like to take a look at an example use-case.
comment:3 by , 11 years ago
Replying to rjollos:
Which plugin? I'd just like to take a look at an example use-case.
th:LighterTheme, which currently has a configuration option for the primary font-family. My workaround is to render the template to a string with mimetype text/plain
, and then to send the string with content-type text/css
using req.send
.
comment:4 by , 11 years ago
Milestone: | next-dev-1.1.x → 1.1.2 |
---|---|
Owner: | set to |
Status: | new → assigned |
Thanks. I will use your plugin to do some testing before committing the change.
comment:5 by , 11 years ago
API Changes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
I've attached a patch for the th:LighterTheme that seems to work well after the change to Trac.
Committed to trunk in [12418].
comment:7 by , 11 years ago
Does this patch look okay?
-
trac/web/chrome.py
diff --git a/trac/web/chrome.py b/trac/web/chrome.py index dc9eaf3..854314f 100644
a b class Chrome(Component): 981 981 if content_type is None: 982 982 content_type = 'text/html' 983 983 method = {'text/html': 'xhtml', 984 984 'text/css': 'text', 985 'text/javascript': 'text', 985 986 'text/plain': 'text'}.get(content_type, 'xml') 986 987 987 988 if method == "xhtml":
comment:8 by , 11 years ago
Sorry. My suggestion breaks backward-compatibility. Some plugins expect html
parsing for text/javascript
. Please ignore it. (I've searched with grep -rE "add_script\\(req, *[\"']/" ./trac-hacks
.)
- th:source:dynamicfieldsplugin/0.12/dynfields/web_ui.py#L59
- th:source:dynamicfieldsplugin/0.12/dynfields/templates/dynfields.html
Also, the following plugin expects html
parsing for text/css
.
comment:9 by , 11 years ago
The change is on trunk
so API changes seem reasonable to make. It seems like th:DynamicFieldsPlugin should be using add_script_data
for Trac ≥ 0.12 anyway. Which leads me to the thought that since we the add_script_data
mechanism, maybe we don't need to handle text/javascript
?
Another issue is that /lightertheme/theme.css
will not be treated as a cacheble resource (th:#7617, th:#9764), so maybe there is a better solution?
follow-up: 13 comment:10 by , 11 years ago
Instead of adding more and more items to the method
dict, how about allowing process_request()
to specify the method as an additional return value? This could even be done in a backward-compatible way.
comment:11 by , 11 years ago
Resolution: | fixed |
---|---|
Status: | closed → reopened |
comment:12 by , 11 years ago
Status: | reopened → assigned |
---|
follow-up: 14 comment:13 by , 11 years ago
Replying to rblank:
Instead of adding more and more items to the
method
dict, how about allowingprocess_request()
to specify the method as an additional return value? This could even be done in a backward-compatible way.
Proposed changes can be found in log:rjollos.git:t11129. Should method
be passed to post_process_request
? The changes seem to get much more complex in that case.
follow-ups: 15 18 comment:14 by , 11 years ago
Cc: | added |
---|
Replying to rjollos:
Proposed changes can be found in log:rjollos.git:t11129. Should
method
be passed topost_process_request
? The changes seem to get much more complex in that case.
Looks nice. Yes, I think the method should be passed to post_process_request
. This can be done relatively easily in a backward-compatible way by using the arity()
function that we have in trac.util
. Basically, add the method argument to the interface and document it, and before calling it, check whether it takes 3 or 4 arguments. We already have a few instances of this pattern (e.g. in trac/wiki/formatter.py
).
But before committing this, since it's a pretty major API change (returning the method from process_request()
, not the issue with post_process_request()
), I would like Christian to chime in. I have been away from Trac development for too long, and he may have had other plans for process_request()
.
follow-up: 16 comment:15 by , 11 years ago
Replying to rblank:
Replying to rjollos:
Proposed changes can be found in log:rjollos.git:t11129. Should
method
be passed topost_process_request
? The changes seem to get much more complex in that case.Looks nice. Yes, I think the method should be passed to
post_process_request
. This can be done relatively easily in a backward-compatible way by using thearity()
function that we have intrac.util
. Basically, add the method argument to the interface and document it, and before calling it, check whether it takes 3 or 4 arguments. We already have a few instances of this pattern (e.g. intrac/wiki/formatter.py
).
+1 , function arity()
should be invoked to determine whether post_process_request
supports new method
arg . Nevertheless I'm wondering whether the condition should be if len(resp) > 3
… a subtle difference , maybe not important at all .
[…]
comment:16 by , 11 years ago
Replying to Olemis Lang <olemis+trac@…>:
Replying to rblank:
Replying to rjollos:
Proposed changes can be found in log:rjollos.git:t11129. Should
method
be passed topost_process_request
? The changes seem to get much more complex in that case.Looks nice. Yes, I think the method should be passed to
post_process_request
. This can be done relatively easily in a backward-compatible way by using thearity()
function that we have intrac.util
. Basically, add the method argument to the interface and document it, and before calling it, check whether it takes 3 or 4 arguments. We already have a few instances of this pattern (e.g. intrac/wiki/formatter.py
).+1 , function
arity()
should be invoked to determine whetherpost_process_request
supports newmethod
arg . Nevertheless I'm wondering whether the condition should beif len(resp) > 3
… a subtle difference , maybe not important at all .[…]
Indeed I think I'd rather prefer
try: method = resp[3] except IndexError: method = None
comment:17 by , 11 years ago
Cc: | added |
---|
follow-up: 20 comment:18 by , 11 years ago
Replying to rblank:
… (cboos) may have had other plans for
process_request()
.
Well, I had various ideas for refactoring the request dispatching part, some discussed in #8509, others in VcRefactoring/Controller… but nothing there which should prevent making incremental enhancements to the current API! So please go ahead.
comment:19 by , 11 years ago
[12418] reverse-merged in [12433]. I'll continue working on the log:rjollos.git:t11129 changes this week.
comment:20 by , 11 years ago
Replying to cboos:
Replying to rblank:
… (cboos) may have had other plans for
process_request()
.Well, I had various ideas for refactoring the request dispatching part, some discussed in #8509, others in VcRefactoring/Controller…
afaict, this approach looks very nice . Please see comment:24:ticket:8509
but nothing there which should prevent making incremental enhancements to the current API! So please go ahead.
IMO , @rjollos patches are looking good . Other refinements to the API will represent major upgrade steps towards future adoption e.g. by plugins .
comment:21 by , 11 years ago
Latest proposed changes can be found in log:rjollos.git:t11129.2. I plan to add some tests.
comment:22 by , 11 years ago
The latest changes can be found in log:rjollos.git:t11129.3:
- Unit tests added.
- Refactored to localize most of the changes to
RequestDispatcher._post_process_request
.
Revised patch for th:LighterTheme: t11129-lightertheme-2.patch.
comment:23 by , 11 years ago
The file move doesn't seem to have been captured in the patch, though it's shown by git status
:
$ git status # On branch master # Changes to be committed: # (use "git reset HEAD <file>..." to unstage) # # renamed: lightertheme/templates/lightertheme/theme.css.tmpl -> lightertheme/templates/theme.css.tmpl # # Changes not staged for commit: # (use "git add <file>..." to update what will be committed) # (use "git checkout -- <file>..." to discard changes in working directory) # # modified: lightertheme/__init__.py # modified: setup.py
by , 11 years ago
Attachment: | t11129-lightertheme-2.patch added |
---|
comment:24 by , 11 years ago
The patch is corrected now. The issue was that I had a mix of staged (moved files) and unstaged (modified files) changes, so even the -M
option didn't result in the moved file being included in the patch. The --cached
option would result in the moved file being included, but not the modified files.
comment:25 by , 11 years ago
API Changes: | modified (diff) |
---|---|
Resolution: | → fixed |
Status: | assigned → closed |
Changes committed to trunk in [12527].
comment:26 by , 9 years ago
Reporter: | changed from | to
---|
Patch to fix mime type of style sheets