go_social 0.0.1 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,6 +1,6 @@
1
- Copyright (c) 2013 TODO: Write your name
1
+ Copyright (c) 2013 Rakesh Jha.
2
2
 
3
- MIT License
3
+ Copyright (c) 2012 Yuva Kumar.
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining
6
6
  a copy of this software and associated documentation files (the
@@ -19,4 +19,4 @@ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
19
  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
20
  LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
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.
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,6 +1,26 @@
1
1
  # GoSocial
2
2
 
3
- TODO: Write a gem description
3
+ Currently there is support for the following social widgets/buttons:
4
+
5
+ ##### Facebook
6
+ * Like Button
7
+ * Like Box
8
+ * Comment Box
9
+
10
+ ##### Pinterest
11
+ * Pinit Button
12
+ * Pinit_follow Button
13
+ * Pinit Embeduser
14
+
15
+ ##### Twitter
16
+ * Tweet Button
17
+ * Twitter_follow Button
18
+ * Twitter timeline
19
+
20
+ ##### Linked In
21
+ * Linkedin Share Button
22
+ * Linkedin Follow Company Button
23
+ * Linkedin Member Profile Button
4
24
 
5
25
  ## Installation
6
26
 
@@ -18,7 +38,97 @@ Or install it yourself as:
18
38
 
19
39
  ## Usage
20
40
 
21
- TODO: Write usage instructions here
41
+ Using SocialButtons is as simple as adding a single method call to your views:
42
+
43
+ ERB example:
44
+ ```erb
45
+ // with optional parameters.
46
+
47
+ <%= like_button(:href => "url-to-be-liked") %>
48
+ <%= comment_box(:href => "url-to-be-liked" ) %>
49
+ <%= like_box(:href => "url-to-be-liked") %>
50
+
51
+ //data-pin-config can have values like above, beside or none
52
+ <%= pinit_button(:url=> "to-refer" , :media =>"image-url" , :description => "Amazing picture", "data-pin-config" => "above") %>
53
+ <%= pinit_follow_button(:title => "user-name") %>
54
+ <%= pinit_embeduser_button %>
55
+
56
+ <%= tweet_button(:via => "your-twitter-name") %>
57
+ <%= twitter_follow_button(:href => "twitter-user-url-to-follow") %>
58
+ <%= twitter_timeline("widget-id" => "your-widget-id", :href => "timeline-url") %>
59
+
60
+ //counter can have values like top, right or none. By default it is top.
61
+ <%= linkedin_share_button(:counter => "right", :url => "linkedin-url-of-user-or-comapny-page") %>
62
+ <%= linkedin_follow_company_button(:counter => "right", :id => "company-id-to-follow") %>
63
+ //format can have values like inline or hover
64
+ <%= linkedin_profile_button(:format => "hover", :text => "John Doe", :width => "400px" , :id => "linkedin-url-of-user-or-comapny-page") %>
65
+
66
+ ```
67
+
68
+ Done. You'll have lovely Social Buttons all up in your view.
69
+
70
+ Of course, you can customize it. Depending on the type of button, there are different options.
71
+
72
+ ### Like Button
73
+
74
+ * `:href` - The URL to like, the default is the current URL.
75
+ * `:send` - Whether to add a send button or not.
76
+ * `:layout` - Size and amount of social context next to button. Has 3 options `:standard`, `:button_count`, and `:box_count`
77
+ * `:width` - Width of the button
78
+ * `"show-faces"` - Show profile photos
79
+ * `:action` - Action name like 'like' or 'recommend'
80
+ * `:font` - Font for the button
81
+ * `:colorscheme` - Current colorscheme
82
+
83
+ More information can be found from [Facebook](http://developers.facebook.com/docs/reference/plugins/like/)
84
+
85
+ So, a simple like button can be added like this:
86
+
87
+ ```erb
88
+ <%= like_button(:href => "url-to-be-liked") %>
89
+ ```
90
+
91
+ ### Pinit Button
92
+
93
+ * `:url` - The URL to share; the default is the current URL.
94
+ * `:media` - The image to be shared.
95
+ * `:description` - Description for the link.
96
+ * `"count-layout"` - Specify pinit count. It can be `horizontal`, `vertical` or `none`.
97
+
98
+ More information can be found from [Pinterest](http://pinterest.com/about/goodies/)
99
+
100
+ So, a simple pinit button can be added like this:
101
+
102
+ ```erb
103
+ <%= pinit_button(url: "your-url", media: @picture.image.url, description: "Amazing Picture") %>
104
+ ```
105
+
106
+ ### Tweet Button
107
+
108
+ * `:url` - The URL to share; the default is the current URL.
109
+ * `:text` - The text that will appear in the tweet; the default is "Check this out!"
110
+ * `:via` - The attribution. Defaults to "tweetbutton", but you should change that.
111
+ * `:lang` - Set the language for the tweet (no default).
112
+ * `:related` - Related Twitter accounts (no default).
113
+ * `:count` - The tweet count box position (values can be "none", "horizontal", or "vertical"; default is "vertical").
114
+
115
+ More information can be found from [Twitter](https://twitter.com/about/resources/buttons#tweet)
116
+
117
+ So, if you wanted to tweet, attribute it to "loremipsum007", and add some custom text, all from a tweet button with a horizontal counter, you'd do this:
118
+
119
+ ```erb
120
+ <%= tweet_button(via: => "loremipsum007", url: "https://twitter.com/loremipsum007", :text => "AWESOME GEM.") %>
121
+ ```
122
+
123
+
124
+ *In all cases, only the options you specify will be overridden; so if you only specify a new default `:via`, then the other defaults will stay intact.
125
+
126
+
127
+ ## TODO
128
+
129
+ * Add tests
130
+ * Give more control to customize buttons
131
+ * Add more social buttons.
22
132
 
23
133
  ## Contributing
24
134
 
@@ -27,3 +137,4 @@ TODO: Write usage instructions here
27
137
  3. Commit your changes (`git commit -am 'Add some feature'`)
28
138
  4. Push to the branch (`git push origin my-new-feature`)
29
139
  5. Create new Pull Request
140
+
@@ -3,7 +3,7 @@ require "go_social/version"
3
3
  module GoSocial
4
4
 
5
5
  def self.names
6
- %w{facebook pinterest twitter}
6
+ %w{facebook pinterest twitter linkedin}
7
7
  end
8
8
 
9
9
  def self.config name = nil, &block
@@ -11,7 +11,7 @@ module GoSocial
11
11
  block_given? ? yield(context) : context
12
12
  end
13
13
 
14
- # add class method for each social widgets registered
14
+ # adding class method for each social widgets registered
15
15
  names.each do |name|
16
16
  (class << self; self; end).send :define_method, name do |&block|
17
17
  clazz = "GoSocial::#{name.to_s.camelize}".constantize
@@ -77,7 +77,8 @@ module GoSocial
77
77
  colorscheme: "light"
78
78
  }.merge("num-posts" => "2")
79
79
  end
80
-
80
+
81
+ # Facebook Script
81
82
  def script
82
83
  '<script>
83
84
  (function(d, s, id) {
@@ -0,0 +1,77 @@
1
+ module GoSocial
2
+ module Linkedin
3
+ include GoSocial::Assistant
4
+
5
+ SHARE_TYPE = "IN/Share"
6
+ FOLLOW_COMPANY_TYPE = "IN/FollowCompany"
7
+ PROFILE_TYPE = "IN/MemberProfile"
8
+
9
+ # Linkedin Share Button
10
+ def linkedin_share_button(options = {})
11
+ clazz = GoSocial::Linkedin
12
+ params = clazz.options_to_data(clazz.default_options_share_button.merge(options))
13
+ params.merge!(type: SHARE_TYPE)
14
+
15
+ html = "".html_safe
16
+ html << clazz.script
17
+ html << content_tag(:script, nil, params)
18
+ html
19
+ end
20
+
21
+ # Linkedin Follow Company Button
22
+ def linkedin_follow_company_button(options = {})
23
+ clazz = GoSocial::Linkedin
24
+ params = clazz.options_to_data(clazz.default_options_follow_company_button.merge(options))
25
+ params.merge!(type: FOLLOW_COMPANY_TYPE)
26
+
27
+ html = "".html_safe
28
+ html << clazz.script
29
+ html << content_tag(:script, nil, params)
30
+ html
31
+ end
32
+
33
+ # Linkedin Member Profile Button
34
+ def linkedin_profile_button(options = {})
35
+ clazz = GoSocial::Linkedin
36
+ params = clazz.options_to_data(clazz.default_options_profile_button.merge(options))
37
+ params.merge!(type: PROFILE_TYPE)
38
+
39
+ html = "".html_safe
40
+ html << clazz.script
41
+ html << content_tag(:script, nil, params)
42
+ html
43
+ end
44
+
45
+
46
+ class << self
47
+ def default_options_share_button
48
+ @default_options_share_button ||= {
49
+ counter: "top"
50
+ }.merge("url" => "http://www.linkedin.com/pub/john-doe/72/a64/a89")
51
+ end
52
+
53
+ def default_options_follow_company_button
54
+ @default_options_follow_company_button ||= {
55
+ counter: "top"
56
+ }.merge("id" => "2440759")
57
+ end
58
+
59
+ def default_options_profile_button
60
+ @default_options_profile_button ||= {
61
+ format: "inline",
62
+ width: "305px"
63
+ }.merge("id" => "http://www.linkedin.com/pub/cipher-test/72/760/310")
64
+ end
65
+
66
+
67
+
68
+ # Linkedin Script
69
+ def script
70
+ '<script src="//platform.linkedin.com/in.js" type="text/javascript">
71
+ lang: en_US
72
+ </script>'.html_safe
73
+ end
74
+
75
+ end
76
+ end
77
+ end
@@ -1,3 +1,3 @@
1
1
  module GoSocial
2
- VERSION = "0.0.1"
2
+ VERSION = "0.1.0"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: go_social
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.1.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2013-06-03 00:00:00.000000000 Z
12
+ date: 2013-06-04 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rails
@@ -42,23 +42,14 @@ files:
42
42
  - Rakefile
43
43
  - go_social.gemspec
44
44
  - lib/go_social.rb
45
- - lib/go_social.rb~
46
45
  - lib/go_social/assistant.rb
47
- - lib/go_social/assistant.rb~
48
46
  - lib/go_social/engine.rb
49
- - lib/go_social/engine.rb~
50
47
  - lib/go_social/facebook.rb
51
- - lib/go_social/facebook.rb~
52
- - lib/go_social/like.rb~
48
+ - lib/go_social/linkedin.rb
53
49
  - lib/go_social/pinterest.rb
54
- - lib/go_social/pinterest.rb~
55
50
  - lib/go_social/twitter.rb
56
- - lib/go_social/twitter.rb~
57
51
  - lib/go_social/version.rb
58
52
  - 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
53
  homepage: https://github.com/Jrakesh/go_social
63
54
  licenses: []
64
55
  post_install_message:
@@ -1,26 +0,0 @@
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)
@@ -1,42 +0,0 @@
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
@@ -1,9 +0,0 @@
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
@@ -1,98 +0,0 @@
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
@@ -1,101 +0,0 @@
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
@@ -1,86 +0,0 @@
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
@@ -1,80 +0,0 @@
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
@@ -1,14 +0,0 @@
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
@@ -1,42 +0,0 @@
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
@@ -1,101 +0,0 @@
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