go_social 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in go_social.gemspec
4
+ gemspec
data/LICENSE.txt ADDED
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2013 TODO: Write your name
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,29 @@
1
+ # GoSocial
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ gem 'go_social'
10
+
11
+ And then execute:
12
+
13
+ $ bundle
14
+
15
+ Or install it yourself as:
16
+
17
+ $ gem install go_social
18
+
19
+ ## Usage
20
+
21
+ TODO: Write usage instructions here
22
+
23
+ ## Contributing
24
+
25
+ 1. Fork it
26
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
27
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
28
+ 4. Push to the branch (`git push origin my-new-feature`)
29
+ 5. Create new Pull Request
data/Rakefile ADDED
@@ -0,0 +1 @@
1
+ require "bundler/gem_tasks"
data/go_social.gemspec ADDED
@@ -0,0 +1,22 @@
1
+ # -*- encoding: utf-8 -*-
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'go_social/version'
5
+
6
+ Gem::Specification.new do |gem|
7
+ gem.name = "go_social"
8
+ gem.version = GoSocial::VERSION
9
+ gem.authors = ["Rakesh Jha"]
10
+ gem.email = ["mrrakesh2112@gmail.com"]
11
+ gem.description = %q{This gem helps to add various social widgets that are commonly used by rails applications. Supports Facebook, Pinterest, Twitter, Flickr, LinkedIn and Google+.}
12
+ gem.summary = %q{A complete social media makeover.}
13
+ gem.homepage = "https://github.com/Jrakesh/go_social"
14
+
15
+ gem.files = `git ls-files`.split($/)
16
+ gem.executables = gem.files.grep(%r{^bin/}).map{ |f| File.basename(f) }
17
+ gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
18
+ gem.require_paths = ["lib"]
19
+
20
+ #add gem dependencies
21
+ gem.add_development_dependency "rails"
22
+ end
@@ -0,0 +1,43 @@
1
+ module GoSocial
2
+ module Assistant
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ attr_reader :scriptized
7
+ attr_writer :default_options
8
+ alias_method :scriptized?, :scriptized
9
+
10
+ def my_name
11
+ self.name.demodulize
12
+ end
13
+
14
+ def help
15
+ "Please HELP by filling in the help of the #{myname} button :) (see google+ button code)"
16
+ end
17
+
18
+ def options_to_data(opts)
19
+ params = {}
20
+ opts.each {|k, v| params["data-#{k}"] = v}
21
+ params
22
+ end
23
+
24
+ def options_to_query(subject, opts)
25
+ # formulate the url, and then strip the part before first '?'
26
+ query_params = opts.slice(:url, :media, :description)
27
+ full_url = subject.url_for(query_params)
28
+ full_url.sub(/^([^?]*)/, '')
29
+ end
30
+
31
+ protected
32
+
33
+ def help_note
34
+ "Note: GoSocial will make sure that the widget scripts are rendered once only!"
35
+ end
36
+
37
+ # returns blank
38
+ def blank_content
39
+ "".html_safe
40
+ end
41
+ end
42
+ end
43
+ end
@@ -0,0 +1,42 @@
1
+ module GoSocial
2
+ module Assistant
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ attr_reader :scriptized
7
+ attr_writer :default_options
8
+ alias_method :scriptized?, :scriptized
9
+
10
+ def my_name
11
+ self.name.demodulize
12
+ end
13
+
14
+ def help
15
+ "Please HELP by filling in the help of the #{myname} button :) (see google+ button code)"
16
+ end
17
+
18
+ def options_to_data(opts)
19
+ params = {}
20
+ opts.each {|k, v| params["data-#{k}"] = v}
21
+ params
22
+ end
23
+
24
+ def options_to_query(subject, opts)
25
+ # formulate the url, and then strip the part before first '?'
26
+ query_params = opts.slice(:url, :media, :description)
27
+ full_url = subject.url_for(query_params)
28
+ full_url.sub(/^([^?]*)/, '')
29
+ end
30
+
31
+ protected
32
+
33
+ def help_note
34
+ "Note: GoSocial will make sure that the widget scripts are rendered once only!"
35
+ end
36
+
37
+ def blank_content
38
+ "".html_safe
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,9 @@
1
+ module GoSocial
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ initializer 'go social config' do
5
+ ActionView::Base.send :include, GoSocial::ViewHelper
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,9 @@
1
+ module GoSocial
2
+ module Rails
3
+ class Engine < ::Rails::Engine
4
+ initializer 'go social config' do
5
+ ActionView::Base.send :include, GoSocial::ViewHelper
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,95 @@
1
+ module GoSocial
2
+ module Facebook
3
+ include GoSocial::Assistant
4
+
5
+ LIKE_BUTTON_CLASS = "fb-like"
6
+ LIKE_BOX_CLASS = "fb-like-box"
7
+ COMMENT_CLASS = "fb-comments"
8
+
9
+ # Facebook Like Button
10
+ def like_button(options = {})
11
+ clazz = GoSocial::Facebook
12
+ params = clazz.options_to_data(clazz.default_options_like_button.merge(options))
13
+ params.merge!(class: LIKE_BUTTON_CLASS)
14
+
15
+ html = "".html_safe
16
+ html << content_tag(:div, nil, id: "fb-root")
17
+ html << clazz.script
18
+ html << content_tag(:div, nil, params)
19
+ html
20
+ end
21
+
22
+ # Facebook Like Box
23
+ def like_box(options = {})
24
+ clazz = GoSocial::Facebook
25
+ params = clazz.options_to_data(clazz.default_options_like_box.merge(options))
26
+ params.merge!(class: LIKE_BOX_CLASS)
27
+
28
+ html = "".html_safe
29
+ html << content_tag(:div, nil, id: "fb-root")
30
+ html << clazz.script
31
+ html << content_tag(:div, nil, params)
32
+ html
33
+ end
34
+
35
+ # Facebook Comment Box
36
+ def comment_box(options = {})
37
+ clazz = GoSocial::Facebook
38
+ params = clazz.options_to_data(clazz.default_options_comment_box.merge(options))
39
+ params.merge!(class: COMMENT_CLASS)
40
+
41
+ html = "".html_safe
42
+ html << content_tag(:div, nil, id: "fb-root")
43
+ html << clazz.script
44
+ html << content_tag(:div, nil, params)
45
+ html
46
+ end
47
+
48
+
49
+ class << self
50
+ def default_options_like_button
51
+ @default_options ||= {
52
+ send: "false",
53
+ layout: "box_count",
54
+ width: "250",
55
+ action: "like",
56
+ font: "arial",
57
+ colorscheme: "light"
58
+ }.merge("show-faces" => "false")
59
+ end
60
+
61
+
62
+ def default_options_like_box
63
+ @default_options ||= {
64
+ send: "false",
65
+ stream: "true",
66
+ width: "250",
67
+ height: "150",
68
+ header: "true",
69
+ colorscheme: "light"
70
+ }.merge("show-faces" => "true", "show-border" => "true")
71
+ end
72
+
73
+
74
+ def default_options_comment_box
75
+ @default_options ||= {
76
+ width: "250",
77
+ colorscheme: "light"
78
+ }.merge("num-posts" => "2")
79
+ end
80
+
81
+ def script
82
+ '<script>
83
+ (function(d, s, id) {
84
+ var js, fjs = d.getElementsByTagName(s)[0];
85
+ if (d.getElementById(id)) return;
86
+ js = d.createElement(s); js.id = id;
87
+ js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
88
+ fjs.parentNode.insertBefore(js, fjs);
89
+ }(document, "script", "facebook-jssdk"));
90
+ </script>'.html_safe
91
+ end
92
+
93
+ end
94
+ end
95
+ end
@@ -0,0 +1,98 @@
1
+ module GoSocial
2
+ module Facebook
3
+ include GoSocial::Assistant
4
+
5
+ LIKE_BUTTON_CLASS = "fb-like"
6
+ LIKE_BOX_CLASS = "fb-like-box"
7
+ COMMENT_CLASS = "fb-comments"
8
+
9
+ # Facebook Like Button
10
+ def like_button(options = {})
11
+ clazz = GoSocial::Facebook
12
+ params = clazz.options_to_data(clazz.default_options_like_button.merge(options))
13
+ params.merge!(class: LIKE_BUTTON_CLASS)
14
+
15
+ html = "".html_safe
16
+ html << content_tag(:div, nil, id: "fb-root")
17
+ html << clazz.script
18
+ html << content_tag(:div, nil, params)
19
+ html
20
+ end
21
+
22
+ # Facebook Like Box
23
+ def like_box(options = {})
24
+ clazz = GoSocial::Facebook
25
+ params = clazz.options_to_data(clazz.default_options_like_box.merge(options))
26
+ params.merge!(class: LIKE_BOX_CLASS)
27
+
28
+ html = "".html_safe
29
+ html << content_tag(:div, nil, id: "fb-root")
30
+ html << clazz.script
31
+ html << content_tag(:div, nil, params)
32
+ html
33
+ end
34
+
35
+ # Facebook Comment Box
36
+ def comment_box(options = {})
37
+ clazz = GoSocial::Facebook
38
+ params = clazz.options_to_data(clazz.default_options_comment_box.merge(options))
39
+ params.merge!(class: COMMENT_CLASS)
40
+
41
+ html = "".html_safe
42
+ html << content_tag(:div, nil, id: "fb-root")
43
+ html << clazz.script
44
+ html << content_tag(:div, nil, params)
45
+ html
46
+ end
47
+
48
+
49
+ class << self
50
+ def default_options_like_button
51
+ @default_options ||= {
52
+ send: "false",
53
+ layout: "box_count",
54
+ width: "250",
55
+ action: "like",
56
+ font: "arial",
57
+ colorscheme: "light"
58
+ }.merge("show-faces" => "false")
59
+ end
60
+
61
+
62
+ def default_options_like_box
63
+ @default_options ||= {
64
+ send: "false",
65
+ stream: "true",
66
+ width: "250",
67
+ height: "150",
68
+ header: "true",
69
+ colorscheme: "light"
70
+ }.merge("show-faces" => "true", "show-border" => "true")
71
+ end
72
+
73
+
74
+ def default_options_comment_box
75
+ @default_options ||= {
76
+ width: "250",
77
+ colorscheme: "light"
78
+ }.merge("num-posts" => "2")
79
+ end
80
+
81
+ def script
82
+ '<script>
83
+ (function(d, s, id) {
84
+ var js, fjs = d.getElementsByTagName(s)[0];
85
+ if (d.getElementById(id)) return;
86
+ js = d.createElement(s); js.id = id;
87
+ js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
88
+ fjs.parentNode.insertBefore(js, fjs);
89
+ }(document, "script", "facebook-jssdk"));
90
+ </script>'.html_safe
91
+ end
92
+
93
+ #def js_sdk app_id
94
+ # "https://connect.facebook.net/en_US/all.js#xfbml=1&appId=#{app_id}"
95
+ #end
96
+ end
97
+ end
98
+ end
@@ -0,0 +1,101 @@
1
+ module GoSocial
2
+ module Facebook
3
+ include GoSocial::Assistant
4
+
5
+ LIKE_BUTTON_CLASS = "fb-like"
6
+ LIKE_BOX_CLASS = "fb-like-box"
7
+ COMMENT_CLASS = "fb-comments"
8
+
9
+ # Facebook Like Button
10
+ def like_button(options = {})
11
+ clazz = GoSocial::Facebook
12
+ params = clazz.options_to_data(clazz.default_options_like_button.merge(options))
13
+ params.merge!(class: LIKE_BUTTON_CLASS)
14
+
15
+ html = "".html_safe
16
+ html << content_tag(:div, nil, id: "fb-root")
17
+ html << clazz.script
18
+ html << content_tag(:div, nil, params)
19
+ html
20
+ end
21
+
22
+ # Facebook Like Box
23
+ def like_box(options = {})
24
+ clazz = GoSocial::Facebook
25
+ params = clazz.options_to_data(clazz.default_options_like_box.merge(options))
26
+ params.merge!(class: LIKE_BOX_CLASS)
27
+
28
+ html = "".html_safe
29
+ html << content_tag(:div, nil, id: "fb-root")
30
+ html << clazz.script
31
+ html << content_tag(:div, nil, params)
32
+ html
33
+ end
34
+
35
+ # Facebook Comment Box
36
+ def comment_box(options = {})
37
+ clazz = GoSocial::Facebook
38
+ params = clazz.options_to_data(clazz.default_options_comment_box.merge(options))
39
+ params.merge!(class: COMMENT_CLASS)
40
+
41
+ html = "".html_safe
42
+ html << content_tag(:div, nil, id: "fb-root")
43
+ html << clazz.script
44
+ html << content_tag(:div, nil, params)
45
+ html
46
+ end
47
+
48
+ # To avoid polluting namespace in like button
49
+ class << self
50
+ def default_options_like_button
51
+ @default_options ||= {
52
+ send: "false",
53
+ layout: "box_count",
54
+ width: "250",
55
+ action: "like",
56
+ font: "arial",
57
+ colorscheme: "light"
58
+ }.merge("show-faces" => "false")
59
+ end
60
+
61
+ # To avoid polluting namespace in like box
62
+ def default_options_like_box
63
+ @default_options ||= {
64
+ send: "false",
65
+ stream: "true",
66
+ width: "250",
67
+ height: "150",
68
+ header: "true",
69
+ colorscheme: "light"
70
+ }.merge("show-faces" => "true", "show-border" => "true")
71
+ end
72
+
73
+ # To avoid polluting namespace in comment box
74
+ def default_options_comment_box
75
+ @default_options ||= {
76
+ width: "250",
77
+ colorscheme: "light"
78
+ }.merge("num-posts" => "2")
79
+ end
80
+
81
+ def script
82
+ return blank_content if scriptized?
83
+ #@scriptized = true
84
+ # "<script src=#{js_sdk(app_id)} type='text/javascript'></script>".html_safe
85
+ '<script>
86
+ (function(d, s, id) {
87
+ var js, fjs = d.getElementsByTagName(s)[0];
88
+ if (d.getElementById(id)) return;
89
+ js = d.createElement(s); js.id = id;
90
+ js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
91
+ fjs.parentNode.insertBefore(js, fjs);
92
+ }(document, "script", "facebook-jssdk"));
93
+ </script>'.html_safe
94
+ end
95
+
96
+ #def js_sdk app_id
97
+ # "https://connect.facebook.net/en_US/all.js#xfbml=1&appId=#{app_id}"
98
+ #end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,86 @@
1
+ module GoSocial
2
+ module Pinterest
3
+ include GoSocial::Assistant
4
+
5
+ PINIT_BUTTON = "http://pinterest.com/pin/create/button/"
6
+ PINIT_IMAGE = "//assets.pinterest.com/images/pidgets/pin_it_button.png"
7
+ CLASS = "pin-it-button"
8
+ TITLE = "Pin It"
9
+
10
+ #Pin it button
11
+ def pinit_button(options = {})
12
+ clazz = GoSocial::Pinterest
13
+ default_options = {url: request.url, media: request.url}
14
+ params = clazz.default_options.merge(clazz.default_options).merge(options)
15
+ params.merge!(:class => CLASS)
16
+
17
+ query_string = clazz.options_to_query(self, params)
18
+ option_params = params.except(:url, :media, :description)
19
+ pinit_link = PINIT_BUTTON + query_string
20
+
21
+ html = "".html_safe
22
+ html << link_to(pinit_link, option_params) do
23
+ image_tag PINIT_IMAGE, border: ("0" || options[:border]), title: (TITLE || options[:title])
24
+ end
25
+ html << clazz.script
26
+ html
27
+ end
28
+
29
+ #Pin-it follow button
30
+ def pinit_follow_button(options = {})
31
+ clazz = GoSocial::Pinterest
32
+ default_options_follow = {href: request.url}
33
+
34
+ params = clazz.default_options_follow.merge(clazz.default_options_follow).merge(options)
35
+ option_params = params.except(:href)
36
+
37
+ html = "".html_safe
38
+ html << link_to(params[:title], params[:href], option_params)
39
+ html << clazz.script
40
+ html
41
+ end
42
+
43
+ #Pin-it embed user (to display pins of a user)
44
+ def pinit_embeduser_button(options = {})
45
+ clazz = GoSocial::Pinterest
46
+ default_options_embed = {href: request.url}
47
+
48
+ params = clazz.default_options_embed.merge(clazz.default_options_embed).merge(options)
49
+ option_params = params.except(:href)
50
+
51
+ html = "".html_safe
52
+ html << link_to(params[:title], params[:href], option_params)
53
+ html << clazz.script
54
+ html
55
+ end
56
+
57
+
58
+ class << self
59
+ def default_options
60
+ @default_options ||= {
61
+ description: "Pin Me!"
62
+ }.merge("data-pin-do" => "buttonPin")
63
+ end
64
+
65
+ def default_options_follow
66
+ @default_options_follow ||= {
67
+ title: "Pinterest"
68
+ }.merge("data-pin-do" => "buttonFollow", :href => "http://pinterest.com/loremipsum007/")
69
+ end
70
+
71
+ def default_options_embed
72
+ @default_options_embed ||= {
73
+ title: "Pinterest"
74
+ }.merge("data-pin-do" => "embedUser", :href => "http://pinterest.com/loremipsum007/")
75
+ end
76
+
77
+ def script
78
+ "<script src=#{pinit_js} type='text/javascript'></script>".html_safe
79
+ end
80
+
81
+ def pinit_js
82
+ "https://assets.pinterest.com/js/pinit.js"
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,86 @@
1
+ module GoSocial
2
+ module Pinterest
3
+ include GoSocial::Assistant
4
+
5
+ PINIT_BUTTON = "http://pinterest.com/pin/create/button/"
6
+ PINIT_IMAGE = "//assets.pinterest.com/images/pidgets/pin_it_button.png"
7
+ CLASS = "pin-it-button"
8
+ TITLE = "Pin It"
9
+
10
+ #Pin it button
11
+ def pinit_button(options = {})
12
+ clazz = GoSocial::Pinterest
13
+ default_options = {url: request.url, media: request.url}
14
+ params = clazz.default_options.merge(clazz.default_options).merge(options)
15
+ params.merge!(:class => CLASS)
16
+
17
+ query_string = clazz.options_to_query(self, params)
18
+ option_params = params.except(:url, :media, :description)
19
+ pinit_link = PINIT_BUTTON + query_string
20
+
21
+ html = "".html_safe
22
+ html << link_to(pinit_link, option_params) do
23
+ image_tag PINIT_IMAGE, border: ("0" || options[:border]), title: (TITLE || options[:title])
24
+ end
25
+ html << clazz.script
26
+ html
27
+ end
28
+
29
+ #Pin-it follow button
30
+ def pinit_follow_button(options = {})
31
+ clazz = GoSocial::Pinterest
32
+ default_options_follow = {href: request.url}
33
+
34
+ params = clazz.default_options_follow.merge(clazz.default_options_follow).merge(options)
35
+ option_params = params.except(:href)
36
+
37
+ html = "".html_safe
38
+ html << link_to(params[:title], params[:href], option_params)
39
+ html << clazz.script
40
+ html
41
+ end
42
+
43
+ #Pin-it embed user (to display pins of a user)
44
+ def pinit_embeduser_button(options = {})
45
+ clazz = GoSocial::Pinterest
46
+ default_options_embed = {href: request.url}
47
+
48
+ params = clazz.default_options_embed.merge(clazz.default_options_embed).merge(options)
49
+ option_params = params.except(:href)
50
+
51
+ html = "".html_safe
52
+ html << link_to(params[:title], params[:href], option_params)
53
+ html << clazz.script
54
+ html
55
+ end
56
+
57
+
58
+ class << self
59
+ def default_options
60
+ @default_options ||= {
61
+ description: "Pin Me!"
62
+ }.merge("data-pin-do" => "buttonPin")
63
+ end
64
+
65
+ def default_options_follow
66
+ @default_options_follow ||= {
67
+ title: "Pinterest"
68
+ }.merge("data-pin-do" => "buttonFollow", :href => "http://pinterest.com/loremipsum007/")
69
+ end
70
+
71
+ def default_options_embed
72
+ @default_options_embed ||= {
73
+ title: "Pinterest"
74
+ }.merge("data-pin-do" => "embedUser", :href => "http://pinterest.com/loremipsum007/")
75
+ end
76
+
77
+ def script
78
+ "<script src=#{pinit_js} type='text/javascript'></script>".html_safe
79
+ end
80
+
81
+ def pinit_js
82
+ "https://assets.pinterest.com/js/pinit.js"
83
+ end
84
+ end
85
+ end
86
+ end
@@ -0,0 +1,80 @@
1
+ module GoSocial
2
+ module Twitter
3
+ include GoSocial::Assistant
4
+
5
+ TWITTER_SHARE_URL = "http://twitter.com/share"
6
+ TWEET_CLASS = "twitter-share-button"
7
+ TWITTER_FOLLOW_CLASS = "twitter-follow-button"
8
+ TWITTER_TIMELINE = "twitter-timeline"
9
+
10
+ #Tweet button
11
+ def tweet_button(options = {})
12
+ clazz = GoSocial::Twitter
13
+ params = clazz.options_to_data(clazz.default_options.merge(options))
14
+ params.merge!(class: TWEET_CLASS)
15
+
16
+ html = "".html_safe
17
+ html << clazz.script
18
+ html << link_to("Tweet", TWITTER_SHARE_URL, params)
19
+ html
20
+ end
21
+
22
+ #Twitter follow button
23
+ def twitter_follow_button(options = {})
24
+ clazz = GoSocial::Twitter
25
+ params = clazz.options_to_data(clazz.default_options_follow.merge(options))
26
+ params.merge!(class: TWITTER_FOLLOW_CLASS)
27
+
28
+ html = "".html_safe
29
+ html << clazz.script
30
+ html << link_to(params[:title], clazz.default_options_follow[:href], params)
31
+ html
32
+ end
33
+
34
+ #Twitter timeline
35
+ def twitter_timeline(options = {})
36
+ clazz = GoSocial::Twitter
37
+ params = clazz.options_to_data(clazz.default_options_timeline.merge(options))
38
+ params.merge!(class: TWITTER_TIMELINE)
39
+
40
+ html = "".html_safe
41
+ html << clazz.script
42
+ html << link_to(params[:title], clazz.default_options_timeline[:href], params)
43
+ html
44
+ end
45
+
46
+ class << self
47
+ def default_options
48
+ @default_options ||= {
49
+ via: "tweetbutton",
50
+ text: "",
51
+ count: "vertical",
52
+ lang: "en",
53
+ related: ""
54
+ }
55
+ end
56
+
57
+ def default_options_follow
58
+ @default_options_follow ||= {
59
+ title: "Follow @loremipsum007",
60
+ size: "large",
61
+ lang: "en"
62
+ }.merge(:href => "https://twitter.com/loremipsum007")
63
+ end
64
+
65
+ def default_options_timeline
66
+ @default_options_timeline ||= {
67
+ lang: "en"
68
+ }.merge("widget-id" => "341385883435536386", :href => "https://twitter.com/loremipsum007")
69
+ end
70
+
71
+ def script
72
+ "<script src=#{twitter_wjs} type='text/javascript'></script>".html_safe
73
+ end
74
+
75
+ def twitter_wjs
76
+ "http://platform.twitter.com/widgets.js"
77
+ end
78
+ end # class
79
+ end
80
+ end
@@ -0,0 +1,80 @@
1
+ module GoSocial
2
+ module Twitter
3
+ include GoSocial::Assistant
4
+
5
+ TWITTER_SHARE_URL = "http://twitter.com/share"
6
+ TWEET_CLASS = "twitter-share-button"
7
+ TWITTER_FOLLOW_CLASS = "twitter-follow-button"
8
+ TWITTER_TIMELINE = "twitter-timeline"
9
+
10
+ #Tweet button
11
+ def tweet_button(options = {})
12
+ clazz = GoSocial::Twitter
13
+ params = clazz.options_to_data(clazz.default_options.merge(options))
14
+ params.merge!(class: TWEET_CLASS)
15
+
16
+ html = "".html_safe
17
+ html << clazz.script
18
+ html << link_to("Tweet", TWITTER_SHARE_URL, params)
19
+ html
20
+ end
21
+
22
+ #Twitter follow button
23
+ def twitter_follow_button(options = {})
24
+ clazz = GoSocial::Twitter
25
+ params = clazz.options_to_data(clazz.default_options_follow.merge(options))
26
+ params.merge!(class: TWITTER_FOLLOW_CLASS)
27
+
28
+ html = "".html_safe
29
+ html << clazz.script
30
+ html << link_to(params[:title], clazz.default_options_follow[:href], params)
31
+ html
32
+ end
33
+
34
+ #Twitter timeline
35
+ def twitter_timeline(options = {})
36
+ clazz = GoSocial::Twitter
37
+ params = clazz.options_to_data(clazz.default_options_timeline.merge(options))
38
+ params.merge!(class: TWITTER_TIMELINE)
39
+
40
+ html = "".html_safe
41
+ html << clazz.script
42
+ html << link_to(params[:title], clazz.default_options_timeline[:href], params)
43
+ html
44
+ end
45
+
46
+ class << self
47
+ def default_options
48
+ @default_options ||= {
49
+ via: "tweetbutton",
50
+ text: "",
51
+ count: "vertical",
52
+ lang: "en",
53
+ related: ""
54
+ }
55
+ end
56
+
57
+ def default_options_follow
58
+ @default_options_follow ||= {
59
+ title: "Follow @loremipsum007",
60
+ size: "large",
61
+ lang: "en"
62
+ }.merge(:href => "https://twitter.com/loremipsum007")
63
+ end
64
+
65
+ def default_options_timeline
66
+ @default_options_timeline ||= {
67
+ lang: "en"
68
+ }.merge("widget-id" => "341385883435536386", :href => "https://twitter.com/loremipsum007")
69
+ end
70
+
71
+ def script
72
+ "<script src=#{twitter_wjs} type='text/javascript'></script>".html_safe
73
+ end
74
+
75
+ def twitter_wjs
76
+ "http://platform.twitter.com/widgets.js"
77
+ end
78
+ end # class
79
+ end
80
+ end
@@ -0,0 +1,3 @@
1
+ module GoSocial
2
+ VERSION = "0.0.1"
3
+ end
@@ -0,0 +1,42 @@
1
+ module GoSocial
2
+ module Assistant
3
+ extend ActiveSupport::Concern
4
+
5
+ module ClassMethods
6
+ attr_reader :scriptized
7
+ attr_writer :default_options
8
+ alias_method :scriptized?, :scriptized
9
+
10
+ def my_name
11
+ self.name.demodulize
12
+ end
13
+
14
+ def help
15
+ "Please HELP by filling in the help of the #{myname} button :) (see google+ button code)"
16
+ end
17
+
18
+ def options_to_data(opts)
19
+ params = {}
20
+ opts.each {|k, v| params["data-#{k}"] = v}
21
+ params
22
+ end
23
+
24
+ def options_to_query(subject, opts)
25
+ # formulate the url, and then strip the part before first '?'
26
+ query_params = opts.slice(:url, :media, :description)
27
+ full_url = subject.url_for(query_params)
28
+ full_url.sub(/^([^?]*)/, '')
29
+ end
30
+
31
+ protected
32
+
33
+ def help_note
34
+ "Note: GoSocial will make sure that the widget scripts are rendered once only!"
35
+ end
36
+
37
+ def blank_content
38
+ "".html_safe
39
+ end
40
+ end
41
+ end
42
+ end
@@ -0,0 +1,101 @@
1
+ module GoSocial
2
+ module Like
3
+ include GoSocial::Assistant
4
+
5
+ LIKE_BUTTON_CLASS = "fb-like"
6
+ LIKE_BOX_CLASS = "fb-like-box"
7
+ COMMENT_CLASS = "fb-comments"
8
+
9
+ # Facebook Like Button
10
+ def like_button(app_id, options = {})
11
+ clazz = GoSocial::Like
12
+ params = clazz.options_to_data(clazz.default_options_like_button.merge(options))
13
+ params.merge!(class: LIKE_BUTTON_CLASS)
14
+
15
+ html = "".html_safe
16
+ html << content_tag(:div, nil, id: "fb-root")
17
+ html << clazz.script(app_id)
18
+ html << content_tag(:div, nil, params)
19
+ html
20
+ end
21
+
22
+ # Facebook Like Box
23
+ def like_box(app_id, options = {})
24
+ clazz = GoSocial::Like
25
+ params = clazz.options_to_data(clazz.default_options_like_box.merge(options))
26
+ params.merge!(class: LIKE_BOX_CLASS)
27
+
28
+ html = "".html_safe
29
+ html << content_tag(:div, nil, id: "fb-root")
30
+ html << clazz.script(app_id)
31
+ html << content_tag(:div, nil, params)
32
+ html
33
+ end
34
+
35
+ # Facebook Comment Box
36
+ def comment_box(app_id, options = {})
37
+ clazz = GoSocial::Like
38
+ params = clazz.options_to_data(clazz.default_options_comment_box.merge(options))
39
+ params.merge!(class: COMMENT_CLASS)
40
+
41
+ html = "".html_safe
42
+ html << content_tag(:div, nil, id: "fb-root")
43
+ html << clazz.script(app_id)
44
+ html << content_tag(:div, nil, params)
45
+ html
46
+ end
47
+
48
+ # To avoid polluting namespace in like button
49
+ class << self
50
+ def default_options_like_button
51
+ @default_options ||= {
52
+ send: "false",
53
+ layout: "box_count",
54
+ width: "250",
55
+ action: "like",
56
+ font: "arial",
57
+ colorscheme: "light"
58
+ }.merge("show-faces" => "false")
59
+ end
60
+
61
+ # To avoid polluting namespace in like box
62
+ def default_options_like_box
63
+ @default_options ||= {
64
+ send: "false",
65
+ stream: "true",
66
+ width: "250",
67
+ show-border: "true",
68
+ header: "true",
69
+ colorscheme: "light"
70
+ }.merge("show-faces" => "true")
71
+ end
72
+
73
+ # To avoid polluting namespace in comment box
74
+ def default_options_comment_box
75
+ @default_options ||= {
76
+ width: "250",
77
+ colorscheme: "light"
78
+ }.merge("num-posts" => "2")
79
+ end
80
+
81
+ def script(app_id)
82
+ return blank_content if scriptized?
83
+ @scriptized = true
84
+ # "<script src=#{js_sdk(app_id)} type='text/javascript'></script>".html_safe
85
+ '<script>
86
+ (function(d, s, id) {
87
+ var js, fjs = d.getElementsByTagName(s)[0];
88
+ if (d.getElementById(id)) return;
89
+ js = d.createElement(s); js.id = id;
90
+ js.src = "//connect.facebook.net/en_US/all.js#xfbml=1";
91
+ fjs.parentNode.insertBefore(js, fjs);
92
+ }(document, "script", "facebook-jssdk"));
93
+ </script>'.html_safe
94
+ end
95
+
96
+ #def js_sdk app_id
97
+ # "https://connect.facebook.net/en_US/all.js#xfbml=1&appId=#{app_id}"
98
+ #end
99
+ end
100
+ end
101
+ end
@@ -0,0 +1,14 @@
1
+ module GoSocial
2
+ [GoSocial.names << :assistant].flatten.each do |name|
3
+ #autoload name.to_s.camelize.to_sym, "go_social/view_helpers/#{name}"
4
+ autoload name.to_s.camelize.to_sym, "go_social/#{name}"
5
+ end
6
+
7
+ module ViewHelper
8
+ # Include all widgets into ViewHelper to be made available
9
+ # to be included into a View as one module (see engine)
10
+ GoSocial.names.each do |name|
11
+ self.send :include, "GoSocial::#{name.to_s.camelize}".constantize
12
+ end
13
+ end
14
+ end
@@ -0,0 +1,14 @@
1
+ module GoSocial
2
+ [GoSocial.names << :assistant].flatten.each do |name|
3
+ #autoload name.to_s.camelize.to_sym, "go_social/view_helpers/#{name}"
4
+ autoload name.to_s.camelize.to_sym, "go_social/#{name}"
5
+ end
6
+
7
+ module ViewHelper
8
+ # Include all widgets into ViewHelper to be made available
9
+ # to be included into a View as one module (see engine)
10
+ GoSocial.names.each do |name|
11
+ self.send :include, "GoSocial::#{name.to_s.camelize}".constantize
12
+ end
13
+ end
14
+ end
data/lib/go_social.rb ADDED
@@ -0,0 +1,25 @@
1
+ require "go_social/version"
2
+
3
+ module GoSocial
4
+
5
+ def self.names
6
+ %w{facebook pinterest twitter}
7
+ end
8
+
9
+ def self.config name = nil, &block
10
+ context = name ? "GoSocial::#{name.to_s.camelize}".constantize : self
11
+ block_given? ? yield(context) : context
12
+ end
13
+
14
+ # add class method for each social widgets registered
15
+ names.each do |name|
16
+ (class << self; self; end).send :define_method, name do |&block|
17
+ clazz = "GoSocial::#{name.to_s.camelize}".constantize
18
+ block_given? ? clazz.instance_eval(&block) : clazz
19
+ end
20
+ end
21
+
22
+ end
23
+
24
+ require "go_social/view_helper"
25
+ require "go_social/engine" if defined?(::Rails::Engine)
data/lib/go_social.rb~ ADDED
@@ -0,0 +1,26 @@
1
+ require "go_social/version"
2
+
3
+ module GoSocial
4
+
5
+ def self.names
6
+ #%w{pinit tweet like google_plus}
7
+ %w{facebook pinterest twitter}
8
+ end
9
+
10
+ def self.config name = nil, &block
11
+ context = name ? "GoSocial::#{name.to_s.camelize}".constantize : self
12
+ block_given? ? yield(context) : context
13
+ end
14
+
15
+ # add class method for each social widgets registered
16
+ names.each do |name|
17
+ (class << self; self; end).send :define_method, name do |&block|
18
+ clazz = "GoSocial::#{name.to_s.camelize}".constantize
19
+ block_given? ? clazz.instance_eval(&block) : clazz
20
+ end
21
+ end
22
+
23
+ end
24
+
25
+ require "go_social/view_helper"
26
+ require "go_social/engine" if defined?(::Rails::Engine)
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: go_social
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Rakesh Jha
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-06-03 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rails
16
+ requirement: !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: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
30
+ description: This gem helps to add various social widgets that are commonly used by
31
+ rails applications. Supports Facebook, Pinterest, Twitter, Flickr, LinkedIn and
32
+ Google+.
33
+ email:
34
+ - mrrakesh2112@gmail.com
35
+ executables: []
36
+ extensions: []
37
+ extra_rdoc_files: []
38
+ files:
39
+ - Gemfile
40
+ - LICENSE.txt
41
+ - README.md
42
+ - Rakefile
43
+ - go_social.gemspec
44
+ - lib/go_social.rb
45
+ - lib/go_social.rb~
46
+ - lib/go_social/assistant.rb
47
+ - lib/go_social/assistant.rb~
48
+ - lib/go_social/engine.rb
49
+ - lib/go_social/engine.rb~
50
+ - lib/go_social/facebook.rb
51
+ - lib/go_social/facebook.rb~
52
+ - lib/go_social/like.rb~
53
+ - lib/go_social/pinterest.rb
54
+ - lib/go_social/pinterest.rb~
55
+ - lib/go_social/twitter.rb
56
+ - lib/go_social/twitter.rb~
57
+ - lib/go_social/version.rb
58
+ - lib/go_social/view_helper.rb
59
+ - lib/go_social/view_helper.rb~
60
+ - lib/go_social/view_helper/assistant.rb~
61
+ - lib/go_social/view_helper/facebook.rb~
62
+ homepage: https://github.com/Jrakesh/go_social
63
+ licenses: []
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ none: false
70
+ requirements:
71
+ - - ! '>='
72
+ - !ruby/object:Gem::Version
73
+ version: '0'
74
+ required_rubygems_version: !ruby/object:Gem::Requirement
75
+ none: false
76
+ requirements:
77
+ - - ! '>='
78
+ - !ruby/object:Gem::Version
79
+ version: '0'
80
+ requirements: []
81
+ rubyforge_project:
82
+ rubygems_version: 1.8.25
83
+ signing_key:
84
+ specification_version: 3
85
+ summary: A complete social media makeover.
86
+ test_files: []