Permalink
Browse files

First shareable commmit

  • Loading branch information...
0 parents commit d81707080f8e6ba079cf8187246c285549f85a9e Herman committed Mar 22, 2013
@@ -0,0 +1,6 @@
+*.gem
+.bundle
+.idea
+Gemfile.lock
+gemfiles/*.lock
+doc
@@ -0,0 +1,4 @@
+source "http://rubygems.org"
+
+gemspec
+
@@ -0,0 +1,20 @@
+Copyright 2013 hermango
+
+Permission is hereby granted, free of charge, to any person obtaining
+a copy of this software and associated documentation files (the
+"Software"), to deal in the Software without restriction, including
+without limitation the rights to use, copy, modify, merge, publish,
+distribute, sublicense, and/or sell copies of the Software, and to
+permit persons to whom the Software is furnished to do so, subject to
+the following conditions:
+
+The above copyright notice and this permission notice shall be
+included in all copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
+EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
+MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
+NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
+LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
+OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
+WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,74 @@
+= Shareable
+A simple and unobtrusive gem for adding social link sharing to your Rails app. Social sites include:
+ - Facebook
+ - Twitter
+ - Pinterest
+ - Reddit
+ - & Google Plus
+
+===Install
+Put this line in your Gemfile:
+ gem 'shareable'
+
+Then run bundle command:
+ bundle
+
+==Usage
+=== Views
+To use shareable in views add any of the following methods:
+-render_shareable
+-facebook_button
+-twitter_button
+-pinterest_button
+-reddit_button
+-google_plus_button
+...
+
+For example, add the helper method to your view:
+<%= render_shareable %>
+
+===Advanced Usage
+Overwrite options locally by passing hash values to the render_shareable method like so:
+<%= render_shareable :url=> 'http://github.com/hermango/', :facebook=> {:send=> 'true', :width=> '100', :url=> 'http://demo.com'} %>
+To render only certain buttons:
+<%= render_shareable :buttons=> ['twitter', 'facebook'] %>
+
+Alternatively, omit the render_shareable method entirely and instead add each social link individually.
+The helper method for each social link, is the site name joined with an underscore to the word 'button'. E.g.:
+<%= twitter_button %>
+<%= reddit_button :title=> 'Alternate Title' %>
+
+To override the default view for a button, place your own template file in the
+app/views/shareable/ directory and prepend your filename with an underscore.
+E.g.: facebook_button -> *app/views/shareable/_facebook.html.erb*
+
+*Facebook compatibility with Internet Explorer*
+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#">
+This is necessary for XFBML to work in earlier versions of Internet Explorer for pages on which the like button appears.
+
+*Styling for social buttons*
+For horizontally aligned buttons, try this CSS:
+nav.share {display:inline-block;} /* shareable's nav tag */
+nav.share div {float:left; overflow:hidden;}
+nav.share iframe {max-height:20px; border:0; margin-top:0; padding-top:0;} /* if using medium sized buttons */
+#___plusone_0 {max-width:70px; font-size: default; !important}
+.twitter-share-button, .twitter-count-horizontal {max-width:80px;}
+.fb_iframe_widget span { vertical-align: top; }
+.fb_edge_widget_with_comment { vertical-align: top;}
+.fb-like{display:inline-block}
+* html .fb-like{display:inline}/* ie6 inline block fix*/
+*+html .fb-like{display:inline}/* ie7 inline block fix*/
+
+===Configuration
+Use shareable's configuration settings or add your own initializer named 'shareable.rb' to the 'config/initializers' directory.
+
+A generator is available for generating the default configuration file into the 'config/initializers' directory.
+Run the following generator command, then edit the generated file.
+ % rails g shareable:config
+
+==To Do:
+- Add Tests.
+- More buttons.
+- More.
+
+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 @@
+<%= output_once :facebook do %>
+<div id="fb-root"></div>
+<script>(function(d, s, id) {
+ var js, fjs = d.getElementsByTagName(s)[0];
+ if (d.getElementById(id)) return;
+ js = d.createElement(s); js.id = id;
+ js.src = "//connect.facebook.net/en_US/all.js#xfbml=1<%= raw('&appId=' + options[:app_id]) unless options[:app_id].empty? %>";
+ fjs.parentNode.insertBefore(js, fjs);
+}(document, 'script', 'facebook-jssdk'));</script>
+<% end %>
+
+<fb:like href='<%= options[:url] %>'
+ send='<%= options[:send] %>'
+ layout='<%= options[:layout] %>'
+ show_faces='<%= options[:show_faces] %>'
+ width='<%= options[:width] %>'
+ action='<%= options[:action] %>'
+ font='<%= options[:font] %>'
+ colorscheme='<%= options[:colorscheme] %>'
+ ref='<%= options[:ref] %>' ></fb:like>
@@ -0,0 +1,21 @@
+<div class='g-plusone gplusshare'
+ data-href='<%= options[:url] %>'
+ data-size='<%= options[:size] %>'
+ data-annotation='<%= options[:annotation] %>'
+ data-width='<%= options[:width] %>'
+ data-align='<%= options[:align] %>'
+ data-expandTo='<%= options[:expand_to] %>'
+ data-callback='<%= options[:callback] %>'
+ data-onstartinteraction='<%= options[:onstartinteraction] %>'
+ data-onendinteraction='<%= options[:onendinteraction] %>'
+ data-recommendations='<%= options[:recommendations] %>'
+></div>
+<%= output_once :google_plus do %>
+<script type="text/javascript">
+ (function() {
+ var po = document.createElement('script'); po.type = 'text/javascript'; po.async = true;
+ po.src = 'https://apis.google.com/js/plusone.js';
+ var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(po, s);
+ })();
+</script>
+<% end %>
@@ -0,0 +1,8 @@
+<script src="//platform.linkedin.com/in.js" type="text/javascript"></script>
+<script type="IN/Share"
+ data-url='<%= options[:url] %>'
+ data-counter='<%= options[:counter] %>'
+ data-onerror='<%= options[:onerror]%>'
+ data-onsuccess='<%= options[:onsuccess]%>'
+ data-showzero='<%= options[:showzero] %>'
+></script>
@@ -0,0 +1,24 @@
+<a data-pin-config='<%= options[:pin_config] %>'
+ 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? %>"
+ data-pin-do='<%= options[:pin_do] %>' >
+ <img src="//assets.pinterest.com/images/pidgets/pin_it_button.png" title='<%= options[:title]%>' alt='<%= options[:alt] %>' /></a>
+
+<%= output_once :pinterest do %>
+<script type="text/javascript">
+ (function (d, buildThese) {
+ var homeScript, newScript, n = buildThese.length, i;
+ for (i = 0; i < n; i = i + 1) {
+ newScript = d.createElement('SCRIPT');
+ newScript.type = 'text/javascript';
+ newScript.async = true;
+ newScript.src = buildThese[i];
+ homeScript = d.getElementsByTagName('SCRIPT')[0];
+ homeScript.parentNode.insertBefore(newScript, homeScript);
+ }
+ }(document, [
+ '//assets.pinterest.com/js/pinit.js'
+ /* load more third-party JavaScript here */
+ ])
+ );
+</script>
+<% end %>
@@ -0,0 +1,11 @@
+<script type="text/javascript">
+ reddit_url='<%= options[:url] %>';
+ reddit_target='<%= options[:target]%>';
+ reddit_title='<%= options[:title] %>';
+ reddit_bgcolor='<%= options[:color] %>';
+ reddit_bordercolor='<%= options[:bordercolor] %>';
+ reddit_newwindow='<%= options[:newwindow] %>';
+</script>
+<script type="text/javascript"
+src="<%= raw((options[:btnsrc].blank? ? ('http://www.reddit.com/static/button/button' + options[:type] + '.js?i=' + options[:points]) : options[:btnsrc]) + '&styled=' + options[:styled]) %>">
+</script>
@@ -0,0 +1,7 @@
+<nav class="share">
+ <%= social_buttons.render do -%>
+ <% each_button do |button| -%>
+ <%= eval button + '_tag' %>
+ <% end -%>
+ <% end -%>
+</nav>
@@ -0,0 +1,21 @@
+<!--script src='http://platform.twitter.com/widgets.js' type='text/javascript'></script> -->
+<a href='http://twitter.com/share'
+ class='twitter-share-button'
+ data-url='<%= options[:url] %>'
+ data-via='<%= options[:via] %>'
+ data-text='<%= options[:text] %>'
+ data-related='<%= options[:related] %>'
+ data-count='<%= options[:count] %>'
+ data-lang='<%= options[:lang] %>'
+ data-counturl='<%= options[:counturl] %>'
+ data-hashtags='<%= options[:hashtags] %>'
+ data-size='<%= options[:size] %>'
+ data-dnt='<%= options[:dnt] %>'>Tweet</a>
+
+<script>!function(d,s,id){
+ var js,fjs=d.getElementsByTagName(s)[0];
+ if(!d.getElementById(id)){
+ js=d.createElement(s);
+ js.id=id;js.src="//platform.twitter.com/widgets.js";
+ fjs.parentNode.insertBefore(js,fjs);}} (document,"script","twitter-wjs");
+</script>
@@ -0,0 +1,16 @@
+module Shareable
+ module Generators
+ class ConfigGenerator < Rails::Generators::Base
+ source_root File.expand_path(File.join(File.dirname(__FILE__), 'templates'))
+
+ desc <<DESC
+Description:
+ Copies Shareable configuration file to your application's initializer directory.
+DESC
+
+ def copy_config_file
+ template 'shareable_config.rb', 'config/initializers/shareable.rb'
+ end
+ end
+ end
+end
@@ -0,0 +1,70 @@
+Shareable.configure do |config|
+ #config.names = %w[ twitter facebook linkedin pinterest google_plus reddit ]
+
+ ##############
+ #facebook
+ ##############
+ #config.app_id=''
+ #config.send= 'false'
+ #config.layout=''
+ #config.show_faces=''
+ #config.width='80'
+ #config.action=''
+ #config.font=''
+ #config.colorscheme=''
+ #config.ref=''
+
+ ##############
+ #google_plus
+ ##############
+ #config.annotation='bubble'
+ #config.align=''
+ #config.expand_to=''
+ #config.callback=''
+ #config.onstartinteraction=''
+ #config.onendinteraction=''
+ #config.recommendations='false'
+
+ ##############
+ #linkedin
+ ##############
+ #config.counter = 'right'
+ #config.onsuccess = ''
+ #config.onerror = ''
+ #config.showzero = 'true'
+
+ ##############
+ #pinterest
+ ##############
+ #config.pin_config = 'none'
+ #config.pin_do = 'buttonPin'
+ #config.title= '' # title for content, also used by reddit button
+ #config.alt='' # alternate text for image tag
+ #config.media=''
+ #config.description='Pin This'
+
+ ##############
+ #reddit
+ ##############
+ #config.target=''
+ #config.color=''
+ #config.bordercolor=''
+ #config.styled='off'
+ #config.newwindow='1'
+ #config.btnsrc='' # alternate reddit button url, eg: 'http://www.reddit.com/buttonlite.js?i=1'
+ #config.type= '1' # button type, eg: 1 to n
+ #config.points = '1' # points style, eg: 0 to 5
+
+ ##############
+ #twitter
+ ##############
+ #config.via='tweetbutton'
+ #config.text=''
+ #config.related=''
+ #config.count='horizontal'
+ #config.lang='en'
+ #config.counturl=''
+ #config.hashtags=''
+ #config.size='medium'
+ #config.dnt=''
+end
@@ -0,0 +1,27 @@
+module Shareable
+end
+
+# load Rails/Railtie
+begin
+ require 'rails'
+rescue LoadError
+ #do nothing
+end
+
+$stderr.puts <<-EOC if !defined?(Rails)
+warning: no rails framework detected.
+
+Your Gemfile might not be configured properly.
+---- e.g. ----
+Rails:
+ gem 'shareable'
+EOC
+
+require 'shareable/config'
+require 'shareable/helpers/action_view_extension'
+require 'shareable/helpers/social_buttons'
+require 'shareable/hooks'
+if defined? Rails
+ require 'shareable/railtie'
+ require 'shareable/engine'
+end
Oops, something went wrong.

0 comments on commit d817070

Please sign in to comment.