Mailing List Archive

How to reach output_buffer in cleanup section of root autohandler
Hi,
I'd like to:
1. catch the content of the output buffer (complete html page which
usually is written to a disc file)
2. do some modifications
3. clear old version of the buffer
4. print modified version

I' found out that $m object stores html in $m->{'request_buffer'}
so if I wirite in the root autohandler:
<%cleannup>
$m->{'request_buffer'} =~s/foo/bar/g;
</%cleanup>
I get what I want in my tests.
Is there a safe method to do this kind of hack?

-Krzysztof
Re: How to reach output_buffer in cleanup section of root autohandler [ In reply to ]
Hi Krzysztof,

Have a look at using Mason's <%filter> block:
http://www.masonhq.com/docs/manual/Devel.html#filtering

--Greg


On 7 Dec 2009, at 9:29 AM, Krzysztof Rudnik wrote:

> Hi,
> I'd like to:
> 1. catch the content of the output buffer (complete html page which
> usually is written to a disc file)
> 2. do some modifications
> 3. clear old version of the buffer
> 4. print modified version
Re: How to reach output_buffer in cleanup section of root autohandler [ In reply to ]
thanks,
I'll try.

To be more precise I want to modify page content after it's been
completed and before it is written to a file

my substitution is going to do very hard job

<%filter>
s/foo(.*?)bar/modify($1,$args)/ge;
</%filter>

where modifiy() is a subroutine defined somewhere and it uses some
external modules
Do you think that using filters is the right way to go?

-Krzysztof



On Mon, Dec 7, 2009 at 3:52 PM, Greg Heo <greg@node79.com> wrote:
> Hi Krzysztof,
>
> Have a look at using Mason's <%filter> block:
> http://www.masonhq.com/docs/manual/Devel.html#filtering
>
> --Greg
>
>
> On 7 Dec 2009, at 9:29 AM, Krzysztof Rudnik wrote:
>
>> Hi,
>> I'd like to:
>> 1. catch the content of the output buffer (complete  html page which
>> usually is written to a disc file)
>> 2. do some modifications
>> 3. clear old version of the buffer
>> 4. print modified version
>
>
>
Re: How to reach output_buffer in cleanup section of root autohandler [ In reply to ]
On Dec 7, 2009, at 8:24 AM, Krzysztof Rudnik wrote:

> To be more precise I want to modify page content after it's been
> completed and before it is written to a file
>
> my substitution is going to do very hard job
>
> <%filter>
> s/foo(.*?)bar/modify($1,$args)/ge;
> </%filter>
>
> where modifiy() is a subroutine defined somewhere and it uses some
> external modules
> Do you think that using filters is the right way to go?

Yes. Use one one in your root-level category template (/autohandler).

Best,

David
Re: How to reach output_buffer in cleanup section of root autohandler [ In reply to ]
thanks,
sorry I am still asking but I am afraid I was not precise enough.

The right solution is !very! important for me
because I am refactoring/optimizing the core tex layer of my working
TeX driven bricolage instance and I would't
like to get optimized="not working" one. [ I probably will, anyway;)]


Here is the screenshot of a typical story preview screen my bric
produces (5 min example with "random" colors)

http://www.mimuw.edu.pl/delta/tex-bric-example.png

and the corresponding bulkedit story screen

http://www.mimuw.edu.pl/delta/tex-bric-example1-bulkedit.png

You can compare the bric result with an example from mathworld

http://mathworld.wolfram.com/EulerFormula.html

I think bricolage can do math better!

Back to the problem.

I' d like my /autohandler look something like that

<%init>
.....
</%init>

% $burner->chain_next

<%cleanup>
#1.
my $output= get output buffer # (ie complete Html of the processed
page in the form it will be written to disk)
# $output=$m->{'request_buffer'} works in my tests

#2.
TeX::do_some_magic($output); # heavy job with tex in background

#3. now I'am ready to filter output
my $new_output=TeX::do_some_substitutions($output); #

$m->clear_buffer;
$m->print($new_output);
</%cleanup>

Using <%filter> to make substitutions does't seem (to me) to be the
right solution
because I had no chance to TeX::do_some_magic() before.


thanks in advance
-Krzysztof



On Mon, Dec 7, 2009 at 6:50 PM, David E. Wheeler <david@kineticode.com> wrote:
> On Dec 7, 2009, at 8:24 AM, Krzysztof Rudnik wrote:
>
>> To be more precise I want to modify page content after it's  been
>> completed and before it is written to a file
>>
>> my substitution is going to do very hard job
>>
>> <%filter>
>> s/foo(.*?)bar/modify($1,$args)/ge;
>> </%filter>
>>
>> where modifiy() is a subroutine defined somewhere  and it uses  some
>> external modules
>> Do you think that using filters is the right way to go?
>
> Yes. Use one one in your root-level category template (/autohandler).
>
> Best,
>
> David
>
Re: How to reach output_buffer in cleanup section of root autohandler [ In reply to ]
On Dec 7, 2009, at 1:30 PM, Krzysztof Rudnik wrote:

> Here is the screenshot of a typical story preview screen my bric
> produces (5 min example with "random" colors)
>
> http://www.mimuw.edu.pl/delta/tex-bric-example.png
>
> and the corresponding bulkedit story screen
>
> http://www.mimuw.edu.pl/delta/tex-bric-example1-bulkedit.png
>
> You can compare the bric result with an example from mathworld
>
> http://mathworld.wolfram.com/EulerFormula.html
>
> I think bricolage can do math better!

Wow. That's some crazy shit right there. I'm impressed.

> Back to the problem.
>
> I' d like my /autohandler look something like that
>
> <%init>
> .....
> </%init>
>
> % $burner->chain_next
>
> <%cleanup>
> #1.
> my $output= get output buffer # (ie complete Html of the processed
> page in the form it will be written to disk)
> # $output=$m->{'request_buffer'} works in my tests
>
> #2.
> TeX::do_some_magic($output); # heavy job with tex in background
>
> #3. now I'am ready to filter output
> my $new_output=TeX::do_some_substitutions($output); #
>
> $m->clear_buffer;
> $m->print($new_output);
> </%cleanup>
>
> Using <%filter> to make substitutions does't seem (to me) to be the
> right solution
> because I had no chance to TeX::do_some_magic() before.

<%filter>;
TeX::do_some_magic($_);
</%filter>

Not sure if you have $m there to clear the buffer, though.

Best,

David
Re: How to reach output_buffer in cleanup section of root autohandler [ In reply to ]
On Mon, Dec 7, 2009 at 10:56 PM, David E. Wheeler <david@kineticode.com> wrote:
> On Dec 7, 2009, at 1:30 PM, Krzysztof Rudnik wrote:
>
>> Here is the screenshot of a typical story preview screen my bric
>> produces (5 min example with "random" colors)
>>
>> http://www.mimuw.edu.pl/delta/tex-bric-example.png
>>
>> and the corresponding bulkedit story screen
>>
>> http://www.mimuw.edu.pl/delta/tex-bric-example1-bulkedit.png
>>
>> You can compare the bric result  with an example from mathworld
>>
>> http://mathworld.wolfram.com/EulerFormula.html
>>
>> I think bricolage can do math better!
>
> Wow. That's some crazy shit right there. I'm impressed.
>
>> Back to the problem.
>>
>> I' d like my /autohandler look something like that
>>
>> <%init>
>> .....
>> </%init>
>>
>> % $burner->chain_next
>>
>> <%cleanup>
>> #1.
>> my $output= get output buffer #  (ie complete Html of the processed
>> page in the form it will be written to disk)
>> # $output=$m->{'request_buffer'} works in my tests
>>
>> #2.
>> TeX::do_some_magic($output); # heavy job with tex in background
>>
>> #3. now I'am ready to filter output
>> my $new_output=TeX::do_some_substitutions($output); #
>>
>> $m->clear_buffer;
>> $m->print($new_output);
>> </%cleanup>
>>
>> Using <%filter> to make substitutions does't seem (to me) to be the
>> right solution
>> because   I had no chance to TeX::do_some_magic() before.
>
> <%filter>;
> TeX::do_some_magic($_);
> </%filter>
>
> Not sure if you have $m there to clear the buffer, though.
seems to work, thanks very much.

krzysztof

>
> Best,
>
> David
>
>