Permalink
Browse files

bump version

  • Loading branch information...
1 parent d8cadec commit bd7831e302f31c763cf852874ca071a2efb7c583 @kristianmandrup kristianmandrup committed Aug 25, 2012
View
@@ -2,6 +2,10 @@ source "http://rubygems.org"
gem 'rails', '>= 3.0.0'
+group :test do
+ gem 'hashie', '~> 1.2.0'
+end
+
group :development do
gem "rspec", ">= 2.8.0"
gem "rdoc", ">= 3.12"
View
@@ -33,6 +33,7 @@ GEM
diff-lcs (1.1.3)
erubis (2.7.0)
git (1.2.5)
+ hashie (1.2.0)
hike (1.2.1)
i18n (0.6.0)
jeweler (1.8.4)
@@ -102,6 +103,7 @@ PLATFORMS
DEPENDENCIES
bundler (>= 1.0.0)
+ hashie (~> 1.2.0)
jeweler (~> 1.8.4)
rails (>= 3.0.0)
rdoc (>= 3.12)
View
@@ -27,6 +27,7 @@ This gem includes the following view helper modules in `social_buttons/view_help
* `Tweet`
* `Like`
* `Pinit`
+* `GooglePlus`
Using SocialButtons is as simple as adding a single method call to your views:
@@ -35,6 +36,7 @@ ERB example:
<%= tweet_button %>
<%= like_button(app_id) %>
<%= pinit_button %>
+<%= google_plus_button %>
```
HAML example:
@@ -43,9 +45,10 @@ HAML example:
= tweet_button
= like_button(app_id)
= pinit_button
+= google_plus_button
```
-Bam. Done. You'll have a sweet lookin' Social Buttons all up in your view.
+Bam. Done. You'll have a sweet lookin' Social Buttons all up in your view.
Of course, you can customize it. Depending on the type of button, there are different options.
@@ -102,6 +105,15 @@ So, a simple pinit button can be added like this:
<%= pinit_button(url: request.url, media: @picture.image.url, description: "Amazing Picture") %>
```
+### Google Plus Button
+
+* `:href` - The URL to share; the default is the current URL.
+* `:size` - Size of button: 'small', 'tall' or 'medium'
+* `:annotation` - The style of button: 'inline', 'bubble', 'none'
+* `:lang` - The locale, fx 'es' for Spanish
+
+See [Google+ button](http://www.google.com/intl/en/webmasters/+1/button/index.html) for more info.
+
### Setting universal defaults
You can set a new default for any option in your `social_buttons.rb` initializer (in `config/initializers`.
View
@@ -1 +1 @@
-0.3.0
+0.3.5
@@ -1,6 +1,6 @@
module SocialButtons
def self.names
- %w{pinit tweet like}
+ %w{pinit tweet like google_plus}
end
def self.config name = nil, &block
@@ -17,9 +17,5 @@ def self.config name = nil, &block
end
end
-SocialButtons.names.each do |name|
- require "social_buttons/view_helpers/#{name}"
-end
-
require "social_buttons/view_helper"
require "social_buttons/engine" if defined?(::Rails::Engine)
@@ -1,5 +1,13 @@
module SocialButtons
+ # autoload :Assistant, 'social_buttons/view_helpers/assistant'
+
+ [SocialButtons.names << :assistant].flatten.each do |name|
+ autoload name.to_s.camelize.to_sym, "social_buttons/view_helpers/#{name}"
+ end
+
module ViewHelper
+ # Include all Social Buttons into ViewHelper to be made available
+ # to be included into a View as one module (see engine)
SocialButtons.names.each do |name|
self.send :include, "SocialButtons::#{name.to_s.camelize}".constantize
end
@@ -0,0 +1,42 @@
+module SocialButtons
+ module Assistant
+ extend ActiveSupport::Concern
+
+ module ClassMethods
+ attr_reader :widgetized
+ attr_writer :default_options
+ alias_method :widgetized?, :widgetized
+
+ def myname
+ self.name.demodulize
+ end
+
+ def help
+ "Please HELP by filling in the help of the #{myname} button :) (see google+ button code)"
+ end
+
+ def options_to_data_params(opts)
+ params = {}
+ opts.each {|k, v| params["data-#{k}"] = v}
+ params
+ end
+
+ def options_to_query_string(subject, opts)
+ # formulate the url, and then strip the part before first '?'
+ query_params = opts.slice(:url, :media, :description)
+ full_url = subject.url_for(query_params)
+ full_url.sub(/^([^?]*)/, '')
+ end
+
+ protected
+
+ def help_note
+ "Note: SocialButons will ensure that the button script is only rendered once!"
+ end
+
+ def empty_content
+ "".html_safe
+ end
+ end
+ end
+end
@@ -0,0 +1,73 @@
+module SocialButtons
+ module GooglePlus
+ include SocialButtons::Assistant
+
+ autoload :Help, "social_buttons/view_helpers/google_plus/help"
+
+ CLASS = "g-plusone"
+
+ # http://www.google.com/intl/en/webmasters/+1/button/index.html
+
+ # Async script mode:
+ # To only output script
+ # = google_button :script, lang: 'es'
+
+ # To NOT output script
+ # = google_button :lang => 'es', script: false
+ def google_plus_button *args
+ options = args.extract_options!
+ clazz = SocialButtons::GooglePlus
+ return clazz.script(options) if args.first == :script
+
+ params = clazz.options_to_data_params(clazz.default_options.merge(options))
+ params.merge!(class: CLASS)
+
+ script_context = options[:script] == :async ? clazz::Async : clazz
+
+ html = "".html_safe
+ html << content_tag(:div, params)
+ html << script_context.script(options[:lang]) if options[:script]
+ html
+ end
+
+ class << self
+ include Help
+
+ def default_options
+ @default_options ||= {
+ annotations: "inline"
+ }
+ end
+
+ module Async
+ # Place this tag in your head or just before your close body tag
+ def script lang = nil
+ %Q{<script type="text/javascript" src="https://apis.google.com/js/plusone.js">
+ #{language lang}
+ </script>}
+ end
+
+ def language lang = nil
+ "{lang: '#{lang}'}" if lang
+ end
+ end
+
+ def script lang = nil
+ return empty_content if widgetized?
+ @widgetized = true
+ %q{<script type="text/javascript">
+ #{language lang}
+ (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>}.html_safe
+ end
+
+ def language lang = nil
+ "window.___gcfg = {lang: '#{lang}'};" if lang
+ end
+ end
+ end
+end
@@ -0,0 +1,42 @@
+module SocialButtons
+ module GooglePlus
+ module Help
+ # Usage
+ # SocialButtons::Google.help
+ #
+ # SocialButtons.config(:google).help
+ def help
+ %Q{Google+ button (options)
+#{Help.show_data_attributes}
+#{Help.other_options}
+#{Help.async_help}
+#{help_note}
+}
+ end
+
+ module Help
+ def show_data_attributes
+ "'data-' attributes: #{data_attributes.inspect}"
+ end
+
+ def other_options
+ "options: lang"
+ end
+
+ def data_attributes
+ %w{size href annotation}
+ end
+
+ def async_help
+%q{Async script mode:
+ To only output script
+ = google_button :script, lang: 'es'
+
+ To NOT output script tag
+ = google_button :lang => 'es', script: false
+}
+ end
+ end
+ end
+ end
+end
@@ -1,43 +1,43 @@
module SocialButtons
module Like
+ include SocialButtons::Assistant
+
+ CLASS = "fb-like"
+
def like_button(app_id, options = {})
- params = options_to_data_params(default_options.merge(options))
- params.merge!(class: "fb-like")
+ clazz = SocialButtons::Like
+ params = clazz.options_to_data_params(clazz.default_options.merge(options))
+ params.merge!(class: CLASS)
html = "".html_safe
html << content_tag(:div, nil, id: "fb-root")
- html << like_widgets_js_tag(app_id) unless @like_widgetized
+ html << clazz.script(app_id)
html << content_tag(:div, nil, params)
+ html
end
+ # To avoid polluting namespace where module is included with util functions!
class << self
- attr_accessor :default_options
- end
-
- def default_options
- options = {
- send: "false",
- layout: "button_count",
- width: "450",
- action: "like",
- font: "arial",
- colorscheme: "light"
- }.merge("show-faces" => "false")
+ def default_options
+ @default_options ||= {
+ send: "false",
+ layout: "button_count",
+ width: "450",
+ action: "like",
+ font: "arial",
+ colorscheme: "light"
+ }.merge("show-faces" => "false")
+ end
- options.merge(SocialButtons::Like.default_options || {})
- end
-
- def like_widgets_js_tag(app_id)
- @like_widgetized = true
-
- js_sdk = "https://connect.facebook.net/en_US/all.js#xfbml=1&appId=#{app_id}"
- "<script src=#{js_sdk} type='text/javascript'></script>".html_safe
- end
+ def script(app_id)
+ return empty_content if widgetized?
+ @widgetized = true
+ "<script src=#{js_sdk(app_id)} type='text/javascript'></script>".html_safe
+ end
- def options_to_data_params(opts)
- params = {}
- opts.each {|k, v| params["data-#{k}"] = v}
- params
+ def js_sdk app_id
+ "https://connect.facebook.net/en_US/all.js#xfbml=1&appId=#{app_id}"
+ end
end
end
end
Oops, something went wrong.

0 comments on commit bd7831e

Please sign in to comment.