Search the web
Sign In
New User? Sign Up
radio-dev
? Already a member? Sign in to Yahoo!

Yahoo! Groups Tips

Did you know...
Message search is now enhanced, find messages faster. Take it for a spin.

Best of Y! Groups

   Check them out and nominate your group.
Having problems with message search? Fill out this form to ensure your group is one of the first to be migrated to the new message search system.

Messages

  Messages Help
Advanced
[Feature Request] flNoCallbacks for radio.upstream.getUpstreamText   Message List  
Reply | Forward Message #7034 of 8443 |
Hello,

In my quest to fix #autoparagraph (if set to false, it still add
'<p>'), I stumbled over what I though (I maybe wrong) a short coming
for filtering text with RU.

It seems that the only hook you get when you want to filter text
before a file get upstreamed is at:
user.radio.callbacks.upstreamGetUpstreamText.[myCallback]

[One could think that you could use
user.radio.callbacks.upstreamFileRendered but please, see the note at
the end of this message to see why its not an option.]

If you check at the top of
radio.upstream.getUpstreamText

you will see this:

bundle { //run user callbacks
if not defined (user.radio.callbacks.upstreamGetUpstreamText) {
new (tableType,
@user.radio.callbacks.upstreamGetUpstreamText)};
local (nomad);
for nomad in @user.radio.callbacks.upstreamGetUpstreamText {
try {
while typeOf (nomad^) == addressType {
nomad = nomad^};
local (s);
if nomad^ (f, @s, adrRelativePath) {
return (s)}}}}

Here the bundle:

1. Pass an adress for the text returned (the content of the address
is empty at that moment).
2. Let the callback at
user.radio.callbacks.upstreamGetUpstreamText.[myCallback]
return any text it want.

Now the problem is this one.

Say you want to use a script called:
user.radio.callbacks.upstreamGetUpstreamText.[deleteExtraParagraphs]

to get rid of the extra '<p>'

You could write something like this (please don't do this) for the
deleteExtraParagraphs callback:

on deleteExtraParagraphs (f, adrFileText, adrRelativePath) {
local (adrfile = @user.radio.settings.files.[f]);
try {
if ( defined (adrfile^.autoparagraph) and
adrfile^.autoparagraph == false ) {
local (s);
s = radio.upstream.getUpstreamText (f,
adrRelativePath);
regex.subst ("<p>(\s|\n\|\r)*<p>", "\n", @s);
adrFileText^ = s;
return true}
else {
return false}};
return false}

But this probably will crash RU of RU will start an infinite loop. Why?

Because of this line in the script:

s = radio.upstream.getUpstreamText (f, adrRelativePath);

Since radio.upstream.getUpstreamText is calling the very callback you
are already in, the script deleteExtraParagraphs will never exit.

The only solution I have found so far is to paste inside
deleteExtraParagraphs radio.upstream.getUpstreamText, delete the two
block that calls callbacks in my copy of
radio.upstream.getUpstreamText and rename the verb.

on deleteExtraParagraphs (f, adrFileText, adrRelativePath) {

on mygetUpstreamText (f, adrRelativePath=nil,
renderedFileExtension="html") {
snip }

local (adrfile = @user.radio.settings.files.[f]);
try {
if ( defined (adrfile^.autoparagraph) and
adrfile^.autoparagraph == false ) {
local (s);
s = mygetUpstreamText (f, adrRelativePath);
regex.subst ("<p>(\s|\n\|\r)*<p>", "\n", @s);
adrFileText^ = s;
return true}
else {
return false}};
return false}

Now the verb is working. I will post this filter on website later.

I really don't like this solution because the filter can get in some
trouble if UserLand change radio.upstream.getUpstreamText, so
mygetUpstreamText will not be in sync with the former verb.

So my feature request is this. Please UserLand, add a new param
called something like flNoCallbacks to radio.upstream.getUpstreamText:
getUpstreamText (f, adrRelativePath=nil,
renderedFileExtension="html", flNoCallbacks= false)

so I could use it in a callback at
user.radio.callbacks.upstreamGetUpstreamText

and replace the line in my callback called deleteExtraParagraphs:
s = mygetUpstreamText (f, adrRelativePath);

by
s = radio.upstream.getUpstreamText (f, adrRelativePath, flNoCallbacks: true);

I think this is a really minor change to
radio.upstream.getUpstreamText and could help a lot anyone wanting to
filter text with a callback at
user.radio.callbacks.upstreamGetUpstreamText.

TIA

Cheers
-Emmanuel

=================================
Note on user.radio.callbacks.upstreamFileRendered
=================================

I though that I could use for filtering text:
user.radio.callbacks.upstreamFileRendered.[myCallback]

But, if you look at the bottom of
radio.upstream.getUpstreamText

in the block that start with:
bundle //call the callbacks
«12/17/01; 6:45:21 PM by DW

you will see that the verb here called 'runCallbacks':

1. doesn't pass an address for the resulting text
2. so, notwithstanding a hack, doesn't offer a way to change the text
that will be returned by
radio.upstream.getUpstreamText

Check an example of this callback at:
radio.upstream.callbacks.upstreamFileRendered.backupRendering.


--
______________________________________________________________________
Emmanuel Décarie / Programmation pour le Web - Programming for the Web
Frontier - Perl - PHP - Javascript - XML <http://scriptdigital.com/>



Thu Oct 31, 2002 3:57 pm

emmanueldecarie
Offline Offline
Send Email Send Email

Forward
Message #7034 of 8443 |
Expand Messages Author Sort by Date

Hello, In my quest to fix #autoparagraph (if set to false, it still add '<p>'), I stumbled over what I though (I maybe wrong) a short coming for filtering text...
Emmanuel. M. Decarie
emmanueldecarie
Offline Send Email
Oct 31, 2002
3:57 pm

... Sorry, I made a false assumption. The name of the directive is: #autoparagraphs with an 's' and not #autoparagraph. So it seems to work well when you...
Emmanuel. M. Decarie
emmanueldecarie
Offline Send Email
Oct 31, 2002
4:50 pm

Could someone work witih Emmanuel to get a spec out of this feature request?? Having trouble understanding what's being asked for. Dave ... From: "Emmanuel. M....
Dave Winer
dwiner
Offline Send Email
Oct 31, 2002
5:58 pm

Hello Dave, Simply put, I just want to be able to use in one of my script radio.upstream.getUpstreamText without the callbacks associated with this verb (so...
Emmanuel Décarie
emmanueldecarie
Offline Send Email
Oct 31, 2002
6:50 pm

Emmanuel, Been there, done that. Check out my pLessFix tool on http://radio.weblogs.com/0001017/publicTools/ It will remove all duplicate or greater <p> tags...
Andy Fragen
ajfragen
Offline Send Email
Oct 31, 2002
10:12 pm

Hello Andy, Thanks for your answer but your solution just reinforce my feeling that there is really a short coming in RU for filtering text before it get...
Emmanuel. M. Decarie
emmanueldecarie
Offline Send Email
Nov 1, 2002
3:22 pm

... Oups, I wanted to say here: I find unfortunate that such an important script like radio.upstream.getUpstreamText is tied to callbacks. I see no logic ...
Emmanuel. M. Decarie
emmanueldecarie
Offline Send Email
Nov 1, 2002
3:30 pm

... I agree, but this was the only way "currently" to achieve what you want. ... This is exactly the line as it reads in pLessFix. ;) ... Actually, I...
Andy Fragen
ajfragen
Offline Send Email
Nov 1, 2002
5:07 pm

Hello Andy, ... before ... want. Well, I offered my own solution, but I consider it as an ugly work-around. ... to ... only ... Well, I just pasted this line...
Emmanuel Décarie
emmanueldecarie
Offline Send Email
Nov 1, 2002
8:50 pm

Emmanuel, Jake has just found and fixed the multiple <p> tag problem. If you've installed your own fix or mine disable it and you'll be pleasantly surprised. I...
Andy Fragen
ajfragen
Offline Send Email
Nov 2, 2002
12:32 am

Hello Andy, The problem is not that you don't have a callback for radio.upstream.getUpstreamText (its at user.radio.callbacks.upstreamGetUpstreamText) is that...
Emmanuel Décarie
emmanueldecarie
Offline Send Email
Nov 2, 2002
4:42 pm

... Changes were released yesterday which should fix the extra <p> tags problem. I've had one report that the fix didn't work for story pages, but this seems...
Jake Savin
jsavin
Offline Send Email
Nov 1, 2002
10:47 pm

Jake, YOU DA MAN! This works for me and I've disabled my pLessFix tool -- yeah! Now all you need to do is fix other places where Radio renders less than ...
Andy Fragen
ajfragen
Offline Send Email
Nov 2, 2002
12:27 am
Advanced

Copyright © 2009 Yahoo! Inc. All rights reserved.
Privacy Policy - Terms of Service - Guidelines - Help