On Domingo, 24 de Mayo de 2009 21:10:57 Ed W escribió:
> [email protected] wrote:
> > AS includes only files which extend rails (lib/extensions), but it
> > doesn't include own classes. When an ActiveScaffold class is used, if it
> > isn't loaded, rails load it automatically. But when a plugin define an
> > ActiveScaffold class in initialization, it breaks autoloading. So you
> > must use ActiveScaffold::Config::Core.class_eval,
>
> Thanks for confirming this.
>
> When did this behaviour change though? Clearly it worked in the past
> because every other AS plugin is written like this?
>
> Aha, re-reading your comment - you say AS only includes these files, so
> presumably there was a change in the past to avoid autoloading
> everything and leave it to the interpreter to load only what is needed?
Yes, I think it was changed for rails 2.2
>
> > or define methods in other
> > module and use ActiveScaffold::Config::Core.send :include, PluginModule.
> > I use this methods when I build ActiveScaffold plugins.
>
> Hmm, this could be neater
>
> Have you got an example of how you do it? It might be interesting to
> align the naming so that the autoloading works on plugin classes also.
> It would perhaps make sense to make a module with the same name as the
> class in an appropriately named file and tuck in a .send at the end of
> the file?
You have an example in ActiveScaffold's environment.rb. ViewHelpers are
included into ActionView::Base
You only need create a directory for each namespace. For example for a
ActiveScaffoldExport::Helpers module, create an active_scaffold_export
directory
and put helpers.rb file inside. In your init.rb add
ActiveScaffold::Helpers::ViewHelpers.send :include ActiveScaffoldExport::Helpers
>
>
> I'm now stuck on how to inject view paths from a plugin into the main AS
> search path. It means somehow affecting either @active_scaffold_paths
> or @active_scaffold_frontends. Would you be averse to adding some
> setter methods here to allow it to be mangled? I think just an
> "active_scaffold_paths=" would be enough (assuming plugin loading order
> is after AS), but alternatively we could introduce a pre_ and post_ set
> of paths which are prepended and postpended to the AS frontend paths?
You should modify active_scaffold_frontends or active_scaffold_overrides, never
active_scaffold_paths. Plugins should add their view paths at the end of
active_scaffold_overrides or at the beginning of active_scaffold_frontends, so
users can override plugin's views, and plugin can override ActiveScaffold's
views.
I usually use @active_scaffold_frontends.unshift view_path, in self.included:
module ActiveScaffoldPlugin
def self.included(base)
base.class_eval do
@active_scaffold_frontends.unshitf 'view_path'
end
end
end
Maybe it would be better to add a method add_active_scaffold_path which add a
view path between active_scaffold_overrides and active_scaffold_frontends.
>
> Ed W
>
>
--
Sergio Cambra .:: entreCables S.L. ::.
Nicolás Guillén 6, locales 2 y 3. 50.018 Zaragoza
T) 902 021 404 F) 976 52 98 07 E) [email protected]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"ActiveScaffold : Ruby on Rails plugin" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/activescaffold?hl=en
-~----------~----~----~----~------~----~------~--~---