forked from twitpay/tweet-button
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d8cadec
commit bd7831e
Showing
14 changed files
with
293 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
0.3.0 | ||
0.3.5 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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.