Lose global tags when a page uses a Behavior?

I’m seeing some interesting behavior (so to speak) with global tags
(please correct me if that’s the wrong term). If I have the following
in app/behaviors/hello_behavior.rb:

class Behavior::Base
define_tags do
tag “hello” do |tag|
“Hello World!”
end
end
end

I would expect to be able to write <r:hello/> in any page to render
the text “Hello World!”.

This seems to work fine on pages that do not have a behavior
specified (i.e., the “Behavior” drop down is left at “”).
However, if I select the Archive behavior, instead of “Hello World!”
I get:

<div><strong>undefined tag `hello'</strong></div>

Any thoughts? If it’s a bug I’m happy to look into the cause. I just
thought I’d ask on the list before I started spelunking.

  • Sean

PS I’m running on trunk revision 114

Sean,

You may have found a bug that happened to me too! I used <r:parent>
tags
(from somebody’s plugin) on some of my pages (that had the Commentable
behavior), and now they are broken, but somehow the code_behavior plugin
isn’t. Maybe there’s a subtle difference in the code that I’m missing?

Sean C.
seancribbs.com

The same thing happened to me, too, as described here:

http://www.ruby-forum.com/topic/80740

It always happens if I assign a behavior to the page that has a
“define_tags” section, while behaviors wthout specific tags leave my
global tags untouched.

So I guess what happens is that the behavior class overwrites the tags
defined in the Behavior::Base extension instead of adding their tags to
it.

Could that be the case?

Wolfgang

I think that if you move your global tags definition into the
PageContext.rbyou wont have that problem, if these are realy global
tags I think this is
where you want them.
Or create a plugin that extends PageContext.
Dror

Just wanted to tell you that I found an albeit ugly solution to my
problem:

http://www.ruby-forum.com/topic/80740

Maybe it’s of help for you, too.

Cheers,
Wolfgang

Wolfgang,

Instead of changing PageContext, change Behavior::Base, like so

Behavior::Base.define_tags do
tag “mytag” do |tag|

end

end

Just make sure that it loads before anything else, i.e. make the plugin
folder start with 01_ or something.

Cheers,

Sean C.
seancribbs.com

Thanks for the suggestion!

I tried reopening PageContext and adding my define_tags in a plugin, but
Rails didn’t seem to like that and refused to start. I required
page_context.rb to load the model class during plugin initialization and
extend it properly, but that approach didn’t work.

Any idea what I’m doing wrong?

Wolfgang

Sean,

thanks, but that’s exactly what I’m doing right now - I just thought
extending PageContext might be the more elegant solution than prefixing
my plugin directories… Anyway - I’ll go with what works.

Cheers,
Wolfgang

Sean C. wrote:

Yeah, I don’t know that it will get you anything, though. At issue is the
order in which the tags are loaded/defined, i.e. if a behavior is defined
before your global tags, those global tags won’t work on pages that have
the
behavior.

But if you can define them on PageContext they will be available on
every page.

Wolfgang, are you overriding PageContext#intialize and then calling
#define_tag ?


John L.
http://wiseheartdesign.com

Hi Wolfgang and John,

It might be worth if it works in production and not in development, I
had a
similar problem with the PageContext and with a tagging plugin I did. My
solution was to put the code in PageContext.rb - test it in development
and
then move it to the plugin and test again in production.
I know this is a ugly solution, but I fifn’t find any other,

Dror

Wolfgang,

Yeah, I don’t know that it will get you anything, though. At issue is
the
order in which the tags are loaded/defined, i.e. if a behavior is
defined
before your global tags, those global tags won’t work on pages that have
the
behavior.

Sean

Wolfgang Wopperer wrote:

If I understand you correctly, I have to override the initialize method
and call define_tags from there?

Something like this would probably work:

require ‘page_context’

class PageContext < Radius::Context
def initialize(page)
super

   define_tag "hello" do
     "hello world!"
   end

   . . .

 end

end


John L.
http://wiseheartdesign.com

John,

at the moment, I only have something like this:

class PageContext
define_tags do

end
end

If I understand you correctly, I have to override the initialize method
and call define_tags from there?

Thanks for further explanations!

Wolfgang

Thanks for the information, John.

Unfortunately, that didn’t work, too. But since I can’t test it locally
at the moment and hence provide no details, I’ll go with the other
solution for the moment and post again when I can tell you more.

Wolfgang