Module: TweetButton
- Defined in:
- lib/tweet-button.rb
Constant Summary collapse
- TWITTER_SHARE_URL =
"http://twitter.com/share"
Class Attribute Summary collapse
-
.default_tweet_button_options ⇒ Object
Returns the value of attribute default_tweet_button_options.
Instance Method Summary collapse
- #custom_tweet_button(text = 'Tweet', options = {}, html_options = {}) ⇒ Object
- #default_tweet_button_options ⇒ Object
- #options_to_data_params(opts) ⇒ Object
-
#options_to_query_string(opts) ⇒ Object
I’m pretty sure this is in the stdlib or Rails somewhere.
- #tweet_button(options = {}) ⇒ Object
- #tweet_widgets_js_tag ⇒ Object
Class Attribute Details
.default_tweet_button_options ⇒ Object
Returns the value of attribute default_tweet_button_options.
18 19 20 |
# File 'lib/tweet-button.rb', line 18 def @default_tweet_button_options end |
Instance Method Details
#custom_tweet_button(text = 'Tweet', options = {}, html_options = {}) ⇒ Object
37 38 39 40 |
# File 'lib/tweet-button.rb', line 37 def (text = 'Tweet', = {}, = {}) # This line is really long. And it makes me sad. link_to(text, "#{TWITTER_SHARE_URL}?#{(.merge())}", ) end |
#default_tweet_button_options ⇒ Object
21 22 23 24 25 26 27 28 29 30 |
# File 'lib/tweet-button.rb', line 21 def { :url => request.url, :via => "tweetbutton", :text => "", :related => "", :count => "vertical", :lang => "en" }.merge(TweetButton. || {}) end |
#options_to_data_params(opts) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/tweet-button.rb', line 42 def (opts) params = {} opts.each {|k, v| params["data-#{k}"] = v} # Make sure the CSS class is there params['class'] = 'twitter-share-button' params end |
#options_to_query_string(opts) ⇒ Object
I’m pretty sure this is in the stdlib or Rails somewhere. Too lazy to figure it out now.
52 53 54 |
# File 'lib/tweet-button.rb', line 52 def (opts) opts.map{|k,v| "#{CGI.escape(k.to_s)}=#{CGI.escape(v)}"}.join("&") end |
#tweet_button(options = {}) ⇒ Object
4 5 6 7 8 9 10 11 12 13 14 15 |
# File 'lib/tweet-button.rb', line 4 def ( = {}) # Merge user specified overrides into defaults, then convert those to data-* attrs params = (.merge()) html = ''.html_safe unless @widgetized html << end html << link_to("Tweet", TWITTER_SHARE_URL, params) end |
#tweet_widgets_js_tag ⇒ Object
32 33 34 35 |
# File 'lib/tweet-button.rb', line 32 def @widgetized = true '<script src="http://platform.twitter.com/widgets.js" type="text/javascript"></script>'.html_safe end |