Module: Octopress::Social::Twitter
Defined Under Namespace
Constant Summary collapse
- DEFAULTS =
{ 'tweet_message' => ":title by :username :hashtags - :url", 'size' => 'normal', 'tweet_count' => false, 'follow_count' => false, 'tweet_link_text' => "Twitter", 'tweet_link_title' => "Share on Twitter", 'profile_link_text' => "Follow :username", 'profile_link_title' => "Follow :username on Twitter", }
Instance Attribute Summary collapse
-
#config ⇒ Object
Returns the value of attribute config.
-
#url ⇒ Object
Returns the value of attribute url.
Instance Method Summary collapse
- #button_message(site, item) ⇒ Object
- #hashtags(item) ⇒ Object
- #message(site, item) ⇒ Object
- #profile_link_text ⇒ Object
- #profile_link_title(item = {}) ⇒ Object
- #set_config(site) ⇒ Object
- #set_url(site, item) ⇒ Object
- #tweet(site, item, url, content) ⇒ 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 Attribute Details
#config ⇒ Object
Returns the value of attribute config.
7 8 9 |
# File 'lib/octopress-social/twitter.rb', line 7 def config @config end |
#url ⇒ Object
Returns the value of attribute url.
7 8 9 |
# File 'lib/octopress-social/twitter.rb', line 7 def url @url end |
Instance Method Details
#button_message(site, item) ⇒ Object
77 78 79 |
# File 'lib/octopress-social/twitter.rb', line 77 def (site, item) %Q{data-text="#{(site, item).sub(/\s?#{url}/, '')}"} end |
#hashtags(item) ⇒ Object
57 58 59 60 61 |
# File 'lib/octopress-social/twitter.rb', line 57 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
67 68 69 70 71 72 73 74 75 |
# File 'lib/octopress-social/twitter.rb', line 67 def (site, item) username_var = (username(item).empty? ? 'by :username' : ':username') (item['tweet_message'] || config['tweet_message']) .sub(':title', item['title'] || '') .sub(username_var, username(item)) .sub(':url', url) .sub(':hashtags', (item)) .strip end |
#profile_link_text ⇒ Object
81 82 83 |
# File 'lib/octopress-social/twitter.rb', line 81 def profile_link_text config['profile_link_text'].sub(':username', username) end |
#profile_link_title(item = {}) ⇒ Object
63 64 65 |
# File 'lib/octopress-social/twitter.rb', line 63 def profile_link_title(item={}) config['profile_link_title'].sub(':username', username) end |
#set_config(site) ⇒ Object
20 21 22 23 24 25 |
# File 'lib/octopress-social/twitter.rb', line 20 def set_config(site) @config ||= begin config = site['octopress_social'] || site DEFAULTS.merge(config['twitter'] || {}) end end |
#set_url(site, item) ⇒ Object
27 28 29 |
# File 'lib/octopress-social/twitter.rb', line 27 def set_url(site, item) @url = Social.full_url(site, item) end |
#tweet(site, item, url, content) ⇒ Object
103 104 105 106 107 108 109 110 111 112 |
# File 'lib/octopress-social/twitter.rb', line 103 def tweet(site, item, url, content) user = "@#{url.match(/.com\/(.+)?\/status/)[1]}" %Q{<blockquote class="twitter-tweet" data-link-color="#{config['embedded_link_color']}" lang="#{item['lang'] || site['lang']}"> <p>#{content}</p> <a href="#{url}"> — #{user}</a> </blockquote> } end |
#tweet_button(site, item) ⇒ Object
38 39 40 41 42 43 44 45 46 47 |
# File 'lib/octopress-social/twitter.rb', line 38 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']} data-url="#{url}" #{(site, item)} data-dnt="true">#{config['tweet_link_text']}</a> } end |
#tweet_link(site, item) ⇒ Object
31 32 33 34 35 36 |
# File 'lib/octopress-social/twitter.rb', line 31 def tweet_link(site, item) %Q{<a class="twitter-share-link" href="https://twitter.com/intent/tweet?&text=#{ERB::Util.url_encode((site, item)).strip}" title="#{config['tweet_link_title']}">#{config['tweet_link_text']}</a>} end |
#twitter_follow_button(*args) ⇒ Object
92 93 94 95 96 97 |
# File 'lib/octopress-social/twitter.rb', line 92 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
85 86 87 88 89 90 |
# File 'lib/octopress-social/twitter.rb', line 85 def twitter_profile_link(*args) %Q{<a class="twitter-profile-link" href="https://twitter.com/#{username.sub('@', '')}" title="#{profile_link_title}">#{profile_link_text}</a>} end |
#twitter_script_tag(*args) ⇒ Object
99 100 101 |
# File 'lib/octopress-social/twitter.rb', line 99 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
49 50 51 52 53 54 55 |
# File 'lib/octopress-social/twitter.rb', line 49 def username(item={}) if username = item['twitter_username'] || config['username'] "@#{username.sub('@', '')}" # ensure @ mark, but not two. else '' end end |