Commit 5de354cb6feb60f9ad732ecdcde0b5a1df8f16dc

Authored by Larissa Reis
1 parent 1e02838e

social-share: adds social buttons to content view page

(ActionItem3238)
plugins/social_share_privacy/lib/social_share_privacy_plugin.rb
... ... @@ -16,4 +16,16 @@ class SocialSharePrivacyPlugin < Noosfero::Plugin
16 16 true
17 17 end
18 18  
  19 + def social_buttons_contents
  20 + proc do
  21 + settings = Noosfero::Plugin::Settings.new(environment, SocialSharePrivacyPlugin)
  22 + locale = FastGettext.locale
  23 + javascript_include_tag('plugins/social_share_privacy/socialshareprivacy/javascripts/socialshareprivacy.js') +
  24 + javascript_include_tag(settings.get_setting(:networks).map { |service| "plugins/social_share_privacy/socialshareprivacy/javascripts/modules/#{service}.js" }) +
  25 + (locale != 'en' ? javascript_include_tag("plugins/social_share_privacy/socialshareprivacy/javascripts/locale/jquery.socialshareprivacy.min.#{locale}.js") : '') +
  26 + javascript_tag("jQuery.fn.socialSharePrivacy.settings.path_prefix = '../../plugins/social_share_privacy/socialshareprivacy/'; jQuery.fn.socialSharePrivacy.settings.order = #{settings.get_setting(:networks)}; jQuery(document).ready(function () { jQuery('.social-buttons').socialSharePrivacy({perma_option: false, info_link_target: '_blank'});});") +
  27 + content_tag(:div, '', :class => "social-buttons")
  28 + end
  29 + end
  30 +
19 31 end
... ...
plugins/social_share_privacy/public/style.css
... ... @@ -4,3 +4,7 @@
4 4 #selected-social-networks {
5 5 width: 50%;
6 6 }
  7 +.social-buttons {
  8 + display: inline-block;
  9 + width: 100%;
  10 +}
... ...
plugins/social_share_privacy/test/functional/content_viewer_controller_test.rb 0 → 100644
... ... @@ -0,0 +1,56 @@
  1 +require File.dirname(__FILE__) + '/../../../../test/test_helper'
  2 +require File.dirname(__FILE__) + '/../../../../app/controllers/public/invite_controller'
  3 +
  4 +# Re-raise errors caught by the controller.
  5 +class ContentViewerController; def rescue_action(e) raise e end; end
  6 +
  7 +class ContentViewerControllerTest < ActionController::TestCase
  8 +
  9 + def setup
  10 + @controller = ContentViewerController.new
  11 + @request = ActionController::TestRequest.new
  12 + @response = ActionController::TestResponse.new
  13 +
  14 + @profile = create_user('testinguser').person
  15 + @environment = @profile.environment
  16 + @environment.enabled_plugins = ['SocialSharePrivacyPlugin']
  17 + @environment.save!
  18 + end
  19 +
  20 + should 'add social content on content view page' do
  21 + page = @profile.articles.build(:name => 'test')
  22 + page.save!
  23 +
  24 + get :view_page, :profile => @profile.identifier, :page => ['test']
  25 +
  26 + assert_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/socialshareprivacy\.js\??\d*/}
  27 + assert_tag :tag => 'div', :attributes => {:class => "social-buttons"}
  28 + end
  29 +
  30 + should 'add social share privacy modules acording to networks settings' do
  31 + page = @profile.articles.build(:name => 'test')
  32 + page.save!
  33 + Noosfero::Plugin::Settings.new(@environment, SocialSharePrivacyPlugin, :networks => ['twitter', 'gplus']).save!
  34 +
  35 + get :view_page, :profile => @profile.identifier, :page => ['test']
  36 +
  37 + assert_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/modules\/twitter\.js\??\d*/}
  38 + assert_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/modules\/gplus\.js\??\d*/}
  39 + end
  40 +
  41 + should 'add javascript with string translations if not english' do
  42 + page = @profile.articles.build(:name => 'test')
  43 + page.save!
  44 + FastGettext.stubs(:locale).returns('pt')
  45 +
  46 + get :view_page, :profile => @profile.identifier, :page => ['test']
  47 +
  48 + assert_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/locale\/jquery\.socialshareprivacy\.min\.pt\.js\??\d*/}
  49 +
  50 + FastGettext.stubs(:locale).returns('en')
  51 +
  52 + get :view_page, :profile => @profile.identifier, :page => ['test']
  53 +
  54 + assert_no_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/locale\/jquery\.socialshareprivacy\.min\.en\.js\??\d*/}
  55 + end
  56 +end
... ...
plugins/social_share_privacy/test/unit/social_share_privacy_test.rb
... ... @@ -25,4 +25,10 @@ class SocialSharePrivacyPluginTest &lt; ActiveSupport::TestCase
25 25 assert_equal [], @settings.get_setting(:networks)
26 26 end
27 27  
  28 + should 'return html code for social share privacy buttons' do
  29 + self.stubs(:environment).returns(Environment.default)
  30 + content = @plugin.social_buttons_contents
  31 + assert self.instance_eval(&content)
  32 + end
  33 +
28 34 end
... ...