Commit 604eb3f6bb8d6ad9515ea0d596ae29b1d51d87bb

Authored by Rodrigo Souto
1 parent 3b83c471

plugins-infra: add infra support to core extensions

The core extensions now should be created inside the folder lib/ext.
They will automatically loaded, so no need for the requires on the
plugin class definition file.

Further information on how to use this feature here:
http://noosfero.org/Development/PluginsArchitecture#Extending_core_classes
Showing 31 changed files with 75 additions and 104 deletions   Show diff stats
lib/noosfero/plugin.rb
... ... @@ -64,6 +64,9 @@ class Noosfero::Plugin
64 64 require init.gsub(/.rb$/, '') if File.file? init
65 65 end
66 66  
  67 + # load extensions
  68 + Dir[File.join(dir, 'lib', 'ext', '*.rb')].each {|file| require_dependency file }
  69 +
67 70 # load class
68 71 klass(plugin_name)
69 72 end
... ...
plugins/bsc/lib/bsc_plugin.rb
1   -require_dependency 'bsc_plugin/ext/enterprise'
2   -require_dependency 'bsc_plugin/ext/product'
3   -
4 1 class BscPlugin < Noosfero::Plugin
5 2  
6 3 Bsc
... ...
plugins/comment_group/lib/comment_group_plugin.rb
1   -require_dependency 'comment_group_plugin/ext/article'
2   -require_dependency 'comment_group_plugin/ext/comment'
3   -
4 1 class CommentGroupPlugin < Noosfero::Plugin
5 2  
6 3 def self.plugin_name
... ...
plugins/comment_group/lib/comment_group_plugin/ext/article.rb
... ... @@ -1,21 +0,0 @@
1   -require_dependency 'article'
2   -
3   -class Article
4   -
5   - #FIXME make this test
6   - has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL']
7   -
8   - #FIXME make this test
9   - validate :not_empty_group_comments_removed
10   -
11   - #FIXME make this test
12   - def not_empty_group_comments_removed
13   - if body
14   - groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq
15   - groups = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-group_id'].to_i}
16   - errors.add_to_base(N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?
17   - end
18   - end
19   -
20   -end
21   -
plugins/comment_group/lib/comment_group_plugin/ext/comment.rb
... ... @@ -1,12 +0,0 @@
1   -require_dependency 'comment'
2   -
3   -class Comment
4   -
5   - named_scope :without_group, :conditions => {:group_id => nil }
6   -
7   - named_scope :in_group, lambda { |group_id| {
8   - :conditions => ['group_id = ?', group_id]
9   - }
10   - }
11   -
12   -end
plugins/comment_group/lib/ext/article.rb 0 → 100644
... ... @@ -0,0 +1,21 @@
  1 +require_dependency 'article'
  2 +
  3 +class Article
  4 +
  5 + #FIXME make this test
  6 + has_many :group_comments, :class_name => 'Comment', :foreign_key => 'source_id', :dependent => :destroy, :order => 'created_at asc', :conditions => [ 'group_id IS NOT NULL']
  7 +
  8 + #FIXME make this test
  9 + validate :not_empty_group_comments_removed
  10 +
  11 + #FIXME make this test
  12 + def not_empty_group_comments_removed
  13 + if body
  14 + groups_with_comments = group_comments.collect {|comment| comment.group_id}.uniq
  15 + groups = Hpricot(body.to_s).search('.macro').collect{|element| element['data-macro-group_id'].to_i}
  16 + errors.add_to_base(N_('Not empty group comment cannot be removed')) unless (groups_with_comments-groups).empty?
  17 + end
  18 + end
  19 +
  20 +end
  21 +
... ...
plugins/comment_group/lib/ext/comment.rb 0 → 100644
... ... @@ -0,0 +1,12 @@
  1 +require_dependency 'comment'
  2 +
  3 +class Comment
  4 +
  5 + named_scope :without_group, :conditions => {:group_id => nil }
  6 +
  7 + named_scope :in_group, lambda { |group_id| {
  8 + :conditions => ['group_id = ?', group_id]
  9 + }
  10 + }
  11 +
  12 +end
... ...
plugins/custom_forms/lib/custom_forms_plugin.rb
1   -require 'ext/role_assignment_trigger'
2   -
3 1 class CustomFormsPlugin < Noosfero::Plugin
4 2  
5 3 def self.plugin_name
... ...
plugins/foo/lib/ext/profile.rb 0 → 100644
... ... @@ -0,0 +1,6 @@
  1 +require_dependency 'profile'
  2 +
  3 +Profile.class_eval do
  4 + def bar
  5 + end
  6 +end
... ...
plugins/foo/lib/foo_plugin.rb
1   -require_dependency 'foo_plugin/ext/profile'
2   -
3 1 class FooPlugin < Noosfero::Plugin
4 2  
5 3 def self.plugin_name
... ...
plugins/foo/lib/foo_plugin/ext/profile.rb
... ... @@ -1,6 +0,0 @@
1   -require_dependency 'profile'
2   -
3   -Profile.class_eval do
4   - def bar
5   - end
6   -end
plugins/google_analytics/lib/google_analytics_plugin.rb
1   -require_dependency File.dirname(__FILE__) + '/ext/profile'
2   -
3 1 class GoogleAnalyticsPlugin < Noosfero::Plugin
4 2  
5 3 include ActionView::Helpers::JavaScriptHelper
... ...
plugins/ldap/lib/ldap_plugin.rb
1   -require_dependency File.dirname(__FILE__) + '/ext/environment'
2 1 require File.dirname(__FILE__) + '/ldap_authentication.rb'
3 2  
4   -
5 3 class LdapPlugin < Noosfero::Plugin
6 4  
7 5 def self.plugin_name
... ...
plugins/pg_search/lib/pg_search_plugin.rb
1   -require 'ext/active_record'
2   -
3 1 class PgSearchPlugin < Noosfero::Plugin
4 2  
5 3 def self.plugin_name
... ...
plugins/require_auth_to_comment/lib/ext/profile.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'profile'
  2 +
  3 +class Profile
  4 + settings_items :allow_unauthenticated_comments, :type => :boolean
  5 +end
... ...
plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin.rb
1   -require_dependency 'require_auth_to_comment_plugin/ext/profile'
2   -
3 1 class RequireAuthToCommentPlugin < Noosfero::Plugin
4 2  
5 3 include ActionView::Helpers::TagHelper
... ...
plugins/require_auth_to_comment/lib/require_auth_to_comment_plugin/ext/profile.rb
... ... @@ -1,5 +0,0 @@
1   -require_dependency 'profile'
2   -
3   -class Profile
4   - settings_items :allow_unauthenticated_comments, :type => :boolean
5   -end
plugins/shopping_cart/lib/ext/enterprise.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'enterprise'
  2 +
  3 +class Enterprise
  4 + has_many :orders, :class_name => "ShoppingCartPlugin::PurchaseOrder", :foreign_key => 'seller_id'
  5 +end
... ...
plugins/shopping_cart/lib/ext/person.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'person'
  2 +
  3 +class Person
  4 + has_many :purchases, :class_name => "ShoppingCartPlugin::PurchaseOrder", :foreign_key => 'customer_id'
  5 +end
... ...
plugins/shopping_cart/lib/shopping_cart_plugin.rb
1   -require_dependency 'shopping_cart_plugin/ext/enterprise'
2   -require_dependency 'shopping_cart_plugin/ext/person'
3   -
4 1 class ShoppingCartPlugin < Noosfero::Plugin
5 2  
6 3 class << self
... ...
plugins/shopping_cart/lib/shopping_cart_plugin/ext/enterprise.rb
... ... @@ -1,5 +0,0 @@
1   -require_dependency 'enterprise'
2   -
3   -class Enterprise
4   - has_many :orders, :class_name => "ShoppingCartPlugin::PurchaseOrder", :foreign_key => 'seller_id'
5   -end
plugins/shopping_cart/lib/shopping_cart_plugin/ext/person.rb
... ... @@ -1,5 +0,0 @@
1   -require_dependency 'person'
2   -
3   -class Person
4   - has_many :purchases, :class_name => "ShoppingCartPlugin::PurchaseOrder", :foreign_key => 'customer_id'
5   -end
plugins/solr/lib/solr_plugin.rb
... ... @@ -39,5 +39,3 @@ class SolrPlugin &lt; Noosfero::Plugin
39 39 end
40 40  
41 41 end
42   -
43   -Dir[File.join(SolrPlugin.root_path, 'lib', 'ext', '*.rb')].each {|file| require_dependency file }
... ...
plugins/stoa/lib/stoa_plugin.rb
1 1 require_dependency 'person'
2   -require_dependency 'ext/person'
3 2  
4 3 class StoaPlugin < Noosfero::Plugin
5 4  
... ...
plugins/sub_organizations/lib/ext/create_enterprise.rb 0 → 100644
... ... @@ -0,0 +1,5 @@
  1 +require_dependency 'create_enterprise'
  2 +
  3 +class CreateEnterprise
  4 + settings_items :sub_organizations_plugin_parent_to_be
  5 +end
... ...
plugins/sub_organizations/lib/ext/organization.rb 0 → 100644
... ... @@ -0,0 +1,13 @@
  1 +require_dependency 'organization'
  2 +class Organization
  3 + settings_items :sub_organizations_plugin_parent_to_be
  4 +
  5 + after_create do |organization|
  6 + if organization.sub_organizations_plugin_parent_to_be.present?
  7 + parent = Organization.find(organization.sub_organizations_plugin_parent_to_be)
  8 + SubOrganizationsPlugin::Relation.add_children(parent,organization)
  9 + end
  10 + end
  11 +
  12 + FIELDS << 'sub_organizations_plugin_parent_to_be'
  13 +end
... ...
plugins/sub_organizations/lib/sub_organizations_plugin.rb
1   -require_dependency 'sub_organizations_plugin/ext/organization'
2   -require_dependency 'sub_organizations_plugin/ext/create_enterprise'
3   -
4 1 class SubOrganizationsPlugin < Noosfero::Plugin
5 2  
6 3 def self.plugin_name
... ...
plugins/sub_organizations/lib/sub_organizations_plugin/ext/create_enterprise.rb
... ... @@ -1,5 +0,0 @@
1   -require_dependency 'create_enterprise'
2   -
3   -class CreateEnterprise
4   - settings_items :sub_organizations_plugin_parent_to_be
5   -end
plugins/sub_organizations/lib/sub_organizations_plugin/ext/organization.rb
... ... @@ -1,13 +0,0 @@
1   -require_dependency 'organization'
2   -class Organization
3   - settings_items :sub_organizations_plugin_parent_to_be
4   -
5   - after_create do |organization|
6   - if organization.sub_organizations_plugin_parent_to_be.present?
7   - parent = Organization.find(organization.sub_organizations_plugin_parent_to_be)
8   - SubOrganizationsPlugin::Relation.add_children(parent,organization)
9   - end
10   - end
11   -
12   - FIELDS << 'sub_organizations_plugin_parent_to_be'
13   -end
plugins/tolerance_time/lib/tolerance_time_plugin.rb
1   -require_dependency 'ext/article'
2   -require_dependency 'ext/comment'
3   -
4 1 class ToleranceTimePlugin < Noosfero::Plugin
5 2  
6 3 def self.plugin_name
... ...
plugins/work_assignment/lib/work_assignment_plugin.rb
1   -require_dependency 'ext/uploaded_file'
2   -
3 1 class WorkAssignmentPlugin < Noosfero::Plugin
4 2  
5 3 def self.plugin_name
... ...