Re: __defineGetter__

Michael Platzer <[email protected]>
Newsgroups gmane.comp.java.helma.general
Message-ID <[email protected]>
Hannes Wallnoefer schrieb:
>> A much nicer solution would be of course if Helma would directly provide
>> sthg like
>>
>>   <% this.comments.first.title %> or <% this.comments.0.title %>
>>   <% this.comments.1.title %>
>>   ...
>>   <% this.comments.last.title %>
>>
>> Take a look at http://www.blogr.at/sphere/blogs for example. It displays
>> a list of Sites, together with the title and text of the latest story,
>> and the titles of the second- and third-last story.
>>     
> You brought me to something interesting here.
>
> What if we rethink deep macros not as a property path with a macro
> invocation at the end, but as a chain of macro invocations? The
> current implementation is actually a subset of that, because property
> lookup is one way to render a macro. Let me explain: The construct <%
> this.comments.last.title %> would result in a chain of macro
> invocations where:
>
> 1) macro "comments" is invoked on handler "this"
> 2) macro "last" is invoked on the result of 1)
> 3) macro "title" is invoked on the result of 2)
>
> This way you could simply write a last_macro() and first_macro() in
> HopObject or wherever that returns the last/first element of the
> collection to fill in the missing pieces of the chain.
>
> This makes some sense to me. What do you think?
>   
Yes this makes sense. Otherwise I could only walk down in a flexible way 
by using filters, and I would end up with the following horrible construct:

 Global/filters.js
    function macro_filter = function(input, param) {
      input[param.macro + "_macro"](param);
    }
    function first_filter(input) {
      return input.get(0);
    }
 Image/macros.js
    function comments_macro(param) {
       return this.comments;
    }
 ----> <% this.comments | first | macro macro="title" %>

So, with your suggestion I end up with the nicer solution:
  HopObject/macros.js
     function first_macro(param) {
        return this.get(0);
     }
 ----> <% this.comments.first.title %>

Other than that I could also easily live with the __defineGetter__ 
solution, since it provides me with a similar flexibility.
 
  michi

_______________________________________________
Helma-user mailing list
[email protected]
http://helma.org/mailman/listinfo/helma-user
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.