Behavior vs. Context

John et al,

In an effort to extend Radiant for my own needs, I have discovered that
I
need to create some Radius tags. Ideally, I’d like these to be part of
the
PageContext class, but I’m not sure how to go about it (should I
alias/override initialize?). I’d be willing to settle for a behavior,
but
since a page can only have a single behavior, and the tags are more like
utilities, I’m not sure it’s appropriate. How should I proceed? Are
there
best practices for this sort of thing?

TIA

Sean C.
seancribbs.com

Sean C. wrote:

John et al,

In an effort to extend Radiant for my own needs, I have discovered that
I need to create some Radius tags. Ideally, I’d like these to be part
of the PageContext class, but I’m not sure how to go about it (should I
alias/override initialize?). I’d be willing to settle for a behavior,
but since a page can only have a single behavior, and the tags are more
like utilities, I’m not sure it’s appropriate. How should I proceed?
Are there best practices for this sort of thing?

I’ve been doing this via a plugin, as follows:

class Behavior::Base
define_tags do
tag “slicktabs” do |tag|
slicktab = SlickTabs.new(tag)
slicktab.output
end
…other tags…
end
end

class SlickTabs

end

Sean C. wrote:

end

class SlickTabs
   ...
end

So essentially, Behavior::Base is available whether there’s a behavior
assigned or not? Or am I misunderstanding?

I just wrote a whole screed about reopening classes in Ruby, then
realized you were asking if Behavior::Base is always available -to the
page-. Oops.

From experience, yes - you don’t need a behavior defined to use the
tags you call from Behavior::Base. I’m not sure entirely why; John can
shed some light, I’m sure.

I think it’s because Behavior::Base acts as kind of an abstract base
class - it sets up a bunch of helpers for defining tags, but (normally)
doesn’t call any of them itself. Any behaviors you write would descend
from it and call them. And Page seems to delegate to Behavior no matter
what, so if no other behavior is defined, you’re still getting
Behavior::Base, which normally does nothing. Now that you’ve reopened
it, you’re defining some tags as well - you’ve modified the “nil”
behavior.

I’m very muddy on this advanced_delegation stuff, so my explanation of
WHY it works may be totally wrong. But it works. Just like a cargo
cult.

Jay

end
end

class SlickTabs

end

So essentially, Behavior::Base is available whether there’s a behavior
assigned or not? Or am I misunderstanding?