Commit 92273fb259c123c5db4165225eb7e81f9a00c560
Exists in
master
and in
29 other branches
Merge branch 'master' into rails-2.3.5
Showing
23 changed files
with
171 additions
and
0 deletions
Show diff stats
app/views/layouts/application-ng.rhtml
... | ... | @@ -27,6 +27,11 @@ |
27 | 27 | <%= javascript_src_tag plugin.class.public_path(js_file), {} %> |
28 | 28 | <% end %> |
29 | 29 | <% end %> |
30 | + <%= | |
31 | + @plugins.map(:head_ending).collect do |content| | |
32 | + content.respond_to?(:call) ? content.call : content | |
33 | + end.join('\n') | |
34 | + %> | |
30 | 35 | </head> |
31 | 36 | <body class="<%= |
32 | 37 | # Identify the current controller and action for the CSS: | ... | ... |
app/views/profile_editor/edit.rhtml
... | ... | @@ -75,6 +75,12 @@ |
75 | 75 | |
76 | 76 | <%= select_categories(:profile_data, _('Select the categories of your interest'), 2) %> |
77 | 77 | |
78 | + <%= | |
79 | + @plugins.map(:profile_editor_extras).each do |content| | |
80 | + content.respond_to?(:call) ? content.call : content | |
81 | + end.join("\n") | |
82 | + %> | |
83 | + | |
78 | 84 | <% button_bar do %> |
79 | 85 | <%= submit_button('save', _('Save'), :cancel => {:action => 'index'}) %> |
80 | 86 | <%= button(:back, _('Back to control panel'), :controller => 'profile_editor') %> | ... | ... |
lib/noosfero/plugin.rb
... | ... | @@ -108,6 +108,12 @@ class Noosfero::Plugin |
108 | 108 | nil |
109 | 109 | end |
110 | 110 | |
111 | + # -> Adds content to profile editor info and settings | |
112 | + # returns = lambda block that creates html code or raw rhtml/html.erb | |
113 | + def profile_editor_extras | |
114 | + nil | |
115 | + end | |
116 | + | |
111 | 117 | # -> Adds content to calalog list item |
112 | 118 | # returns = lambda block that creates a html code |
113 | 119 | def catalog_list_item_extras(item) |
... | ... | @@ -140,6 +146,12 @@ class Noosfero::Plugin |
140 | 146 | nil |
141 | 147 | end |
142 | 148 | |
149 | + # -> Adds content to the ending of the page head | |
150 | + # returns = lambda block that creates html code or raw rhtml/html.erb | |
151 | + def head_ending | |
152 | + nil | |
153 | + end | |
154 | + | |
143 | 155 | # -> Adds plugins' javascript files to application |
144 | 156 | # returns = ['example1.js', 'javascripts/example2.js', 'example3.js'] |
145 | 157 | def js_files | ... | ... |
... | ... | @@ -0,0 +1,28 @@ |
1 | +h1. Google Analytics | |
2 | + | |
3 | +Tracking and web analytics to people and communities. | |
4 | + | |
5 | +h2. Usage | |
6 | + | |
7 | +* Create a "Google Analytics":http://www.google.com/analytics/ account | |
8 | +* Configure your Google Analytics account following these steps | |
9 | + | |
10 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step1.en.png(Google Setup - Step 1)! | |
11 | + | |
12 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step2.en.png(Google Setup - Step 2)! | |
13 | + | |
14 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step3.en.png(Google Setup - Step 3)! | |
15 | + | |
16 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step4.en.png(Google Setup - Step 4)! | |
17 | + | |
18 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step5.en.png(Google Setup - Step 5)! | |
19 | + | |
20 | +!=/plugins/google_analytics/images/doc/google-analytics-setup-step6.en.png(Google Setup - Step 6)! | |
21 | + | |
22 | +* Take note of your Google Analytics Profile ID | |
23 | +* Login to Noosfero and go to your control panel | |
24 | +* Follow Profile Info and Settings and fill in Google Analytics Profile ID | |
25 | + | |
26 | +h2. Info | |
27 | + | |
28 | +* "Google Analytics Support":http://support.google.com/analytics | ... | ... |
... | ... | @@ -0,0 +1,31 @@ |
1 | +require_dependency 'ext/profile' | |
2 | + | |
3 | +class GoogleAnalyticsPlugin < Noosfero::Plugin | |
4 | + | |
5 | + include ActionView::Helpers::JavaScriptHelper | |
6 | + include ActionView::Helpers::FormHelper | |
7 | + include ApplicationHelper | |
8 | + | |
9 | + def self.plugin_name | |
10 | + "Google Analytics" | |
11 | + end | |
12 | + | |
13 | + def self.plugin_description | |
14 | + _("Tracking and web analytics to people and communities") | |
15 | + end | |
16 | + | |
17 | + def profile_id | |
18 | + context.profile && context.profile.data[:google_analytics_profile_id] | |
19 | + end | |
20 | + | |
21 | + def head_ending | |
22 | + unless profile_id.blank? | |
23 | + expanded_template('tracking-code.rhtml',{:profile_id => profile_id}) | |
24 | + end | |
25 | + end | |
26 | + | |
27 | + def profile_editor_extras | |
28 | + labelled_form_field(_('Google Analytics Profile ID'), text_field(:profile_data, :google_analytics_profile_id, :value => context.profile.google_analytics_profile_id)) | |
29 | + end | |
30 | + | |
31 | +end | ... | ... |
plugins/google_analytics/public/images/doc/google-analytics-setup-step1.en.png
0 → 100644
107 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step1.pt.png
0 → 100644
116 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step2.en.png
0 → 100644
65.5 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step2.pt.png
0 → 100644
86.2 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step3.en.png
0 → 100644
38.7 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step3.pt.png
0 → 100644
56 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step4.en.png
0 → 100644
116 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step4.pt.png
0 → 100644
119 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step5.en.png
0 → 100644
75.4 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step5.pt.png
0 → 100644
83.2 KB
plugins/google_analytics/public/images/doc/google-analytics-setup-step6.en.png
0 → 100644
74.6 KB
plugins/google_analytics/test/unit/google_analytics_plugin_test.rb
0 → 100644
... | ... | @@ -0,0 +1,38 @@ |
1 | +require File.dirname(__FILE__) + '/../../../../test/test_helper' | |
2 | + | |
3 | +class GoogleAnalyticsPluginTest < Test::Unit::TestCase | |
4 | + | |
5 | + def setup | |
6 | + @plugin = GoogleAnalyticsPlugin.new | |
7 | + @context = mock() | |
8 | + @profile = mock() | |
9 | + @profile.stubs(:data).returns({:google_analytics_profile_id => 10}) | |
10 | + @profile.stubs(:google_analytics_profile_id).returns(10) | |
11 | + @plugin.context = @context | |
12 | + @context.stubs(:profile).returns(@profile) | |
13 | + end | |
14 | + | |
15 | + should 'return profile_id nil if not in profile context' do | |
16 | + @context.stubs(:profile).returns(nil) | |
17 | + assert_nil @plugin.profile_id | |
18 | + end | |
19 | + | |
20 | + should 'return profile_id if in profile context' do | |
21 | + assert_not_nil @plugin.profile_id | |
22 | + assert_equal 10, @plugin.profile_id | |
23 | + end | |
24 | + | |
25 | + should 'add content at HTML head if profile_id not nil' do | |
26 | + @plugin.expects(:expanded_template).once.returns('content') | |
27 | + assert_equal 'content', @plugin.head_ending | |
28 | + end | |
29 | + | |
30 | + should 'add extra fields to profile editor info and settings' do | |
31 | + assert_tag_in_string @plugin.profile_editor_extras, | |
32 | + :tag => 'input', :attributes => {:id => 'profile_data_google_analytics_profile_id', :value => 10} | |
33 | + end | |
34 | + | |
35 | + should 'extends Profile with attr google_analytics_profile_id' do | |
36 | + assert_respond_to Profile.new, :google_analytics_profile_id | |
37 | + end | |
38 | +end | ... | ... |
... | ... | @@ -0,0 +1,10 @@ |
1 | +<script type="text/javascript"> | |
2 | + var _gaq = _gaq || []; | |
3 | + _gaq.push(['_setAccount', '<%= escape_javascript locals[:profile_id] %>']); | |
4 | + _gaq.push(['_trackPageview']); | |
5 | + (function() { | |
6 | + var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true; | |
7 | + ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js'; | |
8 | + var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s); | |
9 | + })(); | |
10 | +</script> | ... | ... |
test/functional/admin_panel_controller_test.rb
... | ... | @@ -349,6 +349,7 @@ class AdminPanelControllerTest < ActionController::TestCase |
349 | 349 | plugins.stubs(:map).with(:admin_panel_links).returns(links) |
350 | 350 | plugins.stubs(:enabled_plugins).returns([]) |
351 | 351 | plugins.stubs(:map).with(:body_beginning).returns([]) |
352 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
352 | 353 | Noosfero::Plugin::Manager.stubs(:new).returns(plugins) |
353 | 354 | |
354 | 355 | get :index | ... | ... |
test/functional/application_controller_test.rb
... | ... | @@ -400,6 +400,7 @@ class ApplicationControllerTest < ActionController::TestCase |
400 | 400 | plugins = mock() |
401 | 401 | plugins.stubs(:enabled_plugins).returns([]) |
402 | 402 | plugins.stubs(:map).with(:body_beginning).returns(contents) |
403 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
403 | 404 | Noosfero::Plugin::Manager.stubs(:new).returns(plugins) |
404 | 405 | |
405 | 406 | get :index |
... | ... | @@ -408,6 +409,24 @@ class ApplicationControllerTest < ActionController::TestCase |
408 | 409 | assert_tag :tag => 'span', :content => 'This is Plugin2 speaking!', :attributes => {:id => 'plugin2'} |
409 | 410 | end |
410 | 411 | |
412 | + should 'include content in the ending of head supplied by plugins regardless it is a block or html code' do | |
413 | + plugin1_local_variable = "Plugin1" | |
414 | + plugin1_content = lambda {"<script>alert('This is #{plugin1_local_variable} speaking!')</script>"} | |
415 | + plugin2_content = "<style>This is Plugin2 speaking!</style>" | |
416 | + contents = [plugin1_content, plugin2_content] | |
417 | + | |
418 | + plugins = mock() | |
419 | + plugins.stubs(:enabled_plugins).returns([]) | |
420 | + plugins.stubs(:map).with(:head_ending).returns(contents) | |
421 | + plugins.stubs(:map).with(:body_beginning).returns([]) | |
422 | + Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
423 | + | |
424 | + get :index | |
425 | + | |
426 | + assert_tag :tag => 'script', :content => "alert('This is #{plugin1_local_variable} speaking!')" | |
427 | + assert_tag :tag => 'style', :content => 'This is Plugin2 speaking!' | |
428 | + end | |
429 | + | |
411 | 430 | if ActiveRecord::Base.connection.adapter_name == 'PostgreSQL' |
412 | 431 | |
413 | 432 | should 'change postgresql schema' do | ... | ... |
test/functional/manage_products_controller_test.rb
... | ... | @@ -446,6 +446,7 @@ class ManageProductsControllerTest < ActionController::TestCase |
446 | 446 | plugins = mock() |
447 | 447 | plugins.stubs(:enabled_plugins).returns([]) |
448 | 448 | plugins.stubs(:map).with(:body_beginning).returns([]) |
449 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
449 | 450 | plugins.stubs(:map).with(:product_info_extras, product).returns(contents) |
450 | 451 | Noosfero::Plugin::Manager.stubs(:new).returns(plugins) |
451 | 452 | ... | ... |
test/functional/profile_editor_controller_test.rb
... | ... | @@ -869,6 +869,7 @@ class ProfileEditorControllerTest < ActionController::TestCase |
869 | 869 | plugins.stubs(:map).with(:control_panel_buttons).returns(buttons) |
870 | 870 | plugins.stubs(:enabled_plugins).returns([]) |
871 | 871 | plugins.stubs(:map).with(:body_beginning).returns([]) |
872 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
872 | 873 | Noosfero::Plugin::Manager.stubs(:new).returns(plugins) |
873 | 874 | |
874 | 875 | get :index, :profile => profile.identifier |
... | ... | @@ -877,4 +878,18 @@ class ProfileEditorControllerTest < ActionController::TestCase |
877 | 878 | assert_tag :tag => 'a', :content => plugin2_button[:title], :attributes => {:class => /#{plugin2_button[:icon]}/, :href => /#{plugin2_button[:url]}/} |
878 | 879 | end |
879 | 880 | |
881 | + should 'add extra content provided by plugins on edit' do | |
882 | + plugin1_content = "<input id='field_added_by_plugin' value='value_of_field_added_by_plugin'/>" | |
883 | + plugins = mock() | |
884 | + plugins.stubs(:enabled_plugins).returns([]) | |
885 | + plugins.stubs(:map).with(:profile_editor_extras).returns([plugin1_content]) | |
886 | + plugins.stubs(:map).with(:head_ending).returns([]) | |
887 | + plugins.stubs(:map).with(:body_beginning).returns([]) | |
888 | + Noosfero::Plugin::Manager.stubs(:new).returns(plugins) | |
889 | + | |
890 | + get :edit, :profile => profile.identifier | |
891 | + | |
892 | + assert_tag :tag => 'input', :attributes => {:id => 'field_added_by_plugin', :value => 'value_of_field_added_by_plugin'} | |
893 | + end | |
894 | + | |
880 | 895 | end | ... | ... |