[Helma-user] __defineGetter__

Michael Platzer michael.platzer at knallgrau.at
Fri Mar 30 20:38:11 CEST 2007


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

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://helma.org/pipermail/helma-user/attachments/20070330/fd05c91b/attachment.html 


More information about the Helma-user mailing list