Module: Octopress::Social::Twitter
Defined Under Namespace
Classes: Tag
Constant Summary collapse
- DEFAULTS =
{ 'tweet_message' => ":title by :username - :url :hashtags", 'size' => 'normal', 'tweet_count' => false, 'follow_count' => false, 'tweet_link_text' => "Twitter", 'profile_link_text' => "Follow :username" }
Instance Method Summary collapse
- #button_message(site, item) ⇒ Object
- #config(site = nil) ⇒ Object
- #hashtags(item) ⇒ Object
- #message(site, item) ⇒ Object
- #profile_link_text ⇒ Object
- #tweet_button(site, item) ⇒ Object
- #tweet_link(site, item) ⇒ Object
- #twitter_follow_button(*args) ⇒ Object
- #twitter_profile_link(*args) ⇒ Object
- #twitter_script_tag(*args) ⇒ Object
- #username(item = {}) ⇒ Object
Instance Method Details
#button_message(site, item) ⇒ Object
56 57 58 |
# File 'lib/octopress-social/twitter.rb', line 56 def (site, item) %Q{data-text="#{(site, item)}"} end |
#config(site = nil) ⇒ Object
15 16 17 |
# File 'lib/octopress-social/twitter.rb', line 15 def config(site=nil) @config ||= DEFAULTS.merge(site['twitter'] || {}) end |
#hashtags(item) ⇒ Object
41 42 43 44 45 |
# File 'lib/octopress-social/twitter.rb', line 41 def (item) = Array(item['twitter_hashtag'] || item['twitter_hashtags']) .map{|h| "##{h.sub('#', '')}" } # ensure hash mark, but not two. .join(' ') end |
#message(site, item) ⇒ Object
47 48 49 50 51 52 53 54 |
# File 'lib/octopress-social/twitter.rb', line 47 def (site, item) (item['tweet_message'] || config['tweet_message']) .sub(':title', item['title'] || '') .sub(':username', username(item)) .sub(':url', Social.full_url(site, item)) .sub(':hashtags', (item)) .strip end |
#profile_link_text ⇒ Object
60 61 62 |
# File 'lib/octopress-social/twitter.rb', line 60 def profile_link_text config['profile_link_text'].sub(':username', username) end |
#tweet_button(site, item) ⇒ Object
23 24 25 26 27 28 29 30 31 |
# File 'lib/octopress-social/twitter.rb', line 23 def (site, item) %Q{ <a href="https://twitter.com/share" class="twitter-share-button" #{'data-size="large"' if config['size'] == 'large'} #{'data-count="none"' if !config['tweet_count']} #{(site, item)} data-dnt="true">#{config['tweet_link_text']}</a> } end |
#tweet_link(site, item) ⇒ Object
19 20 21 |
# File 'lib/octopress-social/twitter.rb', line 19 def tweet_link(site, item) %Q{<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=#{(site, item).strip}" target="_blank">#{config['tweet_link_text']}</a>} end |
#twitter_follow_button(*args) ⇒ Object
68 69 70 71 72 73 |
# File 'lib/octopress-social/twitter.rb', line 68 def (*args) %Q{ <a href="https://twitter.com/#{username.sub('@', '')}" class="twitter-follow-button" #{'data-show-count="false"' if !config['follow_count']} data-dnt="true">#{profile_link_text}</a> } end |
#twitter_profile_link(*args) ⇒ Object
64 65 66 |
# File 'lib/octopress-social/twitter.rb', line 64 def twitter_profile_link(*args) %Q{<a href="https://twitter.com/#{username.sub('@', '')}" class="twitter-follow-link">#{profile_link_text}</a>} end |
#twitter_script_tag(*args) ⇒ Object
75 76 77 |
# File 'lib/octopress-social/twitter.rb', line 75 def twitter_script_tag(*args) "<script>!function(d,s,id){var js,fjs=d.getElementsByTagName(s)[0],p=/^http:/.test(d.location)?'http':'https';if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src=p+'://platform.twitter.com/widgets.js';fjs.parentNode.insertBefore(js,fjs);}}(document, 'script', 'twitter-wjs');</script>" end |
#username(item = {}) ⇒ Object
33 34 35 36 37 38 39 |
# File 'lib/octopress-social/twitter.rb', line 33 def username(item={}) if username = item['twitter_username'] || config['username'] "@#{username.sub('@', '')}" # ensure @ mark, but not two. else '' end end |