[Radiant] Container tag with default values for nested tags
Casper Fabricius
me at casperfabricius.com
Tue Jun 3 13:48:50 CDT 2008
Nice one, Sean. Seems obvious now that you've shown the way ;)
Thanks,
Casper
On 03/06/2008, at 20:41, Sean Cribbs wrote:
> Well, the natural answer to deferment in Ruby is a closure, of course!
>
> hash[:normal] ||= lambda { parse('<li><r:link /></li>') }
>
> Sean
>
> Casper Fabricius wrote:
>> Sean,
>>
>> Thanks for your answer. However, parse doesn't work quite as I
>> hoped. Calling parse will parse the given string immediately in the
>> current context and return a string. I need to postpone the actual
>> parsing until the context is changed to each item in the
>> collection. I was hoping to be able to construct some kind of proxy-
>> object that would respond to #call just like when nested templates
>> has been given.
>>
>> I can easily solve this by just inserting the default value
>> unparsed, and then have a helper method that checks if the value is
>> a string to parsed or a method to be invoked, but I find that
>> solution quite ugly. I'm obsessing about it, because I'd like to
>> contribute the tag to the Radiant core, so I want it to coded right.
>>
>> Thanks,
>> Casper
>>
>>
>> On 01/06/2008, at 16:51, Sean Cribbs wrote:
>>
>>> Casper,
>>>
>>> Call parse, passing the text you want to parse:
>>>
>>> hash[:normal] ||= parse('<li><r:link /></li>')
>>>
>>> Sean
>>>
>>> Casper Fabricius wrote:
>>>> I'm developing a tag inspired by the way <r:navigation /> works;
>>>> by using nested tags to let the user specify how he wants to
>>>> render a given collection.
>>>>
>>>> The user could write:
>>>> <r:collection_tag>
>>>> <r:normal><b><r:link></b></r:normal>
>>>> </r:collection_tag>
>>>>
>>>> - and the tag uses this nested tag by doing:
>>>> hash = tag.locals.collection_tag = {}
>>>> tag.expand
>>>>
>>>> - and then later:
>>>> hash[:normal].call
>>>>
>>>> - to render the contents of the nested tag.
>>>>
>>>> However, I want the user to also be able to write just:
>>>> <r:collection_tag />
>>>>
>>>> - and the tag will populate hash[:normal] with a default value
>>>> of, say, <r:link />.
>>>>
>>>> However, I don't know how to create a default value for a nested
>>>> tag, least not when it contains other Radius tags that need to be
>>>> parsed in the context of each iteration of the collection.
>>>>
>>>> I have tried assigning default values with code such as:
>>>> hash[:normal] ||= '<li><r:link /></li>'
>>>>
>>>> - or:
>>>> hash[:normal] ||= Proc.new {'<li><r:link /></li>'}
>>>>
>>>> - but the first is just a string, and does not respond to the
>>>> #call method, and the second is just a proc, and do not in fact
>>>> render <r:link /> in the context, it just returns the string
>>>> unparsed.
>>>>
>>>> I know of several examples on using default values for tag
>>>> attributes, but not for nested tags. Any hints, ideas, examples?
>>>>
>>>> Cheers,
>>>> Casper Fabricius
>>>> http://casperfabricius.com
>>>>
>>>> _______________________________________________
>>>> Radiant mailing list
>>>> Post: Radiant at radiantcms.org
>>>> Search: http://radiantcms.org/mailing-list/search/
>>>> Site: http://lists.radiantcms.org/mailman/listinfo/radiant
>>>>
>>>
>>> _______________________________________________
>>> Radiant mailing list
>>> Post: Radiant at radiantcms.org
>>> Search: http://radiantcms.org/mailing-list/search/
>>> Site: http://lists.radiantcms.org/mailman/listinfo/radiant
>>
>> _______________________________________________
>> Radiant mailing list
>> Post: Radiant at radiantcms.org
>> Search: http://radiantcms.org/mailing-list/search/
>> Site: http://lists.radiantcms.org/mailman/listinfo/radiant
>>
>
> _______________________________________________
> Radiant mailing list
> Post: Radiant at radiantcms.org
> Search: http://radiantcms.org/mailing-list/search/
> Site: http://lists.radiantcms.org/mailman/listinfo/radiant
More information about the Radiant
mailing list