diff --git a/app/views/layouts/application-ng.rhtml b/app/views/layouts/application-ng.rhtml index c6dcb04..a3fb7e6 100644 --- a/app/views/layouts/application-ng.rhtml +++ b/app/views/layouts/application-ng.rhtml @@ -27,6 +27,11 @@ <%= javascript_src_tag plugin.class.public_path(js_file), {} %> <% end %> <% end %> + <%= + @plugins.map(:head_ending).collect do |content| + content.respond_to?(:call) ? content.call : content + end.join('\n') + %> + <% button_bar do %> <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> diff --git a/lib/noosfero/plugin.rb b/lib/noosfero/plugin.rb index a51e3e8..7471204 100644 --- a/lib/noosfero/plugin.rb +++ b/lib/noosfero/plugin.rb @@ -108,6 +108,12 @@ class Noosfero::Plugin nil end + # -> Adds content to profile editor info and settings + # returns = lambda block that creates html code or raw rhtml/html.erb + def profile_editor_extras + nil + end + # -> Adds content to calalog list item # returns = lambda block that creates a html code def catalog_list_item_extras(item) @@ -140,6 +146,12 @@ class Noosfero::Plugin nil end + # -> Adds content to the ending of the page head + # returns = lambda block that creates html code or raw rhtml/html.erb + def head_ending + nil + end + # -> Adds plugins' javascript files to application # returns = ['example1.js', 'javascripts/example2.js', 'example3.js'] def js_files diff --git a/plugins/google_analytics/doc/google_analytics.textile b/plugins/google_analytics/doc/google_analytics.textile new file mode 100644 index 0000000..acd6210 --- /dev/null +++ b/plugins/google_analytics/doc/google_analytics.textile @@ -0,0 +1,28 @@ +h1. Google Analytics + +Tracking and web analytics to people and communities. + +h2. Usage + +* Create a "Google Analytics":http://www.google.com/analytics/ account +* Configure your Google Analytics account following these steps + +!=/plugins/google_analytics/images/doc/google-analytics-setup-step1.en.png(Google Setup - Step 1)! + +!=/plugins/google_analytics/images/doc/google-analytics-setup-step2.en.png(Google Setup - Step 2)! + +!=/plugins/google_analytics/images/doc/google-analytics-setup-step3.en.png(Google Setup - Step 3)! + +!=/plugins/google_analytics/images/doc/google-analytics-setup-step4.en.png(Google Setup - Step 4)! + +!=/plugins/google_analytics/images/doc/google-analytics-setup-step5.en.png(Google Setup - Step 5)! + +!=/plugins/google_analytics/images/doc/google-analytics-setup-step6.en.png(Google Setup - Step 6)! + +* Take note of your Google Analytics Profile ID +* Login to Noosfero and go to your control panel +* Follow Profile Info and Settings and fill in Google Analytics Profile ID + +h2. Info + +* "Google Analytics Support":http://support.google.com/analytics diff --git a/plugins/google_analytics/lib/ext/profile.rb b/plugins/google_analytics/lib/ext/profile.rb new file mode 100644 index 0000000..8c966a1 --- /dev/null +++ b/plugins/google_analytics/lib/ext/profile.rb @@ -0,0 +1,5 @@ +require_dependency 'profile' + +class Profile + settings_items :google_analytics_profile_id +end diff --git a/plugins/google_analytics/lib/google_analytics_plugin.rb b/plugins/google_analytics/lib/google_analytics_plugin.rb new file mode 100644 index 0000000..c3ba21b --- /dev/null +++ b/plugins/google_analytics/lib/google_analytics_plugin.rb @@ -0,0 +1,31 @@ +require_dependency 'ext/profile' + +class GoogleAnalyticsPlugin < Noosfero::Plugin + + include ActionView::Helpers::JavaScriptHelper + include ActionView::Helpers::FormHelper + include ApplicationHelper + + def self.plugin_name + "Google Analytics" + end + + def self.plugin_description + _("Tracking and web analytics to people and communities") + end + + def profile_id + context.profile && context.profile.data[:google_analytics_profile_id] + end + + def head_ending + unless profile_id.blank? + expanded_template('tracking-code.rhtml',{:profile_id => profile_id}) + end + end + + def profile_editor_extras + labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => context.profile.google_analytics_profile_id)) + end + +end diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step1.en.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step1.en.png new file mode 100644 index 0000000..dc4d568 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step1.en.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step1.pt.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step1.pt.png new file mode 100644 index 0000000..c91f251 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step1.pt.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step2.en.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step2.en.png new file mode 100644 index 0000000..8bce567 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step2.en.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step2.pt.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step2.pt.png new file mode 100644 index 0000000..613b21e Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step2.pt.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step3.en.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step3.en.png new file mode 100644 index 0000000..233e331 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step3.en.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step3.pt.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step3.pt.png new file mode 100644 index 0000000..eb36828 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step3.pt.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step4.en.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step4.en.png new file mode 100644 index 0000000..4ee5295 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step4.en.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step4.pt.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step4.pt.png new file mode 100644 index 0000000..590467b Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step4.pt.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step5.en.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step5.en.png new file mode 100644 index 0000000..88c28d4 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step5.en.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step5.pt.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step5.pt.png new file mode 100644 index 0000000..ef23f16 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step5.pt.png differ diff --git a/plugins/google_analytics/public/images/doc/google-analytics-setup-step6.en.png b/plugins/google_analytics/public/images/doc/google-analytics-setup-step6.en.png new file mode 100644 index 0000000..4506842 Binary files /dev/null and b/plugins/google_analytics/public/images/doc/google-analytics-setup-step6.en.png differ diff --git a/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb b/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb new file mode 100644 index 0000000..1e08393 --- /dev/null +++ b/plugins/google_analytics/test/unit/google_analytics_plugin_test.rb @@ -0,0 +1,38 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' + +class GoogleAnalyticsPluginTest < Test::Unit::TestCase + + def setup + @plugin = GoogleAnalyticsPlugin.new + @context = mock() + @profile = mock() + @profile.stubs(:data).returns({:google_analytics_profile_id => 10}) + @profile.stubs(:google_analytics_profile_id).returns(10) + @plugin.context = @context + @context.stubs(:profile).returns(@profile) + end + + should 'return profile_id nil if not in profile context' do + @context.stubs(:profile).returns(nil) + assert_nil @plugin.profile_id + end + + should 'return profile_id if in profile context' do + assert_not_nil @plugin.profile_id + assert_equal 10, @plugin.profile_id + end + + should 'add content at HTML head if profile_id not nil' do + @plugin.expects(:expanded_template).once.returns('content') + assert_equal 'content', @plugin.head_ending + end + + should 'add extra fields to profile editor info and settings' do + assert_tag_in_string @plugin.profile_editor_extras, + :tag => 'input', :attributes => {:id => 'profile_data_google_analytics_profile_id', :value => 10} + end + + should 'extends Profile with attr google_analytics_profile_id' do + assert_respond_to Profile.new, :google_analytics_profile_id + end +end diff --git a/plugins/google_analytics/views/tracking-code.rhtml b/plugins/google_analytics/views/tracking-code.rhtml new file mode 100644 index 0000000..8b89062 --- /dev/null +++ b/plugins/google_analytics/views/tracking-code.rhtml @@ -0,0 +1,10 @@ + diff --git a/test/functional/admin_panel_controller_test.rb b/test/functional/admin_panel_controller_test.rb index cf7b6b6..46d4468 100644 --- a/test/functional/admin_panel_controller_test.rb +++ b/test/functional/admin_panel_controller_test.rb @@ -350,6 +350,7 @@ class AdminPanelControllerTest < Test::Unit::TestCase plugins.stubs(:map).with(:admin_panel_links).returns(links) plugins.stubs(:enabled_plugins).returns([]) plugins.stubs(:map).with(:body_beginning).returns([]) + plugins.stubs(:map).with(:head_ending).returns([]) Noosfero::Plugin::Manager.stubs(:new).returns(plugins) get :index diff --git a/test/functional/application_controller_test.rb b/test/functional/application_controller_test.rb index b623717..841e802 100644 --- a/test/functional/application_controller_test.rb +++ b/test/functional/application_controller_test.rb @@ -507,6 +507,7 @@ class ApplicationControllerTest < Test::Unit::TestCase plugins = mock() plugins.stubs(:enabled_plugins).returns([]) plugins.stubs(:map).with(:body_beginning).returns(contents) + plugins.stubs(:map).with(:head_ending).returns([]) Noosfero::Plugin::Manager.stubs(:new).returns(plugins) get :index @@ -515,6 +516,24 @@ class ApplicationControllerTest < Test::Unit::TestCase assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'} end + should 'include content in the ending of head supplied by plugins regardless it is a block or html code' do + plugin1_local_variable = "Plugin1" + plugin1_content = lambda {""} + plugin2_content = "" + contents = [plugin1_content, plugin2_content] + + plugins = mock() + plugins.stubs(:enabled_plugins).returns([]) + plugins.stubs(:map).with(:head_ending).returns(contents) + plugins.stubs(:map).with(:body_beginning).returns([]) + Noosfero::Plugin::Manager.stubs(:new).returns(plugins) + + get :index + + assert_tag :tag => 'script', :content => "alert('This is #{plugin1_local_variable} speaking!')" + assert_tag :tag => 'style', :content => 'This is Plugin2 speaking!' + end + if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' should 'change postgresql schema' do diff --git a/test/functional/manage_products_controller_test.rb b/test/functional/manage_products_controller_test.rb index 24bb76f..58442de 100644 --- a/test/functional/manage_products_controller_test.rb +++ b/test/functional/manage_products_controller_test.rb @@ -447,6 +447,7 @@ class ManageProductsControllerTest < Test::Unit::TestCase plugins = mock() plugins.stubs(:enabled_plugins).returns([]) plugins.stubs(:map).with(:body_beginning).returns([]) + plugins.stubs(:map).with(:head_ending).returns([]) plugins.stubs(:map).with(:product_info_extras, product).returns(contents) Noosfero::Plugin::Manager.stubs(:new).returns(plugins) diff --git a/test/functional/profile_editor_controller_test.rb b/test/functional/profile_editor_controller_test.rb index 3fd0eb5..a717879 100644 --- a/test/functional/profile_editor_controller_test.rb +++ b/test/functional/profile_editor_controller_test.rb @@ -870,6 +870,7 @@ class ProfileEditorControllerTest < Test::Unit::TestCase plugins.stubs(:map).with(:control_panel_buttons).returns(buttons) plugins.stubs(:enabled_plugins).returns([]) plugins.stubs(:map).with(:body_beginning).returns([]) + plugins.stubs(:map).with(:head_ending).returns([]) Noosfero::Plugin::Manager.stubs(:new).returns(plugins) get :index, :profile => profile.identifier @@ -878,4 +879,18 @@ class ProfileEditorControllerTest < Test::Unit::TestCase assert_tag :tag => 'a', :content => plugin2_button[:title], :attributes => {:class => /#{plugin2_button[:icon]}/, :href => /#{plugin2_button[:url]}/} end + should 'add extra content provided by plugins on edit' do + plugin1_content = "" + plugins = mock() + plugins.stubs(:enabled_plugins).returns([]) + plugins.stubs(:map).with(:profile_editor_extras).returns([plugin1_content]) + plugins.stubs(:map).with(:head_ending).returns([]) + plugins.stubs(:map).with(:body_beginning).returns([]) + Noosfero::Plugin::Manager.stubs(:new).returns(plugins) + + get :edit, :profile => profile.identifier + + assert_tag :tag => 'input', :attributes => {:id => 'field_added_by_plugin', :value => 'value_of_field_added_by_plugin'} + end + end -- libgit2 0.21.2