flakey 0.0.2 → 0.0.3

Sign up to get free protection for your applications and to get access to all the features.
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
- # Flakey
1
+ # Flakey [![Build Status](https://secure.travis-ci.org/dtuite/flakey.png?branch=master)](http://travis-ci.org/dtuite/flakey)
2
2
 
3
- TODO: Write a gem description
3
+ Social button helpers for your Rails 3.1 projects.
4
4
 
5
5
  ## Installation
6
6
 
@@ -9,21 +9,25 @@
9
9
 
10
10
  module Flakey
11
11
  class Configuration
12
- attr_accessor :default_twitter_handle, :default_tweet_hashtags,
13
- :default_tweet_via, :default_tweet_related,
14
- :default_tweet_button_size, :default_tweet_button_class,
15
- :default_facebook_nickname, :facebook_app_id,
16
- :default_stackoverflow_nickname, :default_stackoverflow_user_id,
17
- :default_github_name, :plus_one_button_language
12
+ attr_accessor :twitter_handle, :tweet_hashtags,
13
+ :tweet_via, :tweet_related,
14
+ :tweet_button_size, :tweet_button_class,
15
+ :tweet_label, :follow_button_size,
16
+ :follow_button_class, :follow_button_show_count,
17
+ :facebook_nickname, :facebook_app_id,
18
+ :stackoverflow_nickname, :stackoverflow_user_id,
19
+ :github_name, :plus_one_button_language
18
20
 
19
21
  def initialize
20
- self.default_twitter_handle = ''
21
- self.default_tweet_hashtags = ''
22
- self.default_tweet_via = ''
23
- self.default_tweet_related = ''
24
- self.default_tweet_button_class = "twitter-share-button"
22
+ self.twitter_handle = ''
23
+ self.tweet_hashtags = ''
24
+ self.tweet_via = ''
25
+ self.tweet_related = ''
26
+ self.tweet_label = 'Tweet'
25
27
 
26
- self.default_facebook_nickname = ''
28
+ self.follow_button_show_count = 'false'
29
+
30
+ self.facebook_nickname = ''
27
31
 
28
32
  end
29
33
  end
@@ -2,7 +2,7 @@ module Flakey
2
2
  module Facebook
3
3
  def facebook_nickname(options = {})
4
4
  options[:nickname] ||
5
- Flakey.configuration.default_facebook_nickname
5
+ Flakey.configuration.facebook_nickname
6
6
  end
7
7
 
8
8
  def facebook_url(options = {})
@@ -1,7 +1,7 @@
1
1
  module Flakey
2
2
  module Github
3
3
  def github_name(options = {})
4
- options[:name] || Flakey.configuration.default_github_name
4
+ options[:name] || Flakey.configuration.github_name
5
5
  end
6
6
 
7
7
  def github_url(options = {})
@@ -1,11 +1,11 @@
1
1
  module Flakey
2
2
  module Stackoverflow
3
3
  def stackoverflow_nickname(options = {})
4
- options[:nickname] || Flakey.configuration.default_stackoverflow_nickname
4
+ options[:nickname] || Flakey.configuration.stackoverflow_nickname
5
5
  end
6
6
 
7
7
  def stackoverflow_profile_url(options = {})
8
- user_id = Flakey.configuration.default_stackoverflow_user_id
8
+ user_id = Flakey.configuration.stackoverflow_user_id
9
9
  "http://stackoverflow.com/users/#{user_id}/#{stackoverflow_nickname}"
10
10
  end
11
11
  end
@@ -3,6 +3,12 @@
3
3
 
4
4
  module Flakey
5
5
  module Twitter
6
+ BASE_URL = "https://twitter.com"
7
+ SHARE_URL = BASE_URL + "/share"
8
+
9
+ # Default HTML classes for the various buttons.
10
+ TWEET_BUTTON_CLASS = 'twitter-tweet-button'
11
+ FOLLOW_BUTTON_CLASS = 'twitter-follow-button'
6
12
 
7
13
  # Get the default Twitter handle for this configuration. If a
8
14
  # handle argument is supplied, it will be returned.
@@ -15,23 +21,23 @@ module Flakey
15
21
  #
16
22
  # Returns a string.
17
23
  def twitter_handle(handle = nil)
18
- handle || Flakey.configuration.default_twitter_handle
24
+ handle || Flakey.configuration.twitter_handle
19
25
  end
20
26
 
21
27
  # Get the Twitter profile URL for a handle. If no handle is
22
28
  # specified then this method returns the profile URL of the
23
29
  # default handle.
24
30
  #
25
- # twitter_url
31
+ # twitter_profile_url
26
32
  # # => "https://twitter.com/default
27
33
  #
28
- # twitter_url('peter')
34
+ # twitter_profile_url('peter')
29
35
  # # => "https://twitter.com/peter"
30
36
  #
31
37
  # Returns a string.
32
- def twitter_url(handle = nil)
38
+ def twitter_profile_url(handle = nil)
33
39
  handle = handle || twitter_handle
34
- "https://twitter.com/#{handle}"
40
+ BASE_URL + "/#{handle}"
35
41
  end
36
42
 
37
43
  # Generate a tweet button. This method needs the Twitter JavaScript
@@ -40,34 +46,30 @@ module Flakey
40
46
  # Takes a hash of options to use when generating the button.
41
47
  #
42
48
  # [+url+] The URL to tweet. Default to the current request url.
43
- # [+text+] The textual body of the Tweet. Defaults to the current
44
- # page title. This is a Twitter convention.
45
- # [+hashtags+] A list of hashtags to include in the tweet.
46
- # [+label+] The text to appear on the tweet button.
47
- # [+via+] Tweet via an associated abbout. Defaults to the
48
- # +default_tweet_via+ configuration setting.
49
- # [+related+] A related Twitter handle. Defaults to the
50
- # +default_tweet_related+ configuration setting.
51
- # [+class+] HTML classes to apply to the Tweet button. Defaults
52
- # to the +default_tweet_button_class+ configuration setting which
53
- # is <i>"twitter-share-button"</i>.
54
- # [+size+]
49
+ # [+text+] The textual body of the Tweet. Defaults to the current page title. This is a Twitter convention.
50
+ # [+hashtags+] A list of hashtags to include in the tweet. Can be globally configured by setting +tweet_hashtags+.
51
+ # [+label+] The text to appear on the tweet button. Can be configured by setting +tweet_label+.
52
+ # [+via+] Tweet via an associated about. Defaults to the +tweet_via+ configuration setting.
53
+ # [+related+] A related Twitter handle. Defaults to the +tweet_related+ configuration setting.
54
+ # [+class+] HTML classes to apply to the Tweet button. Defaults to the +tweet_button_class+ configuration setting which is <i>"twitter-share-button"</i>.
55
+ # [+size+] The size of the button. Valid options are <i>nil</i> (default) and </i>'large'</i>.
55
56
  #
56
57
  # Returns a HTML string.
57
58
  def tweet_button(options = {})
58
59
  url = options[:url] || request.url
59
60
  text = options[:text]
60
61
  hashtags = options[:hashtags] ||
61
- Flakey.configuration.default_tweet_hashtags
62
- label = options[:label] || 'Tweet'
62
+ Flakey.configuration.tweet_hashtags
63
+ label = options[:label] ||
64
+ Flakey.configuration.tweet_label
63
65
  via = options[:via] ||
64
- Flakey.configuration.default_tweet_via
66
+ Flakey.configuration.tweet_via
65
67
  related = options[:related] ||
66
- Flakey.configuration.default_tweet_related
68
+ Flakey.configuration.tweet_related
67
69
  size = options[:size] ||
68
- Flakey.configuration.default_tweet_button_size
70
+ Flakey.configuration.tweet_button_size
69
71
  class_list = options[:class] ||
70
- Flakey.configuration.default_tweet_button_class
72
+ Flakey.configuration.tweet_button_class
71
73
 
72
74
  data_attr = {
73
75
  :via => via,
@@ -78,19 +80,37 @@ module Flakey
78
80
  # Twitter will take the page title if we just leave it out.
79
81
  data_attr.merge!(text: text) unless text.nil?
80
82
  data_attr.merge!(size: size) unless size.nil?
83
+ class_list = class_list ?
84
+ class_list.concat(' ' + TWEET_BUTTON_CLASS) : TWEET_BUTTON_CLASS
81
85
 
82
- link_to label, "https://twitter.com/share",
83
- :class => class_list, :data => data_attr
86
+ link_to label, SHARE_URL, :class => class_list, :data => data_attr
84
87
  end
85
88
 
89
+ # Generate a follow button. This method needs the Twitter JavaScript
90
+ # to be loaded on the page in order to work correctly.
91
+ #
92
+ # Takes a hash of options to use when generating the button.
93
+ #
94
+ # [+handle+] The Twitter handle of the user to follow. Defaults to the +twitter_handle+ configuration.
95
+ # [+size+] The button size. Can be +nil+ or +'large'+. Configure globally with +follow_button_size+.
96
+ # [+class_list+] HTML classes to apply to the button. Configure globally with +follow_button_class+.
97
+ # [+show_count+] Show the follow count. Defaults to false. Configure globally with +follow_button_show_count+.
98
+ #
99
+ # Returns a HTML string.
86
100
  def follow_button(options = {})
87
101
  handle = options[:handle] || twitter_handle
88
- label = options[:label] || "Follow #{handle}"
89
- size = options[:size] || 'large'
90
- class_list = options[:class] || "twitter-follow-button"
91
- show_count = options[:show_count] || "false"
102
+ label = options[:label] || "Follow @#{handle}"
103
+ size = options[:size] ||
104
+ Flakey.configuration.follow_button_size
105
+ class_list = options[:class] ||
106
+ Flakey.configuration.follow_button_class
107
+ show_count = options[:show_count] ||
108
+ Flakey.configuration.follow_button_show_count
109
+
110
+ class_list = class_list ?
111
+ class_list.concat(' ' + FOLLOW_BUTTON_CLASS) : FOLLOW_BUTTON_CLASS
92
112
 
93
- link_to label, "https://twitter.com/#{handle}",
113
+ link_to label, twitter_profile_url(handle),
94
114
  class: class_list, data: { :"show-count" => show_count, size: size }
95
115
  end
96
116
  end
@@ -1,3 +1,3 @@
1
1
  module Flakey
2
- VERSION = "0.0.2"
2
+ VERSION = "0.0.3"
3
3
  end
@@ -16,4 +16,40 @@ describe Flakey::Twitter do
16
16
  subject.twitter_handle('hello').should == 'hello'
17
17
  end
18
18
  end
19
+
20
+ describe "tweet_button" do
21
+ before { subject.stub_chain('request.url') { '' } }
22
+
23
+ it "should append to the class list" do
24
+ subject.should_receive(:link_to)
25
+ .with("Tweet", Flakey::Twitter::SHARE_URL,
26
+ hash_including(class: 'hello twitter-tweet-button'))
27
+ subject.tweet_button(class: 'hello')
28
+ end
29
+
30
+ it "should work without a class argument" do
31
+ subject.should_receive(:link_to)
32
+ .with("Tweet", Flakey::Twitter::SHARE_URL,
33
+ hash_including(class: 'twitter-tweet-button'))
34
+ subject.tweet_button
35
+ end
36
+ end
37
+
38
+ describe "follow_button" do
39
+ before { subject.stub_chain('request.url') { '' } }
40
+
41
+ it "should append to the class list" do
42
+ subject.should_receive(:link_to)
43
+ .with("Follow @david", subject.twitter_profile_url('david'),
44
+ hash_including(class: 'hello twitter-follow-button'))
45
+ subject.follow_button(handle: 'david', class: 'hello')
46
+ end
47
+
48
+ it "should work without a class argument" do
49
+ subject.should_receive(:link_to)
50
+ .with("Follow @david", subject.twitter_profile_url('david'),
51
+ hash_including(class: 'twitter-follow-button'))
52
+ subject.follow_button(handle: 'david')
53
+ end
54
+ end
19
55
  end
@@ -6,5 +6,5 @@ require "flakey/google_plus"
6
6
  require "flakey/stackoverflow"
7
7
 
8
8
  Flakey.configure do |c|
9
- c.default_twitter_handle = 'grinnick'
9
+ c.twitter_handle = 'grinnick'
10
10
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flakey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.2
4
+ version: 0.0.3
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -13,7 +13,7 @@ date: 2012-07-30 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rspec
16
- requirement: &70265412068800 !ruby/object:Gem::Requirement
16
+ requirement: &70339194043700 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *70265412068800
24
+ version_requirements: *70339194043700
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: rake
27
- requirement: &70265412068380 !ruby/object:Gem::Requirement
27
+ requirement: &70339194043140 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,7 +32,7 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *70265412068380
35
+ version_requirements: *70339194043140
36
36
  description: Social helpers for Rails apps.
37
37
  email:
38
38
  - dtuite@gmail.com