From 6d20972f34b8c8f31f7194276077bffc1d978665 Mon Sep 17 00:00:00 2001 From: Fernando Seror Date: Sun, 9 Aug 2015 09:27:25 -0500 Subject: [PATCH] Share in social networks * Add the social buttons gem to the Gemfile * Initializer and translations for the social buttons * Add the social buttons assets to the sprockets require * Add the social buttons in the show debate view * Spec to lock down the amount of social share buttons to three --- Gemfile | 1 + Gemfile.lock | 4 ++++ app/assets/javascripts/application.js | 1 + app/assets/stylesheets/application.scss | 6 +++++- app/views/debates/show.html.erb | 1 + config/initializers/social_share_button.rb | 3 +++ config/locales/social_share_button.en.yml | 19 +++++++++++++++++++ config/locales/social_share_button.es.yml | 19 +++++++++++++++++++ spec/features/debates_spec.rb | 4 ++++ 9 files changed, 57 insertions(+), 1 deletion(-) create mode 100644 config/initializers/social_share_button.rb create mode 100644 config/locales/social_share_button.en.yml create mode 100644 config/locales/social_share_button.es.yml diff --git a/Gemfile b/Gemfile index 5ca7a1a6b..f3e292881 100644 --- a/Gemfile +++ b/Gemfile @@ -29,6 +29,7 @@ gem 'acts_as_votable' gem "recaptcha", require: "recaptcha/rails" gem 'ckeditor' gem 'cancancan' +gem 'social-share-button' group :development, :test do # Call 'byebug' anywhere in the code to stop execution and get a debugger console diff --git a/Gemfile.lock b/Gemfile.lock index fd9842f39..f3c45c93d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -241,6 +241,9 @@ GEM json (~> 1.8) simplecov-html (~> 0.10.0) simplecov-html (0.10.0) + social-share-button (0.1.8) + coffee-rails + sass-rails spring (1.3.6) sprockets (3.2.0) rack (~> 1.0) @@ -318,6 +321,7 @@ DEPENDENCIES responders rspec-rails (~> 3.0) sass-rails (~> 5.0) + social-share-button spring turbolinks uglifier (>= 1.3.0) diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 08153c4ec..def844e5a 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -15,6 +15,7 @@ //= require foundation //= require turbolinks //= require ckeditor/init +//= require social-share-button //= require app //= require_tree . diff --git a/app/assets/stylesheets/application.scss b/app/assets/stylesheets/application.scss index 1bcdc722a..e4379397e 100644 --- a/app/assets/stylesheets/application.scss +++ b/app/assets/stylesheets/application.scss @@ -1,6 +1,10 @@ +/* + *= require social-share-button + */ + @import "foundation_and_overrides"; @import "fonts"; @import "icons"; @import "variables"; @import "participacion"; -@import "debates"; \ No newline at end of file +@import "debates"; diff --git a/app/views/debates/show.html.erb b/app/views/debates/show.html.erb index 51537d5a5..36622951a 100644 --- a/app/views/debates/show.html.erb +++ b/app/views/debates/show.html.erb @@ -9,6 +9,7 @@

<%= @debate.title %>

<%= @debate.description %>

<%= render 'shared/tags', debate: @debate %>

+

<%= social_share_button_tag(@debate.title) %>

diff --git a/config/initializers/social_share_button.rb b/config/initializers/social_share_button.rb new file mode 100644 index 000000000..d8b6e5254 --- /dev/null +++ b/config/initializers/social_share_button.rb @@ -0,0 +1,3 @@ +SocialShareButton.configure do |config| + config.allow_sites = %w(twitter facebook google_plus) +end diff --git a/config/locales/social_share_button.en.yml b/config/locales/social_share_button.en.yml new file mode 100644 index 000000000..95dba5da9 --- /dev/null +++ b/config/locales/social_share_button.en.yml @@ -0,0 +1,19 @@ +en: + social_share_button: + share_to: Share to %{name} + weibo: Sina Weibo + twitter: Twitter + facebook: Facebook + douban: Douban + qq: Qzone + tqq: Tqq + delicious: Delicious + baidu: Baidu.com + kaixin001: Kaixin001.com + renren: Renren.com + google_plus: Google+ + google_bookmark: Google Bookmark + tumblr: Tumblr + plurk: Plurk + pinterest: Pinterest + email: Email diff --git a/config/locales/social_share_button.es.yml b/config/locales/social_share_button.es.yml new file mode 100644 index 000000000..e0520c19b --- /dev/null +++ b/config/locales/social_share_button.es.yml @@ -0,0 +1,19 @@ +es: + social_share_button: + share_to: Compartir en %{name} + weibo: Sina Weibo + twitter: Twitter + facebook: Facebook + douban: Douban + qq: Qzone + tqq: Tqq + delicious: Delicious + baidu: Baidu.com + kaixin001: Kaixin001.com + renren: Renren.com + google_plus: Google+ + google_bookmark: Google Bookmark + tumblr: Tumblr + plurk: Plurk + pinterest: Pinterest + email: Correo electrónico diff --git a/spec/features/debates_spec.rb b/spec/features/debates_spec.rb index 894b09b19..113e06656 100644 --- a/spec/features/debates_spec.rb +++ b/spec/features/debates_spec.rb @@ -34,6 +34,10 @@ feature 'Debates' do expect(page).to have_content "Debate description" expect(page).to have_content debate.author.name expect(page).to have_content I18n.l(Date.today) + + within('.social-share-button') do + expect(page.all('a').count).to be(3) # Twitter, Facebook, Google+ + end end scenario 'Create' do