flakey 0.2.2 → 0.3.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 041d20dc5bd4b3566cbb859cbb99a260c2365221
4
- data.tar.gz: 2e2067c4e18a57ade6106b071f862c9696a40f51
3
+ metadata.gz: e5e3a881d55a7d7af795bf39c525efe323afa076
4
+ data.tar.gz: 7dac21622501551c67bb98edb50b56a7a60c59e1
5
5
  SHA512:
6
- metadata.gz: ea453dcf9f83cf2d06f891a8b8e76d8f54a420f44cace9607a71f30f8125c0d1384ad8e794cf6b1346aaf789ed35319e2bef42ce7516dd68278b108cba191887
7
- data.tar.gz: 284773f6648fffeedeae1751e69442c22fcb06d01579fe5bfaf50b903efae2e2f62106c6a1d586628d0c66e569798d4fa553aa44cc95571644773620b25babb8
6
+ metadata.gz: fccba15c21831ae81f4bca70eb1ca14c4388706725ce86555f42f0cd5ebbda3cba04be07f9126a90ac2b54805858fc456d5fb283dc81219263b12183edfd78de
7
+ data.tar.gz: 4502b6794fc4aededa6b02bc6fbbb6fa7aa02e95579ef4430b189cdf35badd35844d8d271f33ef9d28dfe3e2ba9416e6637de46f635d5f7be6fb8be0afc4c525
@@ -1,6 +1,11 @@
1
1
  module Flakey
2
2
  module Facebook
3
3
  SHARE_URL = 'https://www.facebook.com/sharer/sharer.php'
4
+ #
5
+ # Needed to be able to pass a block down into link_to.
6
+ # See the share_button method.
7
+ # INFO: http://stackoverflow.com/a/7562194/574190
8
+ attr_accessor :output_buffer
4
9
 
5
10
  def facebook_nickname(options = {})
6
11
  options[:nickname] ||
@@ -45,11 +50,26 @@ module Flakey
45
50
  # INFO: http://goo.gl/MvqIi4
46
51
  #
47
52
  # Returns a HTML string.
48
- def share_button(options = {})
49
- label = options[:label] || 'Share'
50
- url = options[:url] || request.url
53
+ def share_button(options = {}, &block)
54
+ defaults = {
55
+ url: request.url,
56
+ label: 'Share',
57
+ target: '_blank',
58
+ class: 'facebook-share-button'
59
+ }
60
+
61
+ settings = defaults.merge options
62
+
63
+ url = "#{SHARE_URL}?u=#{CGI.escape settings[:url]}"
64
+ label = settings[:label]
65
+ settings.delete(:url)
66
+ settings.delete(:label)
51
67
 
52
- link_to label, "#{SHARE_URL}?u=#{url}", target: '_blank'
68
+ if block_given?
69
+ link_to(url, settings, &block)
70
+ else
71
+ link_to label, url, settings
72
+ end
53
73
  end
54
74
  end
55
75
  end
@@ -1,3 +1,3 @@
1
1
  module Flakey
2
- VERSION = "0.2.2"
2
+ VERSION = "0.3.0"
3
3
  end
@@ -0,0 +1,31 @@
1
+ # encoding: UTF-8
2
+ require "spec_helper"
3
+ require 'action_view'
4
+
5
+ class DummyHelper
6
+ include ::ActionView::Helpers::UrlHelper
7
+ include Flakey::Facebook
8
+ end
9
+
10
+ describe Flakey::Facebook do
11
+ subject { DummyHelper.new }
12
+
13
+ describe 'share_button' do
14
+ before { subject.stub_chain('request.url') { 'http://example.com/hello' } }
15
+ let(:default_url) do
16
+ "#{Flakey::Facebook::SHARE_URL}?u=http%3A%2F%2Fexample.com%2Fhello"
17
+ end
18
+
19
+ it 'should add the url' do
20
+ subject.share_button.should include(default_url)
21
+ end
22
+
23
+ it 'should have a class' do
24
+ subject.share_button.should include('class="facebook-share-but')
25
+ end
26
+
27
+ it 'should render a label' do
28
+ subject.share_button(label: 'Grinnick').should include('>Grinnick</a>')
29
+ end
30
+ end
31
+ end
@@ -58,7 +58,9 @@ describe Flakey::Twitter do
58
58
 
59
59
  describe 'custom_tweet_button' do
60
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" }
61
+ let(:default_url) do
62
+ "#{Flakey::Twitter::SHARE_URL}?url=http%3A%2F%2Fexample.com%2Fhello"
63
+ end
62
64
 
63
65
  it 'should include the default url and label' do
64
66
  subject.should_receive(:link_to)
@@ -20,7 +20,7 @@ if (typeof jQuery === "undefined") {
20
20
  };
21
21
 
22
22
  $(function(){
23
- $('.custom-tweet-button').on('click', function(e){
23
+ $('.custom-tweet-button, .facebook-share-button').on('click', function(e){
24
24
  e.preventDefault();
25
25
  openPopup($(e.target).closest('a').attr('href'), 'twitter');
26
26
  });
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: flakey
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.3.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - David Tuite
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2013-08-28 00:00:00.000000000 Z
11
+ date: 2013-08-29 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport
@@ -89,6 +89,7 @@ files:
89
89
  - lib/flakey/stackoverflow.rb
90
90
  - lib/flakey/twitter.rb
91
91
  - lib/flakey/version.rb
92
+ - spec/flakey/facebook_spec.rb
92
93
  - spec/flakey/twitter_spec.rb
93
94
  - spec/spec_helper.rb
94
95
  - vendor/assets/javascripts/flakey/facebook.js.erb
@@ -119,5 +120,6 @@ signing_key:
119
120
  specification_version: 4
120
121
  summary: Makes a bunch of helper methods available for including in your Rails views.
121
122
  test_files:
123
+ - spec/flakey/facebook_spec.rb
122
124
  - spec/flakey/twitter_spec.rb
123
125
  - spec/spec_helper.rb