Antville Project

rewriting image_macro()

just for the records: i made a huge step forward in rewriting robert's cool image_macro (here's the code in a cvs branch of antville, third function from top).

the features of thumbnail_macro() and imageurl_macro() are now included by handing over param.as = "thumbnail" or param.as = "url". well, to be honest, param.as = "popup" does the job of the thumbnail macro, while param.as = "thumbnail" does almost the same just without popping up a new window using javascript... (good?)

moreover, i started to modify some of the global renderSomething() functions: the problem was that they are hardly re-usable due to many res.writes in the code. so i renamed these functions to renderSomethingAsString() and replaced the direct output by building a string and returning it in the end. then, i added new functions with the old name as wrappers to directly write out the result of the --AsString() functions again. while it sounds complicated here, i think it becomes quite clear when you think of renderSkin and renderSkinAsString...

is that a way to go? would you support this code structure?

comment    

 
robert, May 22, 2002 at 4:38:03 PM CEST

reg. image-macro: the new parameter "popup" looks fine for me. there's more a problem regarding compatibility with existing stories (what happens to those stories that have a thumbnail-macro embedded?).

moreover, i started to modify some of the global renderSomething() functions

i don't know if those wrappers are really needed. although this is syntactically the same as helma provides, this means that a lot of function-calls will actually be doubled - and i'm not sure if that won't degrade performance (have you benchmarked your new structure with the old one?)... so i'd vote for replacing the code of the old renderSomething-functions with your new one, and move the res.write-calls to the calling functions (which of course means a lot more changes to the code). what ya think? do you see any problems with that?

link  

 
tobi, May 22, 2002 at 4:59:22 PM CEST

Re: benchmark

no, i haven't benchmarked the new code, yet (what's a good way to do this effectively, btw.?)

however, i think it's fine to have a possibility of directly rendering strings to the output buffer as well as using the strings as is in other functions...

if we would replace the renderFunctions with new code, where would the res.write stuff move to? macro functions only? or could we completely drop them? what became of automatic processing the prefix and suffix parameters in macro functions that return null (bug 73)?

link  

 
robert, May 22, 2002 at 5:16:32 PM CEST

what i meant is that i'm not sure if it's so much cleaner/better to call a function e.g. renderColor() (which then does res.write(renderColorAsString()) instead of directly doing res.write(renderColor()) somewhere in a macro-function. but what might be a good idea is to set up naming-convention where functions that return a string are called renderSomethingAsString and those that write directly to response just renderSomething.

reg. benchmarking: this was just a sidestep in my mind (so don't take that too seriously), and i'm not sure if this really has a negative effect on performance. tools? i use apache benchmark or, for a more realistic result, http_load.

link  

 
tobi, May 22, 2002 at 5:26:15 PM CEST

ok, ok

i see. i mainly did this as a first step to provide backwards-compatibility. because from the macro point of view it makes a huge difference if a function is called simply by renderSomething() or res.write(renderSomething()) and the function returns a value or itself writes to the output buffer.

for now every render function call gets the right handling as before, except where i modified the calling functions itself.

in the bigger picture and as next step, we certainly should modify the macros itself to call the right render function type.

anyway, this is still depending on if bug 73 will be resolved...

and thanks for the benchmarking tool tips, robert. :)

link  

 
tobi, May 22, 2002 at 5:32:29 PM CEST

Re: thumbnail

do you think this will be a big problem or cause a lot of confusion / misunderstanding?

<% image name="picture" as="thumbnail" %> will produce this output:

while <% image name="picture" as="popup" %> will produce what formerly was done by the thumbnail macro:

click!

the difference is what happens when you click on the thumbnail...

btw. who the fsck has posted all these fscking pictures to the pool? it takes a nation of millions to hold me back from deleting them!

link  

 
robert, May 22, 2002 at 5:48:43 PM CEST

i think the problem is: now we have a lot of stories (i guess) that have a thumbnail_macro embedded: if we throw out the macro, those thumbnails won't appear anymore. if the thumbnail-macro becomes a wrapper-macro (for image_macro), those images will be displayed as normal-size-images (because the parameter as="thumbnail" is missing). and replacing all thumbnail-macros in those stories is quite a lot of (coding-)work ...

link  

 
tobi, May 22, 2002 at 5:52:23 PM CEST

why?

we don't have to throw out thumbnail_macro. but we can modify it to call image_macro with param.as set to "thumbnail", can't we?

function thumbnail_macro(param) {
var p = cloneObject(param); // param is read-only
p.as = "thumbnail";
return(this.image_macro(p));
}
or did i miss something?

link  

 
robert, May 22, 2002 at 10:05:09 PM CEST

ah now i got it

i forgot that you're heavy in cloning business ;-) sure, doing that makes perfect sense, and solves any backwards-compatibility-issues.

link  


... comment
 
hns, May 22, 2002 at 5:58:25 PM CEST

The thing about res.write()

The reason why you need the return-as-string functionality to get reusable code in the first place is that you don't do stuff in natural order. If you do stuff in natural order, you can always directly render out to the response object. I.e. instead of

    var imgtag = renderImageAsString(imgObj, param);
    return(renderMarkupElementAsString("a",
imgtag, linkparam));

you'd have

    openElement ("a", linkparam);
    renderImage (imgObj, param);
    closeElement ("a");

There's really no gain to wrap the renderMarkupElement into one single function here because it naturally falls into two parts, which IMHO are much easier to read (less convoluted) and more efficient, because it uses a stream based approach, which Helma encourages (write everything out as soon as you got it) instead of a stack based one (stack everything up on a heap until everything is ready, then flush it out).

BTW, next to the openElement() and closeElement() functions above you'd only need an emptyElement() function taking the same parameters as openElement() and you'd be set.

link  

 
tobi, May 22, 2002 at 6:08:02 PM CEST

that's alright

but probably also a question of taste or what one considers as natural.

well, one objection i have: a function streaming the output is not re-usable if i would like to post-process its result in another function. at least that's why i have started in this direction: i stumbled too many times across direct output but wanted to have post-processing.

another reason that i ended here is probably because i started with a skin (which is not used anymore, and therefor the streamed approach is possible again). i don't know if it is helma who encourages this or that approach or the peops behind it... (might make no difference, anyway). however, helma supports both ways pushing something ready-made into or getting something serially from within a skin. i'd prefer freedom of choice, as usual.

i happily will make another trial to follow your suggestion, just to see what it's like.

but still remains the question if prefix and suffix will be automatically rendered in such streaming output... (you once said it was possible)?

link  

 
hns, May 22, 2002 at 6:20:50 PM CEST

right

the skin based approach does have its place, but higher up where flexibility is the main concern.

Here, for low level infrastructure stuff, I'd say the other approach is the better fit for the benefit of an easier to follow render-flow.

Regarding native prefix and suffix support in Macros: yes, I'll implement it right now.

link  


... comment
 
tobi, May 23, 2002 at 2:23:46 PM CEST

moving forward

i modified the recent code to adapt hannes' suggestions of rather "streaming" the output than putting everything together in a string. it works very well and i hope this cool concept will keep its promises (but please note that there are still bugs to fix).

however, i would like to keep some of the render/renderAsString siblings at least for the functions renderTextPreview() and renderColor().

regarding the naming of functions i suggest we prefix a function with "render" if it directly outputs to the string buffer. otherwise we should prefix it with "get" or simply use any other name not starting with "render".

i already tried to do this with global/renderFunctions.js, but there remain some exceptions:

  1. doWikiStuff should become renderWikiStuff and be rewritten because it contains markup and does not look like adequate code at all.
  2. openMarkupElement and closeMarkupElement i did not want to call renderOpenMarkupElement, renderMarkupElementClosed or the like because it's just comfy like that (so i rather live with the logical inconsistency here)
as far as i tested the code, everything still works as before. moreover, the first results of making the macro syntax more flexible are ready for testing: the image and the link macro now will add any property that is included in the macro call as html attribute (which only makes sense if it's valid for the tag).

you can get the new code from cvs by stating cvs update -r devjamtobi antville.

i will continue now with setting the output straight for xhtml (which the above changes were necessary for) and what else i volunteered for...

link  

 
hns, May 23, 2002 at 4:28:22 PM CEST

Hi Tobi

sounds all very good and reasonable! I think renderMarkupElement() would better be called emptyMarkupElement() if it only does empty elements, but that's really a minor point.

+1 on renaming/reworking doWikiStuff, it's really a quick hack as far as I remember.

link  

 
robert, May 23, 2002 at 5:08:35 PM CEST

looks fine

i just gave your branch a look, and everything looks really good. kudos! there's just one minor thing: it seems that you forgot to clone the param-object in hopobject/createLinkParam(), so weblogs on root-frontpage don't appear as link (which is - me parece - because you're deleting properties).

and: shouldn't we throw away the openLink() and closeLink()-macros (i assume there are also some other old functions left that could be replaced by your general markup-functions)?

link  

 
tobi, May 23, 2002 at 8:15:04 PM CEST

hi everybody!

ad emptyMarkupElement: i thought about this for a while and considered "emptyMarkupElement" would sound like "emptyTrash" or "make an markup element empty"... that's why i was looking for an alternative. don't take the naming as granted, though.

ad root frontpage: this should be fixed again, right? you probably took a look at the code when it was under heavy processing... :)

ad openLink et al.: i don't want to throw it away right now, because whole antville already was shaking a little bit when i tried to fiddle around with too many parts at once. but generally i support the idea of simplifying the code wherever possible.

btw. i compiled a new snapshot with hannes' recent changes (suffix, prefix support in response buffer) and checked out the current version of the devjamtobi branch to hopdev. please feel free to take a look!

and the frontpage already is valid xhtml!

link  


... comment


The Antville Server Fund has been a great success. Thanks to everybody who contributed!
online for 8550 Days
last updated: 1/4/11, 10:22 AM
status
Youre not logged in ... Login
menu
November 2024
SunMonTueWedThuFriSat
12
3456789
10111213141516
17181920212223
24252627282930
July
recent
zfuture's house here is zfuture's
house
by zfuture (7/31/03, 2:59 AM)
i understand your concerns however,
i hardly can think of a solution. certainly, if the...
by tobi (7/29/03, 9:47 AM)
Found several more similar sites
listed This is getting to be quite a concern to...
by cobalt123 (7/27/03, 7:56 PM)
Second Post Alert on Referrer
bug livecatz I put this into "help" and now here:...
by cobalt123 (7/26/03, 7:14 PM)
well it's not easy to
find from here, anyway. think we should include a link,...
by tobi (7/24/03, 11:25 AM)
So finally I found
the helma Bugzilla - stupid me.
by mdornseif (7/24/03, 10:28 AM)
clock not that it's particularly
earthshattering but the antclock is running slow by about 15...
by kohlehydrat (7/23/03, 8:25 PM)
but blogosphere.us isn't can't really
be rated as spam can it?
by kohlehydrat (7/23/03, 8:08 PM)
More referrer spam www.webfrost.com
by Irene (7/23/03, 7:55 PM)
How to log skin names
I accessed to console?? Hi, I would like to know...
by winson (7/23/03, 4:12 PM)

Click here to get an XML version of this weblog.

Made with Antville
powered by
Helma Object Publisher