Extending admin_ui?

Hi everybody

I need your help.

I would like to know if it’s possile to extend the class AdminUI in
module Radiant. I try to do it by creating a folder Radiant in the lib
folder of my extension, and then create a module Radiant within a class
AdminUI. In this class I modify the Tab class.

When I do that, my class is not loaded when server start.

Then, is it possible to extend the class AdminUi like this ?

Thanks for helping me.


Stephane

On May 26, 2007, at 6:17 PM, Stephane B. wrote:

I would like to know if it’s possile to extend the class AdminUI in
module Radiant. I try to do it by creating a folder Radiant in the lib
folder of my extension, and then create a module Radiant within a
class
AdminUI. In this class I modify the Tab class.

When I do that, my class is not loaded when server start.

Then, is it possible to extend the class AdminUi like this ?

Stephane, what is the goal of your efforts?

adam

Adam W. wrote:

On May 26, 2007, at 6:17 PM, Stephane B. wrote:

I would like to know if it’s possile to extend the class AdminUI in
module Radiant. I try to do it by creating a folder Radiant in the lib
folder of my extension, and then create a module Radiant within a
class
AdminUI. In this class I modify the Tab class.

When I do that, my class is not loaded when server start.

Then, is it possible to extend the class AdminUi like this ?

Stephane, what is the goal of your efforts?

adam

I would like to create a second level of navigation when needed, then
create a ‘sub tab’ system by simply extending current Tab with a TabSet
accessor.
need to

  • add an accessor
  • a method
  • modify initialize

Stephane

I would like to create a second level of navigation when needed, then
create a ‘sub tab’ system by simply extending current Tab with a TabSet
accessor.
need to

  • add an accessor
  • a method
  • modify initialize

I did it already by patching the code but I would like to do it in an
exension.

It is a pretty standard Ruby practice to re-open the class, but
sometimes I find this doesn’t work as expected. Instead, you can try
doing a class_eval or module_eval on the intended class, which will
make sure it’s auto-loaded before you try to override or extend it.
Example:

Radiant::AdminUI::Tab.class_eval {

your code here

}

Cheers,

Sean

Sean C. wrote:

It is a pretty standard Ruby practice to re-open the class, but
sometimes I find this doesn’t work as expected. Instead, you can try
doing a class_eval or module_eval on the intended class, which will
make sure it’s auto-loaded before you try to override or extend it.
Example:

Radiant::AdminUI::Tab.class_eval {

your code here

}

Cheers,

Sean

Thanks for your help. Finally I put my extended code in the definition
of the extension. It looks to work fine… but not really clean. It
seems that only my folder lib/radiant can’t be loaded :(, is there any
way to force to load this folder ?

I saw when creating a new class, it will load it only if I call an
instance of it; only at this stage radiant/rails will look in the lib
folder. Then in the case of Radiant::AdminUI I guess it will not look in
lib as the class already exist.

Is it a matter of Radiant extension mechanism ?

I will try to improve my code and all suggestions are welcome :slight_smile:

Adam W. wrote:

On May 27, 2007, at 5:48 PM, Stephane B. wrote:

Is it a matter of Radiant extension mechanism ?

If you do not care for the solution you have in place, you could
place your code in a file like /lib/radiant/admin_ui_ext.rb,
then in your extension loader, ‘require “radiant/admin_ui_ext”’. Now
the ugly is in the fact that you have a file named slightly
differently than the class it contains, and reloading will not work,
as far as I understand dependencies.rb (a Rails thing).

So, I guess you may have to leave it the way it is.

adam williams

I tried to do like this and I got “already initialized constant” error
message. But mechanism is now clear for me. thanks for the help :slight_smile:

On May 27, 2007, at 5:48 PM, Stephane B. wrote:

Is it a matter of Radiant extension mechanism ?

As you suspect, Radiant::AdminUI is discovered before your extension
is loaded. Your file will not be discovered; the dependencies
mechanism which provides for the discovery of missing constants will
not be triggered - Radiant::AdminUI is not missing, though if it
were, it would find it in your /lib.

If you do not care for the solution you have in place, you could
place your code in a file like /lib/radiant/admin_ui_ext.rb,
then in your extension loader, ‘require “radiant/admin_ui_ext”’. Now
the ugly is in the fact that you have a file named slightly
differently than the class it contains, and reloading will not work,
as far as I understand dependencies.rb (a Rails thing).

So, I guess you may have to leave it the way it is.

adam williams

This forum is not affiliated to the Ruby language, Ruby on Rails framework, nor any Ruby applications discussed here.

| Privacy Policy | Terms of Service | Remote Ruby Jobs