noosfero | Ucsal Plugin (#505)
Rodrigo Souto
gitlab at gitlab.com
Thu Mar 12 17:19:32 BRT 2015
New comment for Merge Request 505
https://gitlab.com/noosfero/noosfero/merge_requests/505#note_948094
Rodrigo Souto
This is a plugin hotspot. We don't want to add plugins' codes on the core.
Do something like this (it's not tested):
```diff
diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb
index a98643e..956e895 100644
--- a/lib/noosfero/plugin.rb
+++ b/lib/noosfero/plugin.rb
@@ -35,6 +35,7 @@ class Noosfero::Plugin
# filters must be loaded after all extensions
klasses.each do |plugin|
load_plugin_filters plugin
+ load_plugin_hotspots plugin
end
end
@@ -108,6 +109,19 @@ class Noosfero::Plugin
end
end
+ # This is a generic method to extend the hotspots list with plugins
+ # hotspots. This allows plugins to extend other plugins.
+ # To use this, the plugin must define its hotspots inside a module Hotspots.
+ # Checkout FooPlugin for usage example.
+ #
+ # TODO The hotspots must be namespaced with the plugin name to avoid
+ # conflicts. If there is anyway to do that automatically, that'd be nice.
+ def load_plugin_hotspots(plugin)
+ ActionDispatch::Reloader.to_prepare do
+ self.send(:include, plugin::Hotspots)
+ end
+ end
+
def add_controller_filters(controller_class, plugin, filters)
unless filters.is_a?(Array)
filters = [filters]
diff --git a/plugins/foo/lib/foo_plugin.rb b/plugins/foo/lib/foo_plugin.rb
index ed1340c..222137e 100644
--- a/plugins/foo/lib/foo_plugin.rb
+++ b/plugins/foo/lib/foo_plugin.rb
@@ -1,5 +1,12 @@
class FooPlugin < Noosfero::Plugin
+ module Hotspots
+ #TODO Find a way to namespace the method automatically instead of depending
+ #on developers remembering it.
+ def foo_plugin_my_hotspot(a, b, c)
+ end
+ end
+
def self.plugin_name
"Foo"
end
```
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://listas.softwarelivre.org/pipermail/noosfero-dev/attachments/20150312/110b52d0/attachment.html>
More information about the Noosfero-dev
mailing list