rrssb-rails 0.0.1 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -1
- data/app/helpers/rrssb/rails/buttons_helper.rb +20 -17
- data/lib/rrssb/rails/version.rb +1 -1
- data/test/helpers/buttons_helper_test.rb +65 -1
- data/vendor/assets/images/rrssb-rails-404.png +0 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: d88e5025e5bd3ad877194b62c21981ff3ce14698
|
4
|
+
data.tar.gz: bf2fcc9b6d5d1ecc162d7a59ad854f6f83e084d3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e85de7cf88f12d6b229f99fb4b30da3eb791bd90f18f0da119be3d85ab2b0a7fd74b652b5d296c1ef8491350dad2f14845184c71a9462ed4bebb6bc306d75836
|
7
|
+
data.tar.gz: 2e6db7fe1e8b288fb3c5af2dc502da940263541f85a30b399286e5dac29bcf3120cd7130dd069f373197d8fecd049920171e8af84d973bbcf7b76c4eb16a146f
|
data/README.md
CHANGED
@@ -49,7 +49,7 @@ You can use the helper `rrssb_tag` to generate and customize your social share b
|
|
49
49
|
|
50
50
|
```ruby
|
51
51
|
rrssb_tag(url: 'http://my_url.com', buttons: %w{facebook twitter google_plus})
|
52
|
-
# => Generate 3 responsive social share
|
52
|
+
# => Generate 3 responsive social share buttons for facebook, twitter and google+ in this order
|
53
53
|
```
|
54
54
|
|
55
55
|
For more information, see the dummy rails application available in `/test`.
|
@@ -3,7 +3,6 @@ module Rrssb
|
|
3
3
|
module ButtonsHelper
|
4
4
|
def rrssb_tag(opts={})
|
5
5
|
buttons = opts[:buttons] || []
|
6
|
-
url = opts.delete(:url) { '#' }
|
7
6
|
contents = opts[:contents] || {}
|
8
7
|
|
9
8
|
html = []
|
@@ -13,20 +12,20 @@ module Rrssb
|
|
13
12
|
html << "<li class='rrssb-#{button.gsub(/[_-]/,'')}'>"
|
14
13
|
html << case button
|
15
14
|
when 'email'
|
16
|
-
label = content
|
17
|
-
subject = content
|
18
|
-
cc = content
|
19
|
-
to = content
|
15
|
+
label = content[:label] || button
|
16
|
+
subject = content[:subject]
|
17
|
+
cc = content[:cc]
|
18
|
+
to = content[:to]
|
20
19
|
link_content = "<span class='rrssb-icon'>#{image_tag('mail.min.svg')}</span><span class='rrssb-text'>#{label}</span>"
|
21
20
|
|
22
21
|
mail_to(to, link_content.html_safe, subject: subject, cc: cc)
|
23
22
|
else
|
24
|
-
label = content
|
23
|
+
label = content[:label] || (button == 'hackernews' ? 'hacker news' : button.humanize)
|
25
24
|
image_name = "#{button}.min.svg"
|
26
25
|
link_content = "<span class='rrssb-icon'>#{image_tag(image_name)}</span><span class='rrssb-text'>#{label}</span>"
|
27
|
-
html_options = { 'class' => 'popup' }
|
26
|
+
html_options = button == 'github' ? {} : { 'class' => 'popup' }
|
28
27
|
|
29
|
-
link_to(link_content.html_safe, social_url(button,
|
28
|
+
link_to(link_content.html_safe, social_url(button, content, opts), html_options)
|
30
29
|
end
|
31
30
|
html << "</li>"
|
32
31
|
end
|
@@ -35,16 +34,20 @@ module Rrssb
|
|
35
34
|
raw html.join("\n")
|
36
35
|
end
|
37
36
|
|
38
|
-
|
39
|
-
|
37
|
+
def social_url(button, content, opts={})
|
38
|
+
title = opts[:title] || ''
|
39
|
+
url = opts[:url] || '#'
|
40
|
+
img = content[:img] || ''
|
41
|
+
|
40
42
|
case button
|
41
|
-
when '
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
43
|
+
when 'delicious' then "https://www.delicious.com/save?v=5&url=#{url}&title=#{title}&jump=yes"
|
44
|
+
when 'facebook' then "https://www.facebook.com/sharer/sharer.php?u=#{url}"
|
45
|
+
when 'github' then url
|
46
|
+
when 'google_plus' then "https://plus.google.com/share?url=#{url}"
|
47
|
+
when 'hackernews' then "https://news.ycombinator.com/submitlink?u=#{url}&t=#{title}"
|
48
|
+
when 'pinterest' then "https://www.pinterest.com/pin/create/button/?url=#{url}&media=#{img}&description=#{title}"
|
49
|
+
when 'twitter' then "https://twitter.com/intent/tweet?url=#{url}&text=#{content[:text]}&via=#{content[:via]}"
|
50
|
+
else image_path('rrssb-rails-404.png')
|
48
51
|
end
|
49
52
|
end
|
50
53
|
end
|
data/lib/rrssb/rails/version.rb
CHANGED
@@ -9,7 +9,71 @@ class Rrssb::Rails::ButtonsHelperTest < ActionView::TestCase
|
|
9
9
|
assert_select doc.root, "ul.rrssb-buttons"
|
10
10
|
assert_select doc.root, "li", 2
|
11
11
|
assert_select doc.root, "a.popup", 2 do
|
12
|
-
assert_select "[href=?]",
|
12
|
+
assert_select "[href=?]", /.*url=#{identifier_url}.*/ # Href property for the 2 includes the given url
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
test "#rrssb_tag generates a github button than opens a link specified by its url, no popup" do
|
17
|
+
url_to_open = 'https://github.com/dam/rrssb-rails'
|
18
|
+
result = rrssb_tag(url: url_to_open, buttons: ['github'])
|
19
|
+
doc = HTML::Document.new(result)
|
20
|
+
|
21
|
+
assert_select doc.root, "li.rrssb-github"
|
22
|
+
assert_select doc.root, "a", 1 do
|
23
|
+
assert_select "[href=?]", /.*#{url_to_open}.*/
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
test "#rrssb_tag generates a delicious button" do
|
28
|
+
identifier_url = 'http://myurl.com'
|
29
|
+
title = 'My sharing title'
|
30
|
+
result = rrssb_tag(url: identifier_url, title: title, buttons: ['delicious'])
|
31
|
+
doc = HTML::Document.new(result)
|
32
|
+
|
33
|
+
assert_select doc.root, "li.rrssb-delicious"
|
34
|
+
assert_select doc.root, "a", 1 do
|
35
|
+
assert_select "[href=?]", /.*url=#{identifier_url}.*/
|
36
|
+
assert_select "[href=?]", /.*title=#{title}.*/
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
test "#rrssb_tag generates a google+ button with special content" do
|
41
|
+
identifier_url = 'http://myurl.com'
|
42
|
+
result = rrssb_tag(url: identifier_url, buttons: ['google_plus'])
|
43
|
+
doc = HTML::Document.new(result)
|
44
|
+
|
45
|
+
assert_select doc.root, "li.rrssb-googleplus"
|
46
|
+
assert_select doc.root, "a", 1 do
|
47
|
+
assert_select "[href=?]", /.*url=#{identifier_url}.*/
|
48
|
+
end
|
49
|
+
end
|
50
|
+
|
51
|
+
test "#rrssb_tag generates a harcker news button to submit a link" do
|
52
|
+
url_to_link = 'http://myurl.com'
|
53
|
+
title = 'My title'
|
54
|
+
result = rrssb_tag(url: url_to_link, title: title, buttons: ['hackernews'])
|
55
|
+
doc = HTML::Document.new(result)
|
56
|
+
|
57
|
+
assert_select doc.root, "li.rrssb-hackernews"
|
58
|
+
assert_select doc.root, "a", 1 do
|
59
|
+
assert_select "[href=?]", /.*u=#{url_to_link}.*/
|
60
|
+
assert_select "[href=?]", /.*t=#{title}.*/
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
test "#rrssb_tag generates a piterest sharing button" do
|
65
|
+
url_to_link = 'http://myurl.com'
|
66
|
+
title = 'My title'
|
67
|
+
img_url = image_url('rrssb-rails-404.png')
|
68
|
+
|
69
|
+
result = rrssb_tag(url: url_to_link, title: title, buttons: ['pinterest'], contents: { pinterest: { img: img_url } } )
|
70
|
+
doc = HTML::Document.new(result)
|
71
|
+
|
72
|
+
assert_select doc.root, "li.rrssb-pinterest"
|
73
|
+
assert_select doc.root, "a", 1 do
|
74
|
+
assert_select "[href=?]", /.*url=#{url_to_link}.*/
|
75
|
+
assert_select "[href=?]", /.*description=#{title}.*/
|
76
|
+
assert_select "[href=?]", /.*media=.*#{img_url}.*/
|
13
77
|
end
|
14
78
|
end
|
15
79
|
end
|
Binary file
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: rrssb-rails
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.1.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Damien Imberdis
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rails
|
@@ -95,6 +95,7 @@ files:
|
|
95
95
|
- vendor/assets/images/pinterest.min.svg
|
96
96
|
- vendor/assets/images/pocket.min.svg
|
97
97
|
- vendor/assets/images/reddit.min.svg
|
98
|
+
- vendor/assets/images/rrssb-rails-404.png
|
98
99
|
- vendor/assets/images/tumblr.min.svg
|
99
100
|
- vendor/assets/images/twitter.min.svg
|
100
101
|
- vendor/assets/images/vk.min.svg
|