Tags using a snippet as a block parameter?

I’m creating an image-tab navigation plugin. Right now, I’m just
automatically scraping the top level of page titles and URLs. But it
would be nicer to provide a syntax like

<r:navtab page_snippet=“nav-pages”/>

(Aside: am I the only one that would prefer hyphens to underscores here?
But Radius doesn’t allow hyphens in attribute names for some reason.
Anyway.)

Snippet nav-pages:

<r:find url="/">
<r:children:each by=“breadcrumb”>
<r:unless_url matches="/sitemap">
<r:link/>
</r:unless_url>
</r:children:each>
</r:find>

This works, if I snag @parser from Behavior:

if (tag.attr[‘page_snippet’])
p @parser.parse(%Q|<r:snippet
name="#{tag.attr[‘page_snippet’]}"/>|)

Is that the right way to do it? Am I headed for trouble?

Jay L.

In regards to hyphens versus underscores, I prefer hyphens too.

Kyle H. wrote:

In regards to hyphens versus underscores, I prefer hyphens too.

I think I prefer underscores. Radius is loosely based on Ruby so it uses
underscores. If I wrote it in scheme I might prefer hyphens. :slight_smile:

Actually, it’s probably better if we stick with underscores and stay
consistent with what we are have already done. Though hyphens are
admittedly more visually pleasing, underscores to have the effect of
encouraging you to find precise words for attribute names. I don’t think
it’s an accident that none of the normal HTML attributes are two words.

Mmmm… does XML make allowances for two word attribute names? What
character do they use?


John L.
http://wiseheartdesign.com

Jay L. wrote:

… For some reason, I never want to use hyphens in
code, but I always do in declarative tag-based languages.

A hyphen in code can easily be confused with a subtraction operation.
Most programming languages therefore don’t allow hyphens in identifiers.

Regards,
Erik.


Erik van Oosten

So, back to the original question:

Jay L. wrote:

So, back to the original question:

This works, if I snag @parser from Behavior:

if (tag.attr[‘page_snippet’])
p @parser.parse(%Q|<r:snippet name=“#{tag.attr[‘page_snippet’]}”/>|)

Is that the right way to do it? Am I headed for trouble?

Use this instead:

tag.render(‘snippet’, ‘name’ => tag.attr[‘page_snippet’])


John L.
http://wiseheartdesign.com

John W. Long wrote:

it’s an accident that none of the normal HTML attributes are two words.

Mmmm… does XML make allowances for two word attribute names? What
character do they use?

Actually, XML allows both hyphens and underscores in both names and
elements.

The only XML I’ve really used, XSLT, uses hyphens. (A quick survey
shows RSS, Atom and XAML using camelCase, and XUL using
runtogetherwords, and XQuery using hyphens. )

CSS (which isn’t XML, of course, but which we’re often editing at the
same time as Radius templates) uses hyphens as well, which is what
triggered my thought. For some reason, I never want to use hyphens in
code, but I always do in declarative tag-based languages.

Jay

Jay L. wrote:

Is there any way around that, to bump the “program counter”?

I’m not quite sure what you mean. If you mean: “Is there a way to render
child tags for their side effects rather than the content they produce?”
Then the answer is yes. Whether or not the tag renders it’s contents is
totally up to the tag. Have a look at the <r:navigation /> tag in
page_context.rb to see how it’s done.


John L.
http://wiseheartdesign.com

John W. Long wrote:

Use this instead:

tag.render(‘snippet’, ‘name’ => tag.attr[‘page_snippet’])

Thanks - that works great. I could swear I tried that first… ah well.

So I’m thinking that, rather than have to create a separate snippet,
what I’d really like to do is:

<r:navtabs>

</r:navtabs>

I imagine I can figure out the contents of the container tag and parse
them, but I can’t think of a way to then skip over those contents when
rendering the actual page - they’ll get parsed by the real parser.

Is there any way around that, to bump the “program counter”?

Jay L.