forked from twitpay/tweet-button
/
tweet.rb
50 lines (41 loc) · 1.17 KB
/
tweet.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
50
module SocialButtons
module Tweet
include SocialButtons::Assistant
TWITTER_SHARE_URL = "http://twitter.com/share"
CLASS = "twitter-share-button"
def tweet_button(options = {})
clazz = SocialButtons::Tweet
# JUNK Code! Refactor!!!!
params = {}
params.merge!(url: request.url)
opt_params = clazz.default_options.merge(options)
params = clazz.options_to_data_params(opt_params)
params.merge!(:class => CLASS)
html = "".html_safe
html << clazz::Scripter.new(self).script
html << link_to("Tweet", TWITTER_SHARE_URL, params)
html
end
class << self
def default_options
@default_options ||= {
via: "tweetbutton",
text: "",
count: "vertical",
lang: "en",
related: ""
}
end
end
class Scripter < SocialButtons::Scripter
def script
return empty_content if widgetized? :tweet
widgetized! :tweet
"<script src=#{twitter_wjs} type='text/javascript'></script>".html_safe
end
def twitter_wjs
"https://platform.twitter.com/widgets.js"
end
end # class
end
end