flakey 0.0.2 → 0.0.3
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/README.md +2 -2
- data/lib/flakey/configuration.rb +16 -12
- data/lib/flakey/facebook.rb +1 -1
- data/lib/flakey/github.rb +1 -1
- data/lib/flakey/stackoverflow.rb +2 -2
- data/lib/flakey/twitter.rb +50 -30
- data/lib/flakey/version.rb +1 -1
- data/spec/flakey/twitter_spec.rb +36 -0
- data/spec/spec_helper.rb +1 -1
- metadata +5 -5
data/README.md
CHANGED
data/lib/flakey/configuration.rb
CHANGED
@@ -9,21 +9,25 @@
|
|
9
9
|
|
10
10
|
module Flakey
|
11
11
|
class Configuration
|
12
|
-
attr_accessor :
|
13
|
-
:
|
14
|
-
:
|
15
|
-
:
|
16
|
-
:
|
17
|
-
:
|
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.
|
21
|
-
self.
|
22
|
-
self.
|
23
|
-
self.
|
24
|
-
self.
|
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.
|
28
|
+
self.follow_button_show_count = 'false'
|
29
|
+
|
30
|
+
self.facebook_nickname = ''
|
27
31
|
|
28
32
|
end
|
29
33
|
end
|
data/lib/flakey/facebook.rb
CHANGED
data/lib/flakey/github.rb
CHANGED
data/lib/flakey/stackoverflow.rb
CHANGED
@@ -1,11 +1,11 @@
|
|
1
1
|
module Flakey
|
2
2
|
module Stackoverflow
|
3
3
|
def stackoverflow_nickname(options = {})
|
4
|
-
options[:nickname] || Flakey.configuration.
|
4
|
+
options[:nickname] || Flakey.configuration.stackoverflow_nickname
|
5
5
|
end
|
6
6
|
|
7
7
|
def stackoverflow_profile_url(options = {})
|
8
|
-
user_id = Flakey.configuration.
|
8
|
+
user_id = Flakey.configuration.stackoverflow_user_id
|
9
9
|
"http://stackoverflow.com/users/#{user_id}/#{stackoverflow_nickname}"
|
10
10
|
end
|
11
11
|
end
|
data/lib/flakey/twitter.rb
CHANGED
@@ -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.
|
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
|
-
#
|
31
|
+
# twitter_profile_url
|
26
32
|
# # => "https://twitter.com/default
|
27
33
|
#
|
28
|
-
#
|
34
|
+
# twitter_profile_url('peter')
|
29
35
|
# # => "https://twitter.com/peter"
|
30
36
|
#
|
31
37
|
# Returns a string.
|
32
|
-
def
|
38
|
+
def twitter_profile_url(handle = nil)
|
33
39
|
handle = handle || twitter_handle
|
34
|
-
"
|
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
|
-
#
|
45
|
-
# [+
|
46
|
-
# [+
|
47
|
-
# [+
|
48
|
-
#
|
49
|
-
# [+
|
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.
|
62
|
-
label = options[:label] ||
|
62
|
+
Flakey.configuration.tweet_hashtags
|
63
|
+
label = options[:label] ||
|
64
|
+
Flakey.configuration.tweet_label
|
63
65
|
via = options[:via] ||
|
64
|
-
Flakey.configuration.
|
66
|
+
Flakey.configuration.tweet_via
|
65
67
|
related = options[:related] ||
|
66
|
-
Flakey.configuration.
|
68
|
+
Flakey.configuration.tweet_related
|
67
69
|
size = options[:size] ||
|
68
|
-
Flakey.configuration.
|
70
|
+
Flakey.configuration.tweet_button_size
|
69
71
|
class_list = options[:class] ||
|
70
|
-
Flakey.configuration.
|
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,
|
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
|
89
|
-
size = options[:size] ||
|
90
|
-
|
91
|
-
|
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,
|
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
|
data/lib/flakey/version.rb
CHANGED
data/spec/flakey/twitter_spec.rb
CHANGED
@@ -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
|
data/spec/spec_helper.rb
CHANGED
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.
|
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: &
|
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: *
|
24
|
+
version_requirements: *70339194043700
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: rake
|
27
|
-
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: *
|
35
|
+
version_requirements: *70339194043140
|
36
36
|
description: Social helpers for Rails apps.
|
37
37
|
email:
|
38
38
|
- dtuite@gmail.com
|