All Projects → huacnlee → Social Share Button

huacnlee / Social Share Button

Licence: mit
Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban ...

Programming Languages

coffeescript
4710 projects

Projects that are alternatives of or similar to Social Share Button

Diaspora
A privacy-aware, distributed, open source social network.
Stars: ✭ 12,937 (+2181.66%)
Mutual labels:  rails, social-network
Stories
Medium clone built with Ruby on Rails
Stars: ✭ 688 (+21.34%)
Mutual labels:  rails, social-network
Socify
🚀 Socify is an open source social networking platform written in Ruby on Rails
Stars: ✭ 363 (-35.98%)
Mutual labels:  rails, social-network
Livingstyleguide
Easily create front-end style guides with Markdown and Sass/SCSS.
Stars: ✭ 874 (+54.14%)
Mutual labels:  rails, front-end
Has friendship
Add friendship to ActiveRecord models
Stars: ✭ 187 (-67.02%)
Mutual labels:  rails, social-network
Brevidy
A video social network built with Ruby on Rails, HAML, Bootstrap, and jQuery.
Stars: ✭ 220 (-61.2%)
Mutual labels:  rails, social-network
Annict
The platform for anime addicts built with Rails and Stimulus.js.
Stars: ✭ 542 (-4.41%)
Mutual labels:  rails, social-network
Condenser
The greatest application front-end to the Steem Blockchain.
Stars: ✭ 516 (-8.99%)
Mutual labels:  social-network
Awesome Twitter Data
A list of Twitter datasets and related resources.
Stars: ✭ 533 (-6%)
Mutual labels:  social-network
Intercooler Js
Making AJAX as easy as anchor tags
Stars: ✭ 4,662 (+722.22%)
Mutual labels:  front-end
Zero downtime migrations
Zero downtime migrations with ActiveRecord 3+ and PostgreSQL
Stars: ✭ 513 (-9.52%)
Mutual labels:  rails
Terraforming Rails
Terraforming legacy Rails applications guides and tools
Stars: ✭ 517 (-8.82%)
Mutual labels:  rails
Serviceworker Rails
Use Service Worker with the Rails asset pipeline
Stars: ✭ 535 (-5.64%)
Mutual labels:  rails
Letter opener web
A web interface for browsing Ruby on Rails sent emails
Stars: ✭ 513 (-9.52%)
Mutual labels:  rails
Devise
Flexible authentication solution for Rails with Warden.
Stars: ✭ 22,088 (+3795.59%)
Mutual labels:  rails
Graphql Ruby
Ruby implementation of GraphQL
Stars: ✭ 4,931 (+769.66%)
Mutual labels:  rails
Blog
😛 个人博客 🤐 订阅是 watch 是 watch 是 watch 是 watch
Stars: ✭ 555 (-2.12%)
Mutual labels:  front-end
Cancancan
The authorization Gem for Ruby on Rails.
Stars: ✭ 5,046 (+789.95%)
Mutual labels:  rails
Activerecord Multi Tenant
Rails/ActiveRecord support for distributed multi-tenant databases like Postgres+Citus
Stars: ✭ 526 (-7.23%)
Mutual labels:  rails
Rails email preview
Preview and edit app mailer templates in Rails.
Stars: ✭ 524 (-7.58%)
Mutual labels:  rails

Social Share Button

This is a gem to helper you quick create a share feature in you Rails apps.

Gem Version

Sites list

  • Facebook
  • Twitter
  • Douban
  • Weibo
  • QZone
  • Google Bookmark
  • Delicious
  • Tumblr
  • Pinterest
  • Email
  • LinkedIn
  • WeChat (Weixin)
  • Vkontakte
  • Odnoklassniki
  • Xing
  • Reddit
  • Hacker News
  • Telegram
  • WhatsApp

Screenshot

2016-10-05 8 51 07

Install

In your Gemfile:

gem 'social-share-button'

Old version for IE and lower browser support:

gem 'social-share-button', '0.2.1'

And install it:

$ bundle install
$ rails generate social_share_button:install

Configure

You can config config/initializers/social_share_button.rb to choose which site do you want to use:

SocialShareButton.configure do |config|
  config.allow_sites = %w(twitter facebook weibo)
end

More site names you can visit https://github.com/huacnlee/social-share-button/blob/master/lib/social_share_button/config.rb#L33 to found it.

Usage

You need add require css,js file in your app assets files:

app/assets/javascripts/application.coffee

#= require social-share-button
#= require social-share-button/wechat # if you need use WeChat

app/assets/stylesheets/application.scss

*= require social-share-button

In Rails 4.1.6 , use @import to require files:

app/assets/stylesheets/application.css.scss

@import "social-share-button";

Then you can use social_share_button_tag helper in views, for example app/views/posts/show.html.erb

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

Apart from the default title, you can specify the title for the special social network:

<%= social_share_button_tag(@post.title, 'data-twitter-title' => 'TheTitleForTwitter') %>

To specify sites at runtime:

<%= social_share_button_tag(@post.title, :allow_sites => %w(twitter facebook)) %>

And you can custom rel attribute:

<%= social_share_button_tag(@post.title, :rel => "twipsy") %>

You can also specify the URL that it links to:

<%= social_share_button_tag(@post.title, :url => "http://myapp.com/foo/bar") %>
<%= social_share_button_tag(@post.title, :url => "http://myapp.com/foo/bar", :image => "http://foo.bar/images/a.jpg", desc: "The summary of page", via: "MyTwitterName") %>

For the Tumblr there are an extra settings, prefixed with : data-*

<%= social_share_button_tag(@post.title, :image => "https://raw.github.com/vkulpa/social-share-button/master/lib/assets/images/sprites/social-share-button/tumblr.png", :'data-type' => 'photo') %>
<%= social_share_button_tag(@post.title, :'data-source' => "https://raw.github.com/vkulpa/social-share-button/master/lib/assets/images/sprites/social-share-button/tumblr.png", :'data-type' => 'photo') %>

Those two above calls are identical. Here are the mapping of attributes depending on you data-type parameter

data-type standard custom :"data-*" prefixed
link (default) title data-title
url data-url
text title data-title
photo title data-caption
image data-source
quote title data-quote
data-source

Facebook

A couple of gotchas for Facebook only:

Facebook needs the description added

  <%= social_share_button_tag('Share to Facebook', :url => course_path(@course), desc: @course.name) %>

This will add the required data-desc element, and Facebook will then accept the request.

Testing from localhost will not work

You will need to test from a live site or Facebook will reject it; localhost will not work.

How to change icon size?

Yes, you can override social-share-button base css to change the icon size.

In you app/assets/stylesheets/application.scss:

$size: 24px;

.social-share-button {
  .ssb-icon {
    background-size: $size $size;
    height: $size;
    width: $size;
  }
}

Demo

https://ruby-china.org/wiki/about

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].