social-share-button 0.0.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. data/.DS_Store +0 -0
  2. data/.gitignore +4 -0
  3. data/Gemfile +6 -0
  4. data/README.markdown +50 -0
  5. data/Rakefile +27 -0
  6. data/lib/assets/images/.DS_Store +0 -0
  7. data/lib/assets/images/sprites/social-share-button.png +0 -0
  8. data/lib/assets/images/sprites/social-share-button/.DS_Store +0 -0
  9. data/lib/assets/images/sprites/social-share-button/douban.png +0 -0
  10. data/lib/assets/images/sprites/social-share-button/facebook.png +0 -0
  11. data/lib/assets/images/sprites/social-share-button/twitter.png +0 -0
  12. data/lib/assets/images/sprites/social-share-button/weibo.png +0 -0
  13. data/lib/assets/javascripts/social-share-button.coffee +18 -0
  14. data/lib/assets/stylesheets/social-share-button.scss +22 -0
  15. data/lib/generators/social_share_button/install_generator.rb +12 -0
  16. data/lib/generators/social_share_button/templates/.DS_Store +0 -0
  17. data/lib/generators/social_share_button/templates/config/initializers/social_share_button.rb +3 -0
  18. data/lib/generators/social_share_button/templates/config/locales/social_share_button.en.yml +8 -0
  19. data/lib/generators/social_share_button/templates/config/locales/social_share_button.zh-CN.yml +8 -0
  20. data/lib/generators/social_share_button/templates/config/locales/social_share_button.zh-TW.yml +7 -0
  21. data/lib/social-share-button.rb +17 -0
  22. data/lib/social_share_button/config.rb +22 -0
  23. data/lib/social_share_button/engine.rb +7 -0
  24. data/lib/social_share_button/helper.rb +21 -0
  25. data/lib/social_share_button/railtie.rb +7 -0
  26. data/lib/social_share_button/version.rb +3 -0
  27. data/social-share-button.gemspec +23 -0
  28. metadata +86 -0
data/.DS_Store ADDED
Binary file
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in social-share.gemspec
4
+ gemspec
5
+
6
+ gem "sprite-factory", "1.4.1"
data/README.markdown ADDED
@@ -0,0 +1,50 @@
1
+ # Social Share Button
2
+
3
+ This is a gem to helper you quick create a share feature in you Rails apps.
4
+
5
+ ## Screenshot
6
+
7
+ ![img](http://l.ruby-china.org/photo/00cc56853b29b5d90458d39e855a936d.png)
8
+
9
+ ## Install
10
+
11
+ in your `Gemfile`:
12
+
13
+ gem 'social_share_button'
14
+
15
+ an install it:
16
+
17
+ $ bundle install
18
+ $ rails generate social_share_button:install
19
+
20
+ ## Configure
21
+
22
+ you can create this content in `config/initializes/social_share_button.rb`:
23
+
24
+ SocialShareButton.configure do |config|
25
+ config.allow_sites = %w(twitter facebook weibo douban)
26
+ end
27
+
28
+ ## Usage
29
+
30
+ you need add require css,js file in your app assets files:
31
+
32
+ `app/assets/javascripts/application.js`
33
+
34
+ //= require social-share-button
35
+
36
+ `app/assets/stylesheets/application.css`
37
+
38
+ *= require social-share-button
39
+
40
+ then you can use `social_share_button_tag` helper in views, for example `app/views/posts/show.html.erb`
41
+
42
+ <%= social_share_button_tag(@post.title) %>
43
+
44
+ and you can custom rel attribute:
45
+
46
+ <%= social_share_button_tag(@post.title, :rel => "twipsy") %>
47
+
48
+ ## Demo
49
+
50
+ [http://ruby-china.org/wiki/about](http://ruby-china.org/wiki/about)
data/Rakefile ADDED
@@ -0,0 +1,27 @@
1
+ require "bundler/gem_tasks"
2
+
3
+ require 'sprite_factory'
4
+
5
+ ROOT_PATH = File.dirname(__FILE__)
6
+
7
+ namespace :assets do
8
+ desc 'recreate sprite images and css'
9
+ task :resprite do
10
+ SpriteFactory.library = :chunkypng
11
+ SpriteFactory.csspath = "image-path('sprites/$IMAGE')"
12
+ dirs = Dir.glob("#{ROOT_PATH}/lib/assets/images/sprites/*/")
13
+ dirs.each do |path|
14
+ dir_name = path.split("/").last
15
+ SpriteFactory.run!("lib/assets/images/sprites/#{dir_name}",
16
+ :layout => :packed,
17
+ :output_style => "lib/assets/stylesheets/#{dir_name}.scss",
18
+ :selector => ".#{dir_name}-") do |images|
19
+ result = []
20
+ images.each do |img|
21
+ result << ".social-share-button-#{img[0]} { display:inline-block; #{img[1][:style]} }"
22
+ end
23
+ result.join("\n")
24
+ end
25
+ end
26
+ end
27
+ end
Binary file
@@ -0,0 +1,18 @@
1
+ window.SocialShareButton =
2
+ openUrl : (url) ->
3
+ window.open(url)
4
+ false
5
+
6
+ share : (site, title) ->
7
+ url = encodeURIComponent(location.href)
8
+ title = encodeURIComponent(title)
9
+ switch site
10
+ when "weibo"
11
+ SocialShareButton.openUrl("http://v.t.sina.com.cn/share/share.php?url=#{url}&title=#{title}&content=utf-8")
12
+ when "twitter"
13
+ SocialShareButton.openUrl("https://twitter.com/home?status=#{title}: #{url}")
14
+ when "douban"
15
+ SocialShareButton.openUrl("http://www.douban.com/recommend/?url=#{url}&title=#{title}&v=1&r=1")
16
+ when "facebook"
17
+ SocialShareButton.openUrl("http://www.facebook.com/sharer.php?t=#{title}&u=#{url}")
18
+ false
@@ -0,0 +1,22 @@
1
+ /*
2
+
3
+ Creating a sprite from following images:
4
+
5
+ lib/assets/images/sprites/social-share-button/douban.png (16x16)
6
+ lib/assets/images/sprites/social-share-button/facebook.png (16x16)
7
+ lib/assets/images/sprites/social-share-button/twitter.png (16x16)
8
+ lib/assets/images/sprites/social-share-button/weibo.png (16x16)
9
+
10
+ Output files:
11
+ lib/assets/images/sprites/social-share-button.png
12
+ lib/assets/stylesheets/social-share-button.scss
13
+
14
+ Output size:
15
+ 32x32
16
+
17
+
18
+ */
19
+ .social-share-button-douban { display:inline-block; width: 16px; height: 16px; background: url(image-path('sprites/social-share-button.png')) 0px 0px no-repeat }
20
+ .social-share-button-facebook { display:inline-block; width: 16px; height: 16px; background: url(image-path('sprites/social-share-button.png')) -16px 0px no-repeat }
21
+ .social-share-button-twitter { display:inline-block; width: 16px; height: 16px; background: url(image-path('sprites/social-share-button.png')) 0px -16px no-repeat }
22
+ .social-share-button-weibo { display:inline-block; width: 16px; height: 16px; background: url(image-path('sprites/social-share-button.png')) -16px -16px no-repeat }
@@ -0,0 +1,12 @@
1
+ module SocialShareButton
2
+ module Generators
3
+ class InstallGenerator < ::Rails::Generators::Base
4
+ desc "Copy SocialShareButton default files"
5
+ source_root File.expand_path('../templates', __FILE__)
6
+
7
+ def copy_config
8
+ directory 'config'
9
+ end
10
+ end
11
+ end
12
+ end
@@ -0,0 +1,3 @@
1
+ SocialShareButton.configure do |config|
2
+ config.allow_sites = %w(twitter facebook weibo douban)
3
+ end
@@ -0,0 +1,8 @@
1
+ en:
2
+ social_share_button:
3
+ share_to: Share to
4
+ weibo: Sina Weibo
5
+ twitter: Twitter
6
+ facebook: Facebook
7
+ douban: Douban
8
+
@@ -0,0 +1,8 @@
1
+ 'zh-CN':
2
+ social_share_button:
3
+ share_to: 分享到
4
+ weibo: 新浪微博
5
+ twitter: Twitter
6
+ facebook: Facebook
7
+ douban: 豆瓣
8
+
@@ -0,0 +1,7 @@
1
+ 'zh-TW':
2
+ social_share_button:
3
+ share_to: 分享到
4
+ weibo: 新浪微博
5
+ twitter: Twitter
6
+ facebook: Facebook
7
+ douban: 豆瓣
@@ -0,0 +1,17 @@
1
+ require "social_share_button/version"
2
+ require "social_share_button/config"
3
+ require "social_share_button/helper"
4
+
5
+ I18n.load_path += Dir.glob( File.dirname(__FILE__) + "lib/locales/*.{rb,yml}" )
6
+
7
+ module SocialShareButton
8
+ module Rails
9
+ if ::Rails.version < "3.1"
10
+ require "social_share_button/railtie"
11
+ else
12
+ require "social_share_button/engine"
13
+ end
14
+ end
15
+ end
16
+
17
+ ActionView::Base.send :include, SocialShareButton::Helper
@@ -0,0 +1,22 @@
1
+ module SocialShareButton
2
+ class << self
3
+ attr_accessor :config
4
+ def configure
5
+ yield self.config ||= Config.new
6
+ end
7
+ end
8
+
9
+ class Config
10
+ # enable social sites to share,
11
+ # * default : twitter facebook weibo douban
12
+ # * site support: twitter facebook weibo douban
13
+ attr_accessor :allow_sites
14
+
15
+ def initialize
16
+ end
17
+ end
18
+ end
19
+
20
+ SocialShareButton.configure do |conf|
21
+ conf.allow_sites = %w(twitter facebook weibo douban)
22
+ end
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+ module SocialShareButton
3
+ module Rails
4
+ class Engine < ::Rails::Engine
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,21 @@
1
+ # coding: utf-8
2
+ module SocialShareButton
3
+ module Helper
4
+ def social_share_button_tag(title = "", opts = {})
5
+ rel = opts[:rel]
6
+ html = []
7
+ html << "<div class='social-share-button' data-title='#{title}'>"
8
+
9
+ SocialShareButton.config.allow_sites.each do |name|
10
+ link_title = [t("social_share_button.share_to"),t("social_share_button.#{name.downcase}")].join("")
11
+ html << link_to("","#", :rel => "nofollow #{rel}",
12
+ "data-site" => name,
13
+ :class => "social-share-button-#{name}",
14
+ :onclick => "return SocialShareButton.share($(this).data('site'), $(this).parent().data('title'));",
15
+ :title => h(link_title))
16
+ end
17
+ html << "</div>"
18
+ raw html.join("\n")
19
+ end
20
+ end
21
+ end
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+ module SocialShareButton
3
+ module Rails
4
+ class Railtie < ::Rails::Railtie
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ module SocialShareButton
2
+ VERSION = "0.0.2"
3
+ end
@@ -0,0 +1,23 @@
1
+ # -*- encoding: utf-8 -*-
2
+ $:.push File.expand_path("../lib", __FILE__)
3
+ require "social_share_button/version"
4
+
5
+ Gem::Specification.new do |s|
6
+ s.name = "social-share-button"
7
+ s.version = SocialShareButton::VERSION
8
+ s.authors = ["Jason Lee"]
9
+ s.email = ["huacnlee@gmail.com"]
10
+ s.homepage = "http://github.com/huacnlee/social-share-button"
11
+ s.summary = %q{Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban, QQ ...}
12
+ s.description = %q{Helper for add social share feature in your Rails app. Twitter, Facebook, Weibo, Douban, QQ ...}
13
+
14
+ s.files = `git ls-files`.split("\n")
15
+ s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
16
+ s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
17
+ s.require_paths = ["lib"]
18
+
19
+ # specify any dependencies here; for example:
20
+ s.files = `git ls-files`.split("\n")
21
+ s.add_development_dependency "rails"
22
+ # s.add_runtime_dependency "rest-client"
23
+ end
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: social-share-button
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.2
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Jason Lee
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2012-01-04 00:00:00.000000000Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: &70198843114980 !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: '0'
22
+ type: :development
23
+ prerelease: false
24
+ version_requirements: *70198843114980
25
+ description: Helper for add social share feature in your Rails app. Twitter, Facebook,
26
+ Weibo, Douban, QQ ...
27
+ email:
28
+ - huacnlee@gmail.com
29
+ executables: []
30
+ extensions: []
31
+ extra_rdoc_files: []
32
+ files:
33
+ - .DS_Store
34
+ - .gitignore
35
+ - Gemfile
36
+ - README.markdown
37
+ - Rakefile
38
+ - lib/assets/images/.DS_Store
39
+ - lib/assets/images/sprites/social-share-button.png
40
+ - lib/assets/images/sprites/social-share-button/.DS_Store
41
+ - lib/assets/images/sprites/social-share-button/douban.png
42
+ - lib/assets/images/sprites/social-share-button/facebook.png
43
+ - lib/assets/images/sprites/social-share-button/twitter.png
44
+ - lib/assets/images/sprites/social-share-button/weibo.png
45
+ - lib/assets/javascripts/social-share-button.coffee
46
+ - lib/assets/stylesheets/social-share-button.scss
47
+ - lib/generators/social_share_button/install_generator.rb
48
+ - lib/generators/social_share_button/templates/.DS_Store
49
+ - lib/generators/social_share_button/templates/config/initializers/social_share_button.rb
50
+ - lib/generators/social_share_button/templates/config/locales/social_share_button.en.yml
51
+ - lib/generators/social_share_button/templates/config/locales/social_share_button.zh-CN.yml
52
+ - lib/generators/social_share_button/templates/config/locales/social_share_button.zh-TW.yml
53
+ - lib/social-share-button.rb
54
+ - lib/social_share_button/config.rb
55
+ - lib/social_share_button/engine.rb
56
+ - lib/social_share_button/helper.rb
57
+ - lib/social_share_button/railtie.rb
58
+ - lib/social_share_button/version.rb
59
+ - social-share-button.gemspec
60
+ homepage: http://github.com/huacnlee/social-share-button
61
+ licenses: []
62
+ metadata: {}
63
+ post_install_message:
64
+ rdoc_options: []
65
+ require_paths:
66
+ - lib
67
+ required_ruby_version: !ruby/object:Gem::Requirement
68
+ none: false
69
+ requirements:
70
+ - - ! '>='
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ none: false
75
+ requirements:
76
+ - - ! '>='
77
+ - !ruby/object:Gem::Version
78
+ version: '0'
79
+ requirements: []
80
+ rubyforge_project:
81
+ rubygems_version: 1.8.10
82
+ signing_key:
83
+ specification_version: 4
84
+ summary: Helper for add social share feature in your Rails app. Twitter, Facebook,
85
+ Weibo, Douban, QQ ...
86
+ test_files: []