shareable 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/Gemfile +4 -0
- data/MIT-LICENSE +20 -0
- data/README.md +102 -0
- data/README.rdoc +74 -0
- data/app/views/shareable/_facebook.html.erb +20 -0
- data/app/views/shareable/_google_plus.html.erb +21 -0
- data/app/views/shareable/_linkedin.html.erb +8 -0
- data/app/views/shareable/_pinterest.html.erb +24 -0
- data/app/views/shareable/_reddit.html.erb +11 -0
- data/app/views/shareable/_social_buttons.html.erb +7 -0
- data/app/views/shareable/_twitter.html.erb +21 -0
- data/lib/shareable.rb +27 -0
- data/lib/shareable/config.rb +95 -0
- data/lib/shareable/engine.rb +4 -0
- data/lib/shareable/helpers/action_view_extension.rb +48 -0
- data/lib/shareable/helpers/social_buttons.rb +85 -0
- data/lib/shareable/helpers/tags.rb +61 -0
- data/lib/shareable/hooks.rb +9 -0
- data/lib/shareable/railtie.rb +7 -0
- data/lib/shareable/version.rb +3 -0
- metadata +171 -0
data/Gemfile
ADDED
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 hermango
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,102 @@
|
|
1
|
+
Shareable
|
2
|
+
=========
|
3
|
+
A simple and unobtrusive gem for adding social link sharing to your Rails app. Supported social sites include:
|
4
|
+
- Facebook
|
5
|
+
- Twitter
|
6
|
+
- Pinterest
|
7
|
+
- Reddit
|
8
|
+
- Linkedin
|
9
|
+
- & Google Plus
|
10
|
+
|
11
|
+
Install
|
12
|
+
--------
|
13
|
+
Put this line in your Gemfile:
|
14
|
+
|
15
|
+
gem 'shareable'
|
16
|
+
|
17
|
+
Then run the bundle command:
|
18
|
+
|
19
|
+
bundle
|
20
|
+
|
21
|
+
Usage
|
22
|
+
------
|
23
|
+
### Views
|
24
|
+
To add shareable in views use any of the following methods:
|
25
|
+
+ render_shareable
|
26
|
+
+ facebook_button
|
27
|
+
+ twitter_button
|
28
|
+
+ pinterest_button
|
29
|
+
+ reddit_button
|
30
|
+
+ google_plus_button
|
31
|
+
...
|
32
|
+
|
33
|
+
For the easiest way to use shareable, add this helper method to your view:
|
34
|
+
|
35
|
+
```no-highlight
|
36
|
+
<%= render_shareable %>
|
37
|
+
```
|
38
|
+
|
39
|
+
### Advanced Usage
|
40
|
+
Pass hash values to the render_shareable method to overwrite options locally:
|
41
|
+
```no-highlight
|
42
|
+
<%= render_shareable :url=> 'http://github.com/hermango/', :facebook=> {:send=> 'true', :url=> 'http://demo.com'} %>
|
43
|
+
```
|
44
|
+
|
45
|
+
To render only certain buttons:
|
46
|
+
```no-highlight
|
47
|
+
<%= render_shareable :buttons=> ['twitter', 'facebook'] %>
|
48
|
+
```
|
49
|
+
|
50
|
+
Alternatively, omit the render_shareable method entirely and instead add each social link individually.
|
51
|
+
The helper method for each social link, is the site name joined with an underscore to the word 'button'. E.g.:
|
52
|
+
|
53
|
+
```no-highlight
|
54
|
+
<%= twitter_button %>
|
55
|
+
<%= reddit_button :title=> 'Alternate Title' %>
|
56
|
+
```
|
57
|
+
|
58
|
+
To override the default view for a button, place your own template file in the
|
59
|
+
app/views/shareable/ directory and prepend your filename with an underscore.
|
60
|
+
|
61
|
+
E.g.: facebook_button -> app/views/shareable/_facebook.html.erb
|
62
|
+
|
63
|
+
#### Facebook compatibility with Internet Explorer
|
64
|
+
Add an XML namespace fb='http://ogp.me/ns/fb#' to the <html> tag of your view. Eg:
|
65
|
+
```no-highlight
|
66
|
+
<html xmlns:fb="http://ogp.me/ns/fb#">
|
67
|
+
```
|
68
|
+
|
69
|
+
This is necessary for XFBML to work in earlier versions of Internet Explorer.
|
70
|
+
|
71
|
+
#### Styling for social buttons
|
72
|
+
For horizontally aligned buttons, try this CSS:
|
73
|
+
|
74
|
+
```no-highlight
|
75
|
+
nav.share {display:inline-block;} /* shareable's nav tag */
|
76
|
+
nav.share div {float:left; overflow:hidden;}
|
77
|
+
nav.share iframe {max-height:20px; border:0; margin-top:0; padding-top:0;} /* if using medium sized buttons */
|
78
|
+
#___plusone_0 {max-width:70px; font-size: default; !important}
|
79
|
+
.twitter-share-button, .twitter-count-horizontal {max-width:80px;}
|
80
|
+
.fb_iframe_widget span { vertical-align: top; }
|
81
|
+
.fb_edge_widget_with_comment { vertical-align: top;}
|
82
|
+
.fb-like{display:inline-block}
|
83
|
+
* html .fb-like{display:inline}/* ie6 inline block fix*/
|
84
|
+
*+html .fb-like{display:inline}/* ie7 inline block fix*/
|
85
|
+
```
|
86
|
+
|
87
|
+
Configuration
|
88
|
+
------------
|
89
|
+
Use shareable's default configuration settings or add your own initializer named 'shareable.rb' to your app's 'config/initializers' directory.
|
90
|
+
|
91
|
+
A generator is available for generating the default configuration file into the 'config/initializers' directory.
|
92
|
+
Run the following generator command, then edit the generated file.
|
93
|
+
|
94
|
+
rails g shareable:config
|
95
|
+
|
96
|
+
To Do:
|
97
|
+
---------
|
98
|
+
- Add Tests.
|
99
|
+
- More buttons.
|
100
|
+
- More.
|
101
|
+
|
102
|
+
This project is based on Akira Matsuda's Kamanari project and uses the MIT-LICENSE. Suggestions, bug reports, criticism and all contributions welcome.
|
data/README.rdoc
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
= Shareable
|
2
|
+
A simple and unobtrusive gem for adding social link sharing to your Rails app. Social sites include:
|
3
|
+
- Facebook
|
4
|
+
- Twitter
|
5
|
+
- Pinterest
|
6
|
+
- Reddit
|
7
|
+
- & Google Plus
|
8
|
+
|
9
|
+
===Install
|
10
|
+
Put this line in your Gemfile:
|
11
|
+
gem 'shareable'
|
12
|
+
|
13
|
+
Then run bundle command:
|
14
|
+
bundle
|
15
|
+
|
16
|
+
==Usage
|
17
|
+
=== Views
|
18
|
+
To use shareable in views add any of the following methods:
|
19
|
+
-render_shareable
|
20
|
+
-facebook_button
|
21
|
+
-twitter_button
|
22
|
+
-pinterest_button
|
23
|
+
-reddit_button
|
24
|
+
-google_plus_button
|
25
|
+
...
|
26
|
+
|
27
|
+
For example, add the helper method to your view:
|
28
|
+
<%= render_shareable %>
|
29
|
+
|
30
|
+
===Advanced Usage
|
31
|
+
Overwrite options locally by passing hash values to the render_shareable method like so:
|
32
|
+
<%= render_shareable :url=> 'http://github.com/hermango/', :facebook=> {:send=> 'true', :width=> '100', :url=> 'http://demo.com'} %>
|
33
|
+
To render only certain buttons:
|
34
|
+
<%= render_shareable :buttons=> ['twitter', 'facebook'] %>
|
35
|
+
|
36
|
+
Alternatively, omit the render_shareable method entirely and instead add each social link individually.
|
37
|
+
The helper method for each social link, is the site name joined with an underscore to the word 'button'. E.g.:
|
38
|
+
<%= twitter_button %>
|
39
|
+
<%= reddit_button :title=> 'Alternate Title' %>
|
40
|
+
|
41
|
+
To override the default view for a button, place your own template file in the
|
42
|
+
app/views/shareable/ directory and prepend your filename with an underscore.
|
43
|
+
E.g.: facebook_button -> *app/views/shareable/_facebook.html.erb*
|
44
|
+
|
45
|
+
*Facebook compatibility with Internet Explorer*
|
46
|
+
Add an XML namespace fb="http://ogp.me/ns/fb#" to the <html> tag of your view. Eg: <html xmlns:fb="http://ogp.me/ns/fb#">
|
47
|
+
This is necessary for XFBML to work in earlier versions of Internet Explorer for pages on which the like button appears.
|
48
|
+
|
49
|
+
*Styling for social buttons*
|
50
|
+
For horizontally aligned buttons, try this CSS:
|
51
|
+
nav.share {display:inline-block;} /* shareable's nav tag */
|
52
|
+
nav.share div {float:left; overflow:hidden;}
|
53
|
+
nav.share iframe {max-height:20px; border:0; margin-top:0; padding-top:0;} /* if using medium sized buttons */
|
54
|
+
#___plusone_0 {max-width:70px; font-size: default; !important}
|
55
|
+
.twitter-share-button, .twitter-count-horizontal {max-width:80px;}
|
56
|
+
.fb_iframe_widget span { vertical-align: top; }
|
57
|
+
.fb_edge_widget_with_comment { vertical-align: top;}
|
58
|
+
.fb-like{display:inline-block}
|
59
|
+
* html .fb-like{display:inline}/* ie6 inline block fix*/
|
60
|
+
*+html .fb-like{display:inline}/* ie7 inline block fix*/
|
61
|
+
|
62
|
+
===Configuration
|
63
|
+
Use shareable's configuration settings or add your own initializer named 'shareable.rb' to the 'config/initializers' directory.
|
64
|
+
|
65
|
+
A generator is available for generating the default configuration file into the 'config/initializers' directory.
|
66
|
+
Run the following generator command, then edit the generated file.
|
67
|
+
% rails g shareable:config
|
68
|
+
|
69
|
+
==To Do:
|
70
|
+
- Add Tests.
|
71
|
+
- More buttons.
|
72
|
+
- More.
|
73
|
+
|
74
|
+
This project is based on Akira Matsuda's Kamanari project and uses the MIT-LICENSE. Suggestions, bug reports, criticism and all contributions welcome.
|
@@ -0,0 +1,20 @@
|
|
1
|
+
<%= output_once :facebook do %>
|
2
|
+
<div id="fb-root"></div>
|
3
|
+
<script>(function(d, s, id) {
|
4
|
+
var js, fjs = d.getElementsByTagName(s)[0];
|
5
|
+
if (d.getElementById(id)) return;
|
6
|
+
js = d.createElement(s); js.id = id;
|
7
|
+
js.src = "//connect.facebook.net/en_US/all.js#xfbml=1<%= raw('&appId=' + options[:app_id]) unless options[:app_id].empty? %>";
|
8
|
+
fjs.parentNode.insertBefore(js, fjs);
|
9
|
+
}(document, 'script', 'facebook-jssdk'));</script>
|
10
|
+
<% end %>
|
11
|
+
|
12
|
+
<fb:like href='<%= options[:url] %>'
|
13
|
+
send='<%= options[:send] %>'
|
14
|
+
layout='<%= options[:layout] %>'
|
15
|
+
show_faces='<%= options[:show_faces] %>'
|
16
|
+
width='<%= options[:width] %>'
|
17
|
+
action='<%= options[:action] %>'
|
18
|
+
font='<%= options[:font] %>'
|
19
|
+
colorscheme='<%= options[:colorscheme] %>'
|
20
|
+
ref='<%= options[:ref] %>' ></fb:like>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<div class='g-plusone gplusshare'
|
2
|
+
data-href='<%= options[:url] %>'
|
3
|
+
data-size='<%= options[:size] %>'
|
4
|
+
data-annotation='<%= options[:annotation] %>'
|
5
|
+
data-width='<%= options[:width] %>'
|
6
|
+
data-align='<%= options[:align] %>'
|
7
|
+
data-expandTo='<%= options[:expand_to] %>'
|
8
|
+
data-callback='<%= options[:callback] %>'
|
9
|
+
data-onstartinteraction='<%= options[:onstartinteraction] %>'
|
10
|
+
data-onendinteraction='<%= options[:onendinteraction] %>'
|
11
|
+
data-recommendations='<%= options[:recommendations] %>'
|
12
|
+
></div>
|
13
|
+
<%= output_once :google_plus do %>
|
14
|
+
<script type="text/javascript">
|
15
|
+
(function() {
|
16
|
+
var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
|
17
|
+
po.src = 'https://apis.google.com/js/plusone.js';
|
18
|
+
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
|
19
|
+
})();
|
20
|
+
</script>
|
21
|
+
<% end %>
|
@@ -0,0 +1,8 @@
|
|
1
|
+
<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
|
2
|
+
<script type="IN/Share"
|
3
|
+
data-url='<%= options[:url] %>'
|
4
|
+
data-counter='<%= options[:counter] %>'
|
5
|
+
data-onerror='<%= options[:onerror]%>'
|
6
|
+
data-onsuccess='<%= options[:onsuccess]%>'
|
7
|
+
data-showzero='<%= options[:showzero] %>'
|
8
|
+
></script>
|
@@ -0,0 +1,24 @@
|
|
1
|
+
<a data-pin-config='<%= options[:pin_config] %>'
|
2
|
+
href="//pinterest.com/pin/create/button/?url=<%= options[:url] %><%= raw('&media=' + options[:media]) unless options[:media].blank? %><%= raw('&description=' + options[:description]) unless options[:description].blank? %>"
|
3
|
+
data-pin-do='<%= options[:pin_do] %>' >
|
4
|
+
<img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" title='<%= options[:title]%>' alt='<%= options[:alt] %>' /></a>
|
5
|
+
|
6
|
+
<%= output_once :pinterest do %>
|
7
|
+
<script type="text/javascript">
|
8
|
+
(function (d, buildThese) {
|
9
|
+
var homeScript, newScript, n = buildThese.length, i;
|
10
|
+
for (i = 0; i < n; i = i + 1) {
|
11
|
+
newScript = d.createElement('SCRIPT');
|
12
|
+
newScript.type = 'text/javascript';
|
13
|
+
newScript.async = true;
|
14
|
+
newScript.src = buildThese[i];
|
15
|
+
homeScript = d.getElementsByTagName('SCRIPT')[0];
|
16
|
+
homeScript.parentNode.insertBefore(newScript, homeScript);
|
17
|
+
}
|
18
|
+
}(document, [
|
19
|
+
'//assets.pinterest.com/js/pinit.js'
|
20
|
+
/* load more third-party JavaScript here */
|
21
|
+
])
|
22
|
+
);
|
23
|
+
</script>
|
24
|
+
<% end %>
|
@@ -0,0 +1,11 @@
|
|
1
|
+
<script type="text/javascript">
|
2
|
+
reddit_url='<%= options[:url] %>';
|
3
|
+
reddit_target='<%= options[:target]%>';
|
4
|
+
reddit_title='<%= options[:title] %>';
|
5
|
+
reddit_bgcolor='<%= options[:color] %>';
|
6
|
+
reddit_bordercolor='<%= options[:bordercolor] %>';
|
7
|
+
reddit_newwindow='<%= options[:newwindow] %>';
|
8
|
+
</script>
|
9
|
+
<script type="text/javascript"
|
10
|
+
src="<%= raw((options[:btnsrc].blank? ? ('http://www.reddit.com/static/button/button' + options[:type] + '.js?i=' + options[:points]) : options[:btnsrc]) + '&styled=' + options[:styled]) %>">
|
11
|
+
</script>
|
@@ -0,0 +1,21 @@
|
|
1
|
+
<!--script src='http://platform.twitter.com/widgets.js' type='text/javascript'></script> -->
|
2
|
+
<a href='http://twitter.com/share'
|
3
|
+
class='twitter-share-button'
|
4
|
+
data-url='<%= options[:url] %>'
|
5
|
+
data-via='<%= options[:via] %>'
|
6
|
+
data-text='<%= options[:text] %>'
|
7
|
+
data-related='<%= options[:related] %>'
|
8
|
+
data-count='<%= options[:count] %>'
|
9
|
+
data-lang='<%= options[:lang] %>'
|
10
|
+
data-counturl='<%= options[:counturl] %>'
|
11
|
+
data-hashtags='<%= options[:hashtags] %>'
|
12
|
+
data-size='<%= options[:size] %>'
|
13
|
+
data-dnt='<%= options[:dnt] %>'>Tweet</a>
|
14
|
+
|
15
|
+
<script>!function(d,s,id){
|
16
|
+
var js,fjs=d.getElementsByTagName(s)[0];
|
17
|
+
if(!d.getElementById(id)){
|
18
|
+
js=d.createElement(s);
|
19
|
+
js.id=id;js.src="//platform.twitter.com/widgets.js";
|
20
|
+
fjs.parentNode.insertBefore(js,fjs);}} (document,"script","twitter-wjs");
|
21
|
+
</script>
|
data/lib/shareable.rb
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
module Shareable
|
2
|
+
end
|
3
|
+
|
4
|
+
# load Rails/Railtie
|
5
|
+
begin
|
6
|
+
require 'rails'
|
7
|
+
rescue LoadError
|
8
|
+
#do nothing
|
9
|
+
end
|
10
|
+
|
11
|
+
$stderr.puts <<-EOC if !defined?(Rails)
|
12
|
+
warning: no rails framework detected.
|
13
|
+
|
14
|
+
Your Gemfile might not be configured properly.
|
15
|
+
---- e.g. ----
|
16
|
+
Rails:
|
17
|
+
gem 'shareable'
|
18
|
+
EOC
|
19
|
+
|
20
|
+
require 'shareable/config'
|
21
|
+
require 'shareable/helpers/action_view_extension'
|
22
|
+
require 'shareable/helpers/social_buttons'
|
23
|
+
require 'shareable/hooks'
|
24
|
+
if defined? Rails
|
25
|
+
require 'shareable/railtie'
|
26
|
+
require 'shareable/engine'
|
27
|
+
end
|
@@ -0,0 +1,95 @@
|
|
1
|
+
require 'active_support/configurable'
|
2
|
+
|
3
|
+
module Shareable
|
4
|
+
# Configures global settings for Shareable
|
5
|
+
def self.configure(&block)
|
6
|
+
yield @config ||= Shareable::Configuration.new
|
7
|
+
end
|
8
|
+
|
9
|
+
# Global settings for Shareable
|
10
|
+
def self.config
|
11
|
+
@config
|
12
|
+
end
|
13
|
+
|
14
|
+
# need a Class for 3.0
|
15
|
+
class Configuration #:nodoc:
|
16
|
+
include ActiveSupport::Configurable
|
17
|
+
config_accessor :names, :url, :send, :layout, :show_faces, :title, :alt, :target, :app_id,
|
18
|
+
:width, :action, :font, :colorscheme, :ref, :annotation, :align, :expand_to, :callback,
|
19
|
+
:onstartinteraction, :onendinteraction, :pin_config, :pin_do, :media, :color,
|
20
|
+
:bordercolor, :btnsrc, :via, :text, :related, :count, :lang, :counturl, :hashtags, :size, :dnt,
|
21
|
+
:type, :styled, :newwindow, :description, :counter, :onsuccess, :onerror, :showzero,
|
22
|
+
:recommendations, :points
|
23
|
+
end
|
24
|
+
|
25
|
+
configure do |config|
|
26
|
+
config.names = %w[ twitter facebook linkedin pinterest google_plus reddit ]
|
27
|
+
|
28
|
+
##############
|
29
|
+
#facebook
|
30
|
+
##############
|
31
|
+
config.app_id = ''
|
32
|
+
config.send= 'false'
|
33
|
+
config.layout='button_count'
|
34
|
+
config.show_faces=''
|
35
|
+
config.width='80'
|
36
|
+
config.action=''
|
37
|
+
config.font=''
|
38
|
+
config.colorscheme=''
|
39
|
+
config.ref=''
|
40
|
+
|
41
|
+
##############
|
42
|
+
#google_plus
|
43
|
+
##############
|
44
|
+
config.annotation='bubble'
|
45
|
+
config.recommendations='false'
|
46
|
+
config.align=''
|
47
|
+
config.expand_to=''
|
48
|
+
config.callback=''
|
49
|
+
config.onstartinteraction=''
|
50
|
+
config.onendinteraction=''
|
51
|
+
|
52
|
+
##############
|
53
|
+
#linkedin
|
54
|
+
##############
|
55
|
+
config.counter = 'right'
|
56
|
+
config.onsuccess = ''
|
57
|
+
config.onerror = ''
|
58
|
+
config.showzero = 'true'
|
59
|
+
|
60
|
+
##############
|
61
|
+
#pinterest
|
62
|
+
##############
|
63
|
+
config.pin_config = 'beside'
|
64
|
+
config.pin_do = 'buttonPin'
|
65
|
+
config.title= '' # title for content, also used by reddit button
|
66
|
+
config.alt='' # alternate text for image tag
|
67
|
+
config.media=''
|
68
|
+
config.description='Pin This'
|
69
|
+
|
70
|
+
##############
|
71
|
+
#reddit
|
72
|
+
##############
|
73
|
+
config.target=''
|
74
|
+
config.color=''
|
75
|
+
config.bordercolor=''
|
76
|
+
config.styled='off'
|
77
|
+
config.newwindow='1'
|
78
|
+
config.btnsrc='' # alternate reddit button url, eg: 'http://www.reddit.com/buttonlite.js?i=1'
|
79
|
+
config.type= '1' # button type, eg: 1 to n
|
80
|
+
config.points = '1' # points style, eg: 0 to 5
|
81
|
+
|
82
|
+
##############
|
83
|
+
#twitter
|
84
|
+
##############
|
85
|
+
config.via='tweetbutton'
|
86
|
+
config.text=''
|
87
|
+
config.related=''
|
88
|
+
config.count='horizontal'
|
89
|
+
config.lang='en'
|
90
|
+
config.counturl=''
|
91
|
+
config.hashtags=''
|
92
|
+
config.size='medium'
|
93
|
+
config.dnt=''
|
94
|
+
end
|
95
|
+
end
|
@@ -0,0 +1,48 @@
|
|
1
|
+
require 'shareable/helpers/social_buttons'
|
2
|
+
|
3
|
+
module Shareable
|
4
|
+
# = Helpers
|
5
|
+
module ActionViewExtension
|
6
|
+
# A helper that renders social links
|
7
|
+
# <%= render_shareable [options] %>
|
8
|
+
def render_shareable(options = {}, &block)
|
9
|
+
buttons = Shareable::Helpers::SocialButtons.new self, refine_options(options)
|
10
|
+
buttons.to_s
|
11
|
+
end
|
12
|
+
|
13
|
+
Shareable::Helpers::SocialButtons.buttons.each do |button|
|
14
|
+
eval <<-DEF
|
15
|
+
def #{button}_button(options = {})
|
16
|
+
#{button} = Shareable::Helpers::#{button.split('_').collect(&:capitalize).join}.new self, refine_options(options, :#{button})
|
17
|
+
#{button}.to_s
|
18
|
+
end
|
19
|
+
DEF
|
20
|
+
end
|
21
|
+
|
22
|
+
#credit to http://elektronaut.no/
|
23
|
+
def output_once(name, &block) #:nodoc:
|
24
|
+
@output_once_blocks ||= []
|
25
|
+
unless @output_once_blocks.include?(name)
|
26
|
+
@output_once_blocks << name
|
27
|
+
capture(&block)
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
protected
|
32
|
+
def refine_options(options={},button=nil)
|
33
|
+
options[:options] ||= {}
|
34
|
+
options[:options].merge! options.except(:options)
|
35
|
+
if options[:url].blank? then
|
36
|
+
options[:options][:url] = request.url
|
37
|
+
end
|
38
|
+
#only do for button method calls, don't do this render_shareable
|
39
|
+
if button
|
40
|
+
#add values from configuration to our options for each option that is not passed as part of the button method call
|
41
|
+
(Shareable::Helpers::SocialButtons.config_options[button] - options[:options].keys).each do |key|
|
42
|
+
options[:options][key] = Shareable.config.config.values_at(key).first
|
43
|
+
end
|
44
|
+
end
|
45
|
+
options
|
46
|
+
end
|
47
|
+
end
|
48
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
require 'active_support/inflector'
|
2
|
+
require 'action_view'
|
3
|
+
require 'action_view/log_subscriber'
|
4
|
+
require 'action_view/context'
|
5
|
+
require 'shareable/helpers/tags'
|
6
|
+
|
7
|
+
module Shareable
|
8
|
+
module Helpers
|
9
|
+
class SocialButtons < Tag
|
10
|
+
include ::ActionView::Context
|
11
|
+
cattr_accessor :buttons
|
12
|
+
self.buttons = %w[ twitter facebook pinterest reddit google_plus linkedin ]
|
13
|
+
|
14
|
+
#not very DRY. Refactor.
|
15
|
+
cattr_accessor :config_options
|
16
|
+
self.config_options = {
|
17
|
+
:facebook => [ :app_id, :send, :layout, :show_faces, :width, :action, :font, :colorscheme, :ref ],
|
18
|
+
:google_plus => [ :annotation, :recommendations, :align, :expand_to, :callback, :onstartinteraction, :onendinteraction, :size, :width ],
|
19
|
+
:linkedin => [ :counter, :onsuccess, :onerror, :showzero ],
|
20
|
+
:pinterest => [ :pin_config, :pin_do, :title, :alt, :media, :description ],
|
21
|
+
:reddit => [ :title, :target, :color, :bordercolor, :type, :styled, :newwindow, :btnsrc, :points ],
|
22
|
+
:twitter => [ :via, :text, :related, :count, :lang, :counturl, :hashtags, :size, :dnt ]}
|
23
|
+
|
24
|
+
def initialize(template, options) #:nodoc:
|
25
|
+
@template, @options = template, options
|
26
|
+
@options[:buttons] ||= allowable(Shareable.config.names)
|
27
|
+
@options[:options] ||= {}
|
28
|
+
Shareable.config.config.each_key do |key|
|
29
|
+
@options[:options].merge! key => (options[key].blank? ? Shareable.config.config.values_at(key).first : options[key])
|
30
|
+
end
|
31
|
+
# initialize @output_bugger i.v. used in ActionView::Context
|
32
|
+
@output_buffer = ActionView::OutputBuffer.new
|
33
|
+
end
|
34
|
+
|
35
|
+
# render given block, view template for socialize class
|
36
|
+
def render(&block) #:nodoc:
|
37
|
+
instance_eval(&block)
|
38
|
+
@output_buffer
|
39
|
+
end
|
40
|
+
|
41
|
+
buttons.each do |tag|
|
42
|
+
eval <<-DEF
|
43
|
+
def #{tag}_tag
|
44
|
+
#{tag.split('_').collect(&:capitalize).join}.new @template, @options
|
45
|
+
end
|
46
|
+
DEF
|
47
|
+
end
|
48
|
+
|
49
|
+
def to_s #:nodoc:
|
50
|
+
#from Kamanari for handling log subscriber:
|
51
|
+
subscriber = ActionView::LogSubscriber.log_subscribers.detect {|ls| ls.is_a? ActionView::LogSubscriber}
|
52
|
+
return super @options.merge :social_buttons => self unless subscriber
|
53
|
+
|
54
|
+
# dirty hack to suppress logging render_partial
|
55
|
+
class << subscriber
|
56
|
+
alias_method :render_partial_with_logging, :render_partial
|
57
|
+
# do nothing
|
58
|
+
def render_partial(event); end
|
59
|
+
end
|
60
|
+
|
61
|
+
ret = super @options.merge :social_buttons => self
|
62
|
+
|
63
|
+
class << subscriber
|
64
|
+
alias_method :render_partial, :render_partial_with_logging
|
65
|
+
undef :render_partial_with_logging
|
66
|
+
end
|
67
|
+
ret
|
68
|
+
end
|
69
|
+
|
70
|
+
def each_relevant_button #:nodoc:
|
71
|
+
@options[:buttons].each do |button|
|
72
|
+
yield button
|
73
|
+
end
|
74
|
+
end
|
75
|
+
|
76
|
+
alias :each_button :each_relevant_button
|
77
|
+
|
78
|
+
protected
|
79
|
+
|
80
|
+
def allowable(names)
|
81
|
+
names.select { |b| buttons.include? b }
|
82
|
+
end
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,61 @@
|
|
1
|
+
module Shareable
|
2
|
+
module Helpers
|
3
|
+
class Tag
|
4
|
+
def initialize(template, options = {}) #:nodoc:
|
5
|
+
@template, @options = template, options.dup
|
6
|
+
end
|
7
|
+
|
8
|
+
def to_s(locals = {}) #:nodoc:
|
9
|
+
@template.render :partial => "shareable/#{self.class.name.demodulize.underscore}", :locals => @options.merge(locals)
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
class Socialize < Tag
|
14
|
+
def to_s(locals={}) #:nodoc:
|
15
|
+
locals[:options] ||= {}
|
16
|
+
social_site = self.class.name.demodulize.downcase.to_sym
|
17
|
+
if @options[:options]
|
18
|
+
@options[:filtered] ||= @options[:options].reject {|opt| locals[:options].include?(opt)}
|
19
|
+
locals[:options].merge!(@options[:filtered])
|
20
|
+
end
|
21
|
+
if @options[social_site]
|
22
|
+
locals[:options].merge!(@options[social_site])
|
23
|
+
end
|
24
|
+
super locals
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
class Facebook < Socialize
|
29
|
+
end
|
30
|
+
|
31
|
+
class GooglePlus < Socialize
|
32
|
+
end
|
33
|
+
|
34
|
+
class Linkedin < Socialize
|
35
|
+
end
|
36
|
+
|
37
|
+
class Pinterest < Socialize
|
38
|
+
def to_s(locals={}) #:nodoc:
|
39
|
+
locals[:options] ||= {}
|
40
|
+
unless @options[:options].blank?
|
41
|
+
p_opts = {:description => CGI::escape(@options[:options][:description] ? @options[:options][:description] : '' ),
|
42
|
+
:url => CGI::escape(@options[:options][:url] ? @options[:options][:url] : ''),
|
43
|
+
:media => CGI::escape(@options[:options][:media] ? @options[:options][:media] : '')}
|
44
|
+
locals[:options].merge!(@options[:options].merge(p_opts))
|
45
|
+
if @options[:pinterest]
|
46
|
+
@options[:pinterest][:description] = CGI::escape(@options[:pinterest][:description]) if @options[:pinterest][:description]
|
47
|
+
@options[:pinterest][:url] = CGI::escape(@options[:pinterest][:url]) if @options[:pinterest][:url]
|
48
|
+
@options[:pinterest][:media] = CGI::escape(@options[:pinterest][:media]) if @options[:pinterest][:media]
|
49
|
+
end
|
50
|
+
end
|
51
|
+
super locals
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
class Reddit < Socialize
|
56
|
+
end
|
57
|
+
|
58
|
+
class Twitter < Socialize
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
metadata
ADDED
@@ -0,0 +1,171 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shareable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 0
|
8
|
+
- 1
|
9
|
+
version: 0.0.1
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Hermango
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2013-03-22 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: activesupport
|
22
|
+
prerelease: false
|
23
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
24
|
+
requirements:
|
25
|
+
- - ">="
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 3
|
29
|
+
- 0
|
30
|
+
- 0
|
31
|
+
version: 3.0.0
|
32
|
+
type: :runtime
|
33
|
+
version_requirements: *id001
|
34
|
+
- !ruby/object:Gem::Dependency
|
35
|
+
name: actionpack
|
36
|
+
prerelease: false
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
requirements:
|
39
|
+
- - ">="
|
40
|
+
- !ruby/object:Gem::Version
|
41
|
+
segments:
|
42
|
+
- 3
|
43
|
+
- 0
|
44
|
+
- 0
|
45
|
+
version: 3.0.0
|
46
|
+
type: :runtime
|
47
|
+
version_requirements: *id002
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
52
|
+
requirements:
|
53
|
+
- - ">="
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
segments:
|
56
|
+
- 1
|
57
|
+
- 0
|
58
|
+
- 0
|
59
|
+
version: 1.0.0
|
60
|
+
type: :development
|
61
|
+
version_requirements: *id003
|
62
|
+
- !ruby/object:Gem::Dependency
|
63
|
+
name: tzinfo
|
64
|
+
prerelease: false
|
65
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
66
|
+
requirements:
|
67
|
+
- - ">="
|
68
|
+
- !ruby/object:Gem::Version
|
69
|
+
segments:
|
70
|
+
- 0
|
71
|
+
version: "0"
|
72
|
+
type: :development
|
73
|
+
version_requirements: *id004
|
74
|
+
- !ruby/object:Gem::Dependency
|
75
|
+
name: rspec
|
76
|
+
prerelease: false
|
77
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
78
|
+
requirements:
|
79
|
+
- - ">="
|
80
|
+
- !ruby/object:Gem::Version
|
81
|
+
segments:
|
82
|
+
- 0
|
83
|
+
version: "0"
|
84
|
+
type: :development
|
85
|
+
version_requirements: *id005
|
86
|
+
- !ruby/object:Gem::Dependency
|
87
|
+
name: rr
|
88
|
+
prerelease: false
|
89
|
+
requirement: &id006 !ruby/object:Gem::Requirement
|
90
|
+
requirements:
|
91
|
+
- - ">="
|
92
|
+
- !ruby/object:Gem::Version
|
93
|
+
segments:
|
94
|
+
- 0
|
95
|
+
version: "0"
|
96
|
+
type: :development
|
97
|
+
version_requirements: *id006
|
98
|
+
- !ruby/object:Gem::Dependency
|
99
|
+
name: capybara
|
100
|
+
prerelease: false
|
101
|
+
requirement: &id007 !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - ">="
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
segments:
|
106
|
+
- 1
|
107
|
+
- 0
|
108
|
+
version: "1.0"
|
109
|
+
type: :development
|
110
|
+
version_requirements: *id007
|
111
|
+
description: Add social sharing links to a view in your Rails app with one method call. The configuration options for each social link are customizable. Please see read me doc for more details.
|
112
|
+
email:
|
113
|
+
executables: []
|
114
|
+
|
115
|
+
extensions: []
|
116
|
+
|
117
|
+
extra_rdoc_files: []
|
118
|
+
|
119
|
+
files:
|
120
|
+
- app/views/shareable/_facebook.html.erb
|
121
|
+
- app/views/shareable/_google_plus.html.erb
|
122
|
+
- app/views/shareable/_linkedin.html.erb
|
123
|
+
- app/views/shareable/_pinterest.html.erb
|
124
|
+
- app/views/shareable/_reddit.html.erb
|
125
|
+
- app/views/shareable/_social_buttons.html.erb
|
126
|
+
- app/views/shareable/_twitter.html.erb
|
127
|
+
- lib/shareable/helpers/action_view_extension.rb
|
128
|
+
- lib/shareable/helpers/social_buttons.rb
|
129
|
+
- lib/shareable/helpers/tags.rb
|
130
|
+
- lib/shareable/config.rb
|
131
|
+
- lib/shareable/engine.rb
|
132
|
+
- lib/shareable/hooks.rb
|
133
|
+
- lib/shareable/railtie.rb
|
134
|
+
- lib/shareable/version.rb
|
135
|
+
- lib/shareable.rb
|
136
|
+
- MIT-LICENSE
|
137
|
+
- Gemfile
|
138
|
+
- README.rdoc
|
139
|
+
- README.md
|
140
|
+
has_rdoc: true
|
141
|
+
homepage: http://github.com/hermango/shareable
|
142
|
+
licenses:
|
143
|
+
- MIT
|
144
|
+
post_install_message:
|
145
|
+
rdoc_options: []
|
146
|
+
|
147
|
+
require_paths:
|
148
|
+
- lib
|
149
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
150
|
+
requirements:
|
151
|
+
- - ">="
|
152
|
+
- !ruby/object:Gem::Version
|
153
|
+
segments:
|
154
|
+
- 0
|
155
|
+
version: "0"
|
156
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
157
|
+
requirements:
|
158
|
+
- - ">="
|
159
|
+
- !ruby/object:Gem::Version
|
160
|
+
segments:
|
161
|
+
- 0
|
162
|
+
version: "0"
|
163
|
+
requirements: []
|
164
|
+
|
165
|
+
rubyforge_project:
|
166
|
+
rubygems_version: 1.3.6
|
167
|
+
signing_key:
|
168
|
+
specification_version: 3
|
169
|
+
summary: Simple and unobtrusive gem for adding social links to your Rails app.
|
170
|
+
test_files: []
|
171
|
+
|