flakey 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: e7b5137cf69f93d6138540da2b40499ee8754908
4
+ data.tar.gz: f4ca7aba6b994881a5d784ee53a8e8b0c7c24476
5
+ SHA512:
6
+ metadata.gz: c35db990e4adccc4b7dd83bba42601d9855bafd4bc9ffd2fcab29a4305e987a2458c1d15103d02061b9079a009f013464384601a54e992560608c01cb6672ac2
7
+ data.tar.gz: 9ebdf8fc9ddadb16e42b5d5b381ea4c4351a1cd611462e964aded1049f9f84bc08cd9415a63aa8f954df7db195c1bb68337123a15e0bfe799b1c2edbe6b8b491
data/README.md CHANGED
@@ -22,11 +22,16 @@ Or install it yourself as:
22
22
 
23
23
  # config/initializers/flakey.rb
24
24
  Flakey.configure do |config|
25
+ config.twitter_handle = ''
26
+
25
27
  # Optionally include:
26
- # config.default_twitter_handle = 'dtuite'
27
- # config.default_tweet_hastags = ''
28
- # config.default_tweet_via = ''
29
- # config.default_tweet_related = ''
28
+ config.twitter_user_id = nil
29
+ config.tweet_hashtags = ''
30
+ config.tweet_via = ''
31
+ config.tweet_related = ''
32
+ config.tweet_button_count_position = 'horizontal'
33
+
34
+ config.follow_button_show_count = 'false'
30
35
  end
31
36
 
32
37
  # app/assets/javascrippts/application.js
@@ -45,8 +50,10 @@ Or install it yourself as:
45
50
 
46
51
  # config/initializers/flakey.rb
47
52
  Flakey.configure do |config|
48
- config.facebook_app_id = '<YOUR_APP_ID>'
49
- config.default_facebook_nickname = '<A_FACEBOOK_NICKNAME>'
53
+ self.facebook_nickname = ''
54
+
55
+ # Optionally include:
56
+ config.facebook_app_id = nil
50
57
  end
51
58
 
52
59
  # app/assets/javascrippts/application.js
@@ -65,7 +72,7 @@ Or install it yourself as:
65
72
 
66
73
  # config/initializers/flakey.rb
67
74
  Flakey.configure do |config|
68
- config.default_github_name = 'dtuite'
75
+ config.github_name = 'dtuite'
69
76
  end
70
77
 
71
78
  # app/helpers/application_helper.rb
@@ -80,8 +87,8 @@ Or install it yourself as:
80
87
 
81
88
  # config/initializers/flakey.rb
82
89
  Flakey.configure do |config|
83
- config.default_stackoverflow_nickname = 'david-tuite'
84
- config.default_stackoverflow_user_id = '7389247'
90
+ config.stackoverflow_nickname = 'david-tuite'
91
+ config.stackoverflow_user_id = '7389247'
85
92
  end
86
93
 
87
94
  # app/helpers/application_helper.rb
@@ -97,6 +104,7 @@ Or install it yourself as:
97
104
  # config/initializers/flakey.rb
98
105
  Flakey.configure do |config|
99
106
  config.google_plus_user_id = "9873465784"
107
+
100
108
  # Optionally:
101
109
  # Should be of the form of, for example, 'en-GB' or 'de'.
102
110
  # config.plus_one_button_language = 'en-GB'
data/flakey.gemspec CHANGED
@@ -17,6 +17,9 @@ Gem::Specification.new do |gem|
17
17
 
18
18
  gem.add_dependency 'activesupport'
19
19
 
20
+ # Pretend we're in Rails.
21
+ gem.add_development_dependency 'actionpack'
22
+
20
23
  gem.add_development_dependency 'rspec'
21
24
  gem.add_development_dependency 'rake'
22
25
  end
@@ -10,18 +10,19 @@
10
10
  module Flakey
11
11
  class Configuration
12
12
  attr_accessor :twitter_handle, :tweet_hashtags, :tweet_via, :tweet_related,
13
- :tweet_button_size, :tweet_button_class, :tweet_label,
13
+ :tweet_button_size, :tweet_button_class,
14
14
  :follow_button_size, :follow_button_class, :follow_button_show_count,
15
15
  :facebook_nickname, :facebook_app_id, :stackoverflow_nickname,
16
16
  :stackoverflow_user_id, :github_name, :plus_one_button_language,
17
- :google_plus_user_id
17
+ :google_plus_user_id, :twitter_user_id, :tweet_button_count_position
18
18
 
19
19
  def initialize
20
+ self.twitter_user_id = nil
20
21
  self.twitter_handle = ''
21
22
  self.tweet_hashtags = ''
22
23
  self.tweet_via = ''
23
24
  self.tweet_related = ''
24
- self.tweet_label = 'Tweet'
25
+ self.tweet_button_count_position = 'horizontal'
25
26
 
26
27
  self.follow_button_show_count = 'false'
27
28
 
@@ -1,5 +1,7 @@
1
1
  module Flakey
2
2
  module Facebook
3
+ SHARE_URL = 'https://www.facebook.com/sharer/sharer.php'
4
+
3
5
  def facebook_nickname(options = {})
4
6
  options[:nickname] ||
5
7
  Flakey.configuration.facebook_nickname
@@ -10,6 +12,20 @@ module Flakey
10
12
  "https://www.facebook.com/" + nickname
11
13
  end
12
14
 
15
+ # Generate a traditional tweet button. This method needs the Facebook
16
+ # JavaScript to be loaded on the page to work correctly.
17
+ #
18
+ # Takes a hash of options used to generate the button.
19
+ #
20
+ # [+url+] The URL to like. Default to the current request url.
21
+ # [+layout+] String. The layout of the button.
22
+ # [+width+] Integer. The width of the area taken up by the button.
23
+ # [+send+] Boolean. Include a Send button or not.
24
+ # [+font+] String. The font to use for the button text.
25
+ # [+class_list+] String. Must include 'fb-like' if overwriting.
26
+ # [+show_faces+] Boolean. Whether to show faces or not.
27
+ #
28
+ # Returns a HTML string.
13
29
  def like_button(options = {})
14
30
  url = options[:url] || request.url
15
31
  layout = options[:layout] || 'button_count'
@@ -24,5 +40,16 @@ module Flakey
24
40
  :'show-faces' => show_faces, font: font
25
41
  }
26
42
  end
43
+
44
+ # Generate a Facebook Share button.
45
+ # INFO: http://goo.gl/MvqIi4
46
+ #
47
+ # Returns a HTML string.
48
+ def share_button(options = {})
49
+ label = options[:label] || 'Share'
50
+ url = options[:url] || request.url
51
+
52
+ link_to label, "#{SHARE_URL}?u=#{url}", target: '_blank'
53
+ end
27
54
  end
28
55
  end
@@ -1,9 +1,11 @@
1
+ # encoding: UTF-8
1
2
  require 'active_support/core_ext/hash/except'
2
- # THis class is used to generate standard Twitter buttons as documented
3
+ # This class is used to generate standard Twitter buttons as documented
3
4
  # on the [Twitter developers site](https://twitter.com/about/resources/buttons).
4
5
 
5
6
  module Flakey
6
7
  module Twitter
8
+
7
9
  BASE_URL = "https://twitter.com"
8
10
  SHARE_URL = BASE_URL + "/share"
9
11
 
@@ -11,6 +13,11 @@ module Flakey
11
13
  TWEET_BUTTON_CLASS = 'twitter-share-button'
12
14
  FOLLOW_BUTTON_CLASS = 'twitter-follow-button'
13
15
 
16
+ # Needed to be able to pass a block down into link_to.
17
+ # See the custom_tweet_button method.
18
+ # INFO: http://stackoverflow.com/a/7562194/574190
19
+ attr_accessor :output_buffer
20
+
14
21
  # Get the default Twitter handle for this configuration. If a
15
22
  # handle argument is supplied, it will be returned.
16
23
  #
@@ -49,33 +56,34 @@ module Flakey
49
56
  # [+url+] The URL to tweet. Default to the current request url.
50
57
  # [+text+] The textual body of the Tweet. Defaults to the current page title. This is a Twitter convention.
51
58
  # [+hashtags+] A list of hashtags to include in the tweet. Can be globally configured by setting +tweet_hashtags+.
52
- # [+label+] The text to appear on the tweet button. Can be configured by setting +tweet_label+.
53
59
  # [+via+] Tweet via an associated about. Defaults to the +tweet_via+ configuration setting.
54
60
  # [+related+] A related Twitter handle. Defaults to the +tweet_related+ configuration setting.
55
61
  # [+class+] HTML classes to apply to the Tweet button. Defaults to the +tweet_button_class+ configuration setting which is <i>"twitter-share-button"</i>.
56
62
  # [+size+] The size of the button. Valid options are <i>nil</i> (default) and </i>'large'</i>.
63
+ # [+count+] The position of the Tweet count. Valid options are <i>horizonal</i> (default), <i>vertical</i> and </i>none</i>.
57
64
  #
58
65
  # Returns a HTML string.
59
66
  def tweet_button(options = {})
60
67
  url = options[:url] || request.url
61
- text = options[:text]
68
+ text = options[:text] || ''
62
69
  hashtags = options[:hashtags] || Flakey.configuration.tweet_hashtags
63
- label = options[:label] || Flakey.configuration.tweet_label
64
70
  via = options[:via] || Flakey.configuration.tweet_via
65
71
  related = options[:related] || Flakey.configuration.tweet_related
66
72
  size = options[:size] || Flakey.configuration.tweet_button_size
67
73
  class_list = options[:class] || Flakey.configuration.tweet_button_class
74
+ count = options[:count] || Flakey.configuration.tweet_button_count_position
68
75
 
69
- data_attr = { via: via, related: related, hashtags: hashtags }
76
+ data_attr = { via: via, related: related, hashtags: hashtags,
77
+ count: count }
70
78
  # Twitter will take the page title if we just leave it out.
71
- data_attr.merge!(text: text) unless text.nil?
79
+ data_attr.merge!(text: sanitize(text)) unless text.nil?
72
80
  data_attr.merge!(size: size) unless size.nil?
73
81
  data_attr.merge!(url: url) unless url.nil?
74
82
 
75
83
  class_list = class_list ?
76
84
  class_list.concat(' ' + TWEET_BUTTON_CLASS) : TWEET_BUTTON_CLASS
77
85
 
78
- link_to label, SHARE_URL, :class => class_list, :data => data_attr
86
+ link_to "Tweet", SHARE_URL, class: class_list, data: data_attr
79
87
  end
80
88
 
81
89
  # Generate a traditional follow button. This method needs the Twitter
@@ -109,8 +117,9 @@ module Flakey
109
117
  # Generate a link which will open a dialog for following the user with
110
118
  # whe specified user_id or screen_name.
111
119
  def follow_intent_link(text, options = {})
112
- user_id_to_follow = options[:user_id] || nil
113
- screen_name_to_follow = options[:screen_name] || nil
120
+ user_id_to_follow = options[:user_id] || Flakey.configuration.twitter_user_id
121
+ screen_name_to_follow = options[:screen_name] ||
122
+ Flakey.configuration.twitter_handle
114
123
 
115
124
  intent_url = 'https://twitter.com/intent/user?'
116
125
 
@@ -120,11 +129,43 @@ module Flakey
120
129
 
121
130
  intent_url += '&' if user_id_to_follow && screen_name_to_follow
122
131
 
123
- if screen_name_to_follow
132
+ unless screen_name_to_follow == ''
124
133
  intent_url += "screen_name=#{screen_name_to_follow}"
125
134
  end
126
135
 
127
136
  link_to text, intent_url, options.except(:user_id, :screen_name)
128
137
  end
138
+
139
+ def custom_tweet_button(options = {}, &block)
140
+ defaults = {
141
+ label: 'Tweet',
142
+ url: request.url,
143
+ related: Flakey.configuration.tweet_related,
144
+ hashtags: Flakey.configuration.tweet_hashtags,
145
+ via: Flakey.configuration.tweet_via,
146
+ class: 'custom-tweet-button',
147
+ target: '_blank'
148
+ }
149
+ settings = defaults.merge(options)
150
+ url = "#{SHARE_URL}?url=#{CGI.escape settings[:url]}"
151
+
152
+ label = settings[:label]
153
+ # Delete these so we can pass the settings directly into link_to
154
+ settings.delete(:label)
155
+ settings.delete(:url)
156
+
157
+ %w[text hashtags related via].each do |url_key|
158
+ if settings.has_key?(url_key.to_sym) && settings[url_key.to_sym] != ''
159
+ url += "&#{url_key}=#{CGI.escape settings[url_key.to_sym]}"
160
+ settings.delete(url_key.to_sym)
161
+ end
162
+ end
163
+
164
+ if block_given?
165
+ link_to(url, settings, &block)
166
+ else
167
+ link_to label, url, settings
168
+ end
169
+ end
129
170
  end
130
171
  end
@@ -1,3 +1,3 @@
1
1
  module Flakey
2
- VERSION = "0.1.4"
2
+ VERSION = "0.2.0"
3
3
  end
@@ -1,6 +1,9 @@
1
+ # encoding: UTF-8
1
2
  require "spec_helper"
3
+ require 'action_view'
2
4
 
3
5
  class DummyHelper
6
+ include ::ActionView::Helpers::UrlHelper
4
7
  include Flakey::Twitter
5
8
  end
6
9
 
@@ -52,4 +55,36 @@ describe Flakey::Twitter do
52
55
  subject.follow_button(handle: 'david')
53
56
  end
54
57
  end
58
+
59
+ describe 'custom_tweet_button' do
60
+ before { subject.stub_chain('request.url') { 'http://example.com/hello' } }
61
+ let(:default_url) { "#{Flakey::Twitter::SHARE_URL}?url=http%3A%2F%2Fexample.com%2Fhello" }
62
+
63
+ it 'should include the default url and label' do
64
+ subject.should_receive(:link_to)
65
+ .with('Tweet', default_url, hash_including(target: '_blank'))
66
+ subject.custom_tweet_button
67
+ end
68
+
69
+ it 'should allow specifying the text' do
70
+ expected_url = "#{default_url}&text=Hello+there"
71
+ subject.should_receive(:link_to)
72
+ .with('Tweet', expected_url, anything)
73
+ subject.custom_tweet_button(text: "Hello there")
74
+ end
75
+
76
+ it 'should allow specifying the via' do
77
+ Flakey.configuration.stub(tweet_via: 'hello')
78
+ subject.custom_tweet_button.should =~ /via=hello/
79
+ end
80
+
81
+ it 'should not include blank via' do
82
+ Flakey.configuration.stub(tweet_via: '')
83
+ subject.custom_tweet_button.should_not =~ /&via=/
84
+ end
85
+
86
+ it 'should set a class' do
87
+ subject.custom_tweet_button.should =~ /class="custom-twee/
88
+ end
89
+ end
55
90
  end
@@ -3,7 +3,11 @@
3
3
  var js, fjs = d.getElementsByTagName(s)[0];
4
4
  if (d.getElementById(id)) return;
5
5
  js = d.createElement(s); js.id = id;
6
- js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=<%= Flakey.configuration.facebook_app_id %>";
6
+ <% if Flakey.configuration.facebook_app_id %>
7
+ js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1&appId=<%= Flakey.configuration.facebook_app_id %>";
8
+ <% else %>
9
+ js.src = "//connect.facebook.net/en_GB/all.js#xfbml=1";
10
+ <% end %>
7
11
  fjs.parentNode.insertBefore(js, fjs);
8
12
  }(document, 'script', 'facebook-jssdk'));
9
13
  <% end %>
@@ -0,0 +1,28 @@
1
+ // Used to make Facebook Share dialogs and Custom Tweet dialogs open in a
2
+ // dialog rather than taking the user to a new tab.
3
+
4
+ if (typeof jQuery === "undefined") {
5
+ throw "Flakey popup requires jQuery";
6
+ };
7
+
8
+ (function($) {
9
+ // Function for opening popups.
10
+ var openPopup = function(url, name, options){
11
+ options || (options = {});
12
+
13
+ var width = options.width || 575;
14
+ var height = options.height || 400;
15
+ var left = ($(window).width() - width) / 2;
16
+ var top = ($(window).height() - height) / 2;
17
+ var opts = "status=1,width=" + width + ',height=' + height + ',top=' + top + ',left=' + left;
18
+
19
+ window.open(url, 'twitter', opts)
20
+ };
21
+
22
+ $(function(){
23
+ $('.custom-tweet-button').on('click', function(e){
24
+ e.preventDefault();
25
+ openPopup($(e.target).attr('href'), 'twitter');
26
+ });
27
+ });
28
+ })(jQuery);
metadata CHANGED
@@ -1,62 +1,69 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flakey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
5
- prerelease:
4
+ version: 0.2.0
6
5
  platform: ruby
7
6
  authors:
8
7
  - David Tuite
9
8
  autorequire:
10
9
  bindir: bin
11
10
  cert_chain: []
12
- date: 2013-07-05 00:00:00.000000000 Z
11
+ date: 2013-08-28 00:00:00.000000000 Z
13
12
  dependencies:
14
13
  - !ruby/object:Gem::Dependency
15
14
  name: activesupport
16
15
  requirement: !ruby/object:Gem::Requirement
17
- none: false
18
16
  requirements:
19
- - - ! '>='
17
+ - - '>='
20
18
  - !ruby/object:Gem::Version
21
19
  version: '0'
22
20
  type: :runtime
23
21
  prerelease: false
24
22
  version_requirements: !ruby/object:Gem::Requirement
25
- none: false
26
23
  requirements:
27
- - - ! '>='
24
+ - - '>='
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: actionpack
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - '>='
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - '>='
28
39
  - !ruby/object:Gem::Version
29
40
  version: '0'
30
41
  - !ruby/object:Gem::Dependency
31
42
  name: rspec
32
43
  requirement: !ruby/object:Gem::Requirement
33
- none: false
34
44
  requirements:
35
- - - ! '>='
45
+ - - '>='
36
46
  - !ruby/object:Gem::Version
37
47
  version: '0'
38
48
  type: :development
39
49
  prerelease: false
40
50
  version_requirements: !ruby/object:Gem::Requirement
41
- none: false
42
51
  requirements:
43
- - - ! '>='
52
+ - - '>='
44
53
  - !ruby/object:Gem::Version
45
54
  version: '0'
46
55
  - !ruby/object:Gem::Dependency
47
56
  name: rake
48
57
  requirement: !ruby/object:Gem::Requirement
49
- none: false
50
58
  requirements:
51
- - - ! '>='
59
+ - - '>='
52
60
  - !ruby/object:Gem::Version
53
61
  version: '0'
54
62
  type: :development
55
63
  prerelease: false
56
64
  version_requirements: !ruby/object:Gem::Requirement
57
- none: false
58
65
  requirements:
59
- - - ! '>='
66
+ - - '>='
60
67
  - !ruby/object:Gem::Version
61
68
  version: '0'
62
69
  description: Social helpers for Rails apps.
@@ -86,36 +93,30 @@ files:
86
93
  - spec/spec_helper.rb
87
94
  - vendor/assets/javascripts/flakey/facebook.js.erb
88
95
  - vendor/assets/javascripts/flakey/google_plus.js.erb
96
+ - vendor/assets/javascripts/flakey/popup.js
89
97
  - vendor/assets/javascripts/flakey/twitter.js.erb
90
98
  homepage: ''
91
99
  licenses: []
100
+ metadata: {}
92
101
  post_install_message:
93
102
  rdoc_options: []
94
103
  require_paths:
95
104
  - lib
96
105
  required_ruby_version: !ruby/object:Gem::Requirement
97
- none: false
98
106
  requirements:
99
- - - ! '>='
107
+ - - '>='
100
108
  - !ruby/object:Gem::Version
101
109
  version: '0'
102
- segments:
103
- - 0
104
- hash: -1451939396660981137
105
110
  required_rubygems_version: !ruby/object:Gem::Requirement
106
- none: false
107
111
  requirements:
108
- - - ! '>='
112
+ - - '>='
109
113
  - !ruby/object:Gem::Version
110
114
  version: '0'
111
- segments:
112
- - 0
113
- hash: -1451939396660981137
114
115
  requirements: []
115
116
  rubyforge_project:
116
- rubygems_version: 1.8.25
117
+ rubygems_version: 2.0.3
117
118
  signing_key:
118
- specification_version: 3
119
+ specification_version: 4
119
120
  summary: Makes a bunch of helper methods available for including in your Rails views.
120
121
  test_files:
121
122
  - spec/flakey/twitter_spec.rb