diff --git a/plugins/social_share_privacy/lib/social_share_privacy_plugin.rb b/plugins/social_share_privacy/lib/social_share_privacy_plugin.rb index 33a3248..3399c5d 100644 --- a/plugins/social_share_privacy/lib/social_share_privacy_plugin.rb +++ b/plugins/social_share_privacy/lib/social_share_privacy_plugin.rb @@ -16,4 +16,16 @@ class SocialSharePrivacyPlugin < Noosfero::Plugin true end + def social_buttons_contents + proc do + settings = Noosfero::Plugin::Settings.new(environment, SocialSharePrivacyPlugin) + locale = FastGettext.locale + javascript_include_tag('plugins/social_share_privacy/socialshareprivacy/javascripts/socialshareprivacy.js') + + javascript_include_tag(settings.get_setting(:networks).map { |service| "plugins/social_share_privacy/socialshareprivacy/javascripts/modules/#{service}.js" }) + + (locale != 'en' ? javascript_include_tag("plugins/social_share_privacy/socialshareprivacy/javascripts/locale/jquery.socialshareprivacy.min.#{locale}.js") : '') + + 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'});});") + + content_tag(:div, '', :class => "social-buttons") + end + end + end diff --git a/plugins/social_share_privacy/public/style.css b/plugins/social_share_privacy/public/style.css index e137426..8529625 100644 --- a/plugins/social_share_privacy/public/style.css +++ b/plugins/social_share_privacy/public/style.css @@ -4,3 +4,7 @@ #selected-social-networks { width: 50%; } +.social-buttons { + display: inline-block; + width: 100%; +} diff --git a/plugins/social_share_privacy/test/functional/content_viewer_controller_test.rb b/plugins/social_share_privacy/test/functional/content_viewer_controller_test.rb new file mode 100644 index 0000000..bf7b20a --- /dev/null +++ b/plugins/social_share_privacy/test/functional/content_viewer_controller_test.rb @@ -0,0 +1,56 @@ +require File.dirname(__FILE__) + '/../../../../test/test_helper' +require File.dirname(__FILE__) + '/../../../../app/controllers/public/invite_controller' + +# Re-raise errors caught by the controller. +class ContentViewerController; def rescue_action(e) raise e end; end + +class ContentViewerControllerTest < ActionController::TestCase + + def setup + @controller = ContentViewerController.new + @request = ActionController::TestRequest.new + @response = ActionController::TestResponse.new + + @profile = create_user('testinguser').person + @environment = @profile.environment + @environment.enabled_plugins = ['SocialSharePrivacyPlugin'] + @environment.save! + end + + should 'add social content on content view page' do + page = @profile.articles.build(:name => 'test') + page.save! + + get :view_page, :profile => @profile.identifier, :page => ['test'] + + assert_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/socialshareprivacy\.js\??\d*/} + assert_tag :tag => 'div', :attributes => {:class => "social-buttons"} + end + + should 'add social share privacy modules acording to networks settings' do + page = @profile.articles.build(:name => 'test') + page.save! + Noosfero::Plugin::Settings.new(@environment, SocialSharePrivacyPlugin, :networks => ['twitter', 'gplus']).save! + + get :view_page, :profile => @profile.identifier, :page => ['test'] + + assert_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/modules\/twitter\.js\??\d*/} + assert_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/modules\/gplus\.js\??\d*/} + end + + should 'add javascript with string translations if not english' do + page = @profile.articles.build(:name => 'test') + page.save! + FastGettext.stubs(:locale).returns('pt') + + get :view_page, :profile => @profile.identifier, :page => ['test'] + + assert_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/locale\/jquery\.socialshareprivacy\.min\.pt\.js\??\d*/} + + FastGettext.stubs(:locale).returns('en') + + get :view_page, :profile => @profile.identifier, :page => ['test'] + + assert_no_tag :tag => 'script', :attributes => {:src => /\/javascripts\/plugins\/social_share_privacy\/socialshareprivacy\/javascripts\/locale\/jquery\.socialshareprivacy\.min\.en\.js\??\d*/} + end +end diff --git a/plugins/social_share_privacy/test/unit/social_share_privacy_test.rb b/plugins/social_share_privacy/test/unit/social_share_privacy_test.rb index 470ec15..3637658 100644 --- a/plugins/social_share_privacy/test/unit/social_share_privacy_test.rb +++ b/plugins/social_share_privacy/test/unit/social_share_privacy_test.rb @@ -25,4 +25,10 @@ class SocialSharePrivacyPluginTest < ActiveSupport::TestCase assert_equal [], @settings.get_setting(:networks) end + should 'return html code for social share privacy buttons' do + self.stubs(:environment).returns(Environment.default) + content = @plugin.social_buttons_contents + assert self.instance_eval(&content) + end + end -- libgit2 0.21.2