On 11/29/12, Olemis Lang <[email protected]> wrote:
> On 11/29/12, Matevz Bradac <[email protected]> wrote:
>> Hi,
>>
>
> :)
>
> [...]
>>
>> I tried to override this behaviour by prepending a DocTypeInserter
>> filter to the stream, but that doesn't
>> work either - the doctype from trac always comes first in line, and
>> any subsequent doctypes are ignored
>> by the serializer.
>>
>
> :(
>
[...]
>> If not, is there any way of overriding trac's behaviour without
>> modifying trac itself?
>>
>
> Yes , I'll take a look in a while and follow with some suggestion
> ;)
>

I analyzed the code in trac.web.chrome.Chrome.render_template . I'll
paste all the relevant parts of the source code below and suggest
something after that .

{{{
#!py

        if self.stream_filters:
            stream |= self._filter_stream(req, method, filename,
stream, data)

[...]

        doctype = {'text/html': DocType.XHTML_STRICT}.get(content_type)

[...]
            buffer = StringIO()
            stream.render(method, doctype=doctype, out=buffer,
                          encoding='utf-8')

}}}

Notice how doctype is selected (second statement) . Afterwards
DocType.XHTML_STRICT is passed in to stream.render method , and that's
the reason why you are always obtaining HTML strict doctype over and
over

:-/

The good news is that all this happens after the stream has been
filtered (first statement) . Considering the first paragraph in your
original message it seems to me that you are inserting the DOCTYPE at
the beginning of the stream (cmiiw) and that's not the way to go ...

I suggest you to consider this approach

1. BH theme already implements IRequestFilter
2. implement a stream wrapper overriding render
    method in such a way that DocType.HTML5
    (or something more accurate , your choice ;)
    is used instead of HTML strict *if appropriate*
    e.g. bloodhound theme enabled , etc, etc ...
3. return stream wrapper rather than the original
    stream so that your brand new render method
    is invoked and the content type you want is
    used instead.

... you might need to take some extra precautions though ... but I'm
confident you'll figure them out along the way
;)

PS: ... if you need more precise help in real-time I'll connect
tomorrow to #bloodhound @ freenode IRC channel . More people will be
there too .

PS: PS: BTW , even if something else is done , in the end we
definitely have to improve current implementation of filter_stream
method . It turns out that transformations (i.e. inclusion of default
Bootstrap classes et al. ) are happening even if bloodhound theme is
not activated . That's not right because under such circumstances
Bootstrap won't be there and our template swapping trick won't be
happening at all .

-- 
Regards,

Olemis.

Blog ES: http://simelo-es.blogspot.com/
Blog EN: http://simelo-en.blogspot.com/

Featured article:

Reply via email to