forked from twitpay/tweet-button
-
Notifications
You must be signed in to change notification settings - Fork 11
/
like.rb
49 lines (43 loc) · 1.4 KB
/
like.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
module SocialButtons
module Like
include SocialButtons::Assistant
CLASS = "fb-like"
def like_button(app_id, options = {})
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 << clazz::Scripter.new(self).script(app_id, options)
html << content_tag(:div, nil, params)
html
end
# To avoid polluting namespace where module is included with util functions!
class << self
def default_options
@default_options ||= {
send: "false",
layout: "button_count",
width: "450",
action: "like",
font: "arial",
colorscheme: "light"
}.merge("show-faces" => "false")
end
end
class Scripter < SocialButtons::Scripter
def script(app_id, options = {})
return empty_content if widgetized? :like
widgetized! :like
[
"<script src=#{js_sdk options} type='text/javascript'></script>",
"<script>FB.init({ appId: '#{app_id}', status: true, cookie: true, xfbml: true });</script>",
].join.html_safe
end
def js_sdk options = {}
loc = options[:locale] || 'en_US'
"https://connect.facebook.net/" + loc + "/all.js"
end
end
end
end