yashare 0.1 → 0.9
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -0
- data/README.md +35 -1
- data/lib/yashare/helpers.rb +7 -6
- data/lib/yashare/version.rb +1 -1
- data/lib/yashare/widget.rb +17 -19
- data/spec/spec_helper.rb +4 -0
- data/spec/support/default.html +2 -0
- data/spec/support/with_services.html +2 -0
- data/spec/yashare/helpers_spec.rb +23 -0
- data/spec/yashare/widget_spec.rb +93 -0
- data/yashare.gemspec +1 -0
- metadata +24 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc67f92b907766a7f421ef6ae5717ebab687ad8e
|
4
|
+
data.tar.gz: ba2ba0306f24d629265f24d0fc5d9405cb1c26c3
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ee2c04093b6466caabe98116de4d862efa93ae588cea2cb5b0bb7437cca93cbc941bdd48d517f5d872426f4968e5d7e4d21d5892680d6d08ddd0fd6416662f73
|
7
|
+
data.tar.gz: e83bbb55bcee55e08aadf978b1699a1efa5964743053380cb2e334f8d828071d2a821d254b18f06e47c92a2fa49cd4ae2784d544d4ff7e4284ae8900e94a8bbe
|
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,12 @@
|
|
1
1
|
# YaShare
|
2
2
|
|
3
|
+
[![Build Status](https://travis-ci.org/andrewgr/yashare.png)](https://travis-ci.org/andrewgr/yashare)
|
4
|
+
[![Code Climate](https://codeclimate.com/github/andrewgr/yashare/badges/gpa.svg)](https://codeclimate.com/github/andrewgr/yashare)
|
5
|
+
[![Test Coverage](https://codeclimate.com/github/andrewgr/yashare/badges/coverage.svg)](https://codeclimate.com/github/andrewgr/yashare/coverage)
|
6
|
+
[![Gem Version](https://badge.fury.io/rb/yashare.svg)](http://badge.fury.io/rb/yashare)
|
7
|
+
|
8
|
+
An Action View helper to add Yandex Share buttons to your Rails App.
|
9
|
+
|
3
10
|
## Installation
|
4
11
|
|
5
12
|
Add this line to your application's Gemfile:
|
@@ -16,7 +23,34 @@ Or install it yourself as:
|
|
16
23
|
|
17
24
|
## Usage
|
18
25
|
|
19
|
-
|
26
|
+
Use `yashare` helper in your view code to add the Yandex Share buttons to the page. Without any parameters, this code
|
27
|
+
|
28
|
+
<%= yashare %>
|
29
|
+
|
30
|
+
will render this HTML:
|
31
|
+
```HTML
|
32
|
+
<script charset="utf-8" type="text/javascript" src="//yastatic.net/share/share.js"></script>
|
33
|
+
<div class="yashare-auto-init" data-yashareQuickServices="vkontakte,facebook,twitter,lj" data-yashareL10n="ru" data-yashareType="button"></div>
|
34
|
+
```
|
35
|
+
|
36
|
+
Use `services` option to specify buttons for which services should be displayed. The default services are: `:vkontakte`, `:facebook`, `:twitter`, `:lj`. Supported services: `:blogger`, `:delicious`, `:diary`, `:digg`, `:evernote`, `:facebook`, `:friendfeed`, `:gplus`, `:juick`, `:liveinternet`, `:linkedin`, `:lj`, `:moikrug`, `:moimir`, `:myspace`, `:odnoklassniki`, `:pinterest`, `:surfingbird`, `:tutby`, `:twitter`, `:vkontakte`, `:yazakladki`.
|
37
|
+
|
38
|
+
<%= yashare(services: [:twitter, :facebook]) %>
|
39
|
+
|
40
|
+
Use `lang` option to specify the language for the buttons. The default value is `ru`. Supported values: `:az`,
|
41
|
+
`:be`, `:en`, `:hy`, `:ka`, `:kk`, `:ro`, `:ru`, `:tr`, `:tt`, `:uk`.
|
42
|
+
|
43
|
+
<%= yashare(lang: :ru) %>
|
44
|
+
|
45
|
+
Use `image` option to specify the image for sharing on Pinterest. This option is useful only when `services` option includes `:pinterest`.
|
46
|
+
|
47
|
+
<%= yashare(image: 'http://example.com/i/photo.jpg') %>
|
48
|
+
|
49
|
+
Use `type` option to specify the appearance of the buttons. Default value is `:button`. Supported values: `:small`, `:button`, `:link`, `:icon`, `:none`.
|
50
|
+
|
51
|
+
<%= yashare(type: :small) %>
|
52
|
+
|
53
|
+
Read Yandex Share button [documentation](https://tech.yandex.ru/share/) (in Russian) for more information.
|
20
54
|
|
21
55
|
## Contributing
|
22
56
|
|
data/lib/yashare/helpers.rb
CHANGED
@@ -2,17 +2,18 @@ module Yashare
|
|
2
2
|
module Helpers
|
3
3
|
extend ActiveSupport::Concern
|
4
4
|
|
5
|
-
def yashare(opts={})
|
6
|
-
|
5
|
+
def yashare(opts = {})
|
6
|
+
attrs = {
|
7
7
|
charset: 'utf-8',
|
8
8
|
type: 'text/javascript',
|
9
9
|
src: '//yastatic.net/share/share.js'
|
10
|
-
|
10
|
+
}
|
11
11
|
|
12
|
-
|
12
|
+
script = content_tag(:script, nil, attrs)
|
13
|
+
widget = Yashare::Widget.new(self, opts)
|
14
|
+
html = [script, widget].join("\n")
|
13
15
|
|
14
|
-
html
|
15
|
-
self.raw(html)
|
16
|
+
raw(html)
|
16
17
|
end
|
17
18
|
end
|
18
19
|
end
|
data/lib/yashare/version.rb
CHANGED
data/lib/yashare/widget.rb
CHANGED
@@ -1,36 +1,34 @@
|
|
1
1
|
module Yashare
|
2
2
|
class Widget
|
3
|
-
def initialize(view, opts={})
|
3
|
+
def initialize(view, opts = {})
|
4
4
|
@view = view
|
5
5
|
|
6
|
-
@services = opts.fetch(:services,
|
6
|
+
@services = opts.fetch(:services, %w(vkontakte facebook twitter lj))
|
7
7
|
@image = opts.fetch(:image, nil)
|
8
8
|
@type = opts.fetch(:type, 'button')
|
9
9
|
@lang = opts.fetch(:lang, 'ru')
|
10
10
|
end
|
11
11
|
|
12
12
|
def to_s
|
13
|
-
|
14
|
-
|
15
|
-
data: {
|
16
|
-
yashareL10n: lang,
|
17
|
-
yashareType: type,
|
18
|
-
yashareQuickServices: services.join(',')
|
19
|
-
}
|
20
|
-
}
|
21
|
-
|
22
|
-
if type == 'small'
|
23
|
-
attrs[:data][:yashareTheme] = 'counter'
|
24
|
-
end
|
13
|
+
@html ||= render
|
14
|
+
end
|
25
15
|
|
26
|
-
|
27
|
-
attrs[:data][:yashareImage] = image
|
28
|
-
end
|
16
|
+
private
|
29
17
|
|
30
|
-
|
18
|
+
def render
|
19
|
+
view.content_tag(:div, nil, class: 'yashare-auto-init', data: data_attrs)
|
31
20
|
end
|
32
21
|
|
33
|
-
|
22
|
+
def data_attrs
|
23
|
+
{
|
24
|
+
yashareQuickServices: Array(services).join(','),
|
25
|
+
yashareL10n: lang,
|
26
|
+
yashareType: type
|
27
|
+
}.tap do |data|
|
28
|
+
data[:yashareTheme] = 'counter' if type.to_s == 'small'
|
29
|
+
data[:yashareImage] = image if image.present?
|
30
|
+
end
|
31
|
+
end
|
34
32
|
|
35
33
|
attr_reader :view, :type, :services, :image, :lang
|
36
34
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Yashare::Helpers do
|
4
|
+
describe '#yashare' do
|
5
|
+
let(:view) { ActionView::Base.new }
|
6
|
+
|
7
|
+
context 'no options specified' do
|
8
|
+
subject { view.yashare }
|
9
|
+
|
10
|
+
let(:expected) { File.read('./spec/support/default.html').strip }
|
11
|
+
|
12
|
+
it { is_expected.to eq(expected) }
|
13
|
+
end
|
14
|
+
|
15
|
+
context 'services specified' do
|
16
|
+
subject { view.yashare(services: :facebook) }
|
17
|
+
|
18
|
+
let(:expected) { File.read('./spec/support/with_services.html').strip }
|
19
|
+
|
20
|
+
it { is_expected.to eq(expected) }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
@@ -0,0 +1,93 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
RSpec.describe Yashare::Widget do
|
4
|
+
let(:view) { ActionView::Base.new }
|
5
|
+
|
6
|
+
describe '#to_s' do
|
7
|
+
context 'no options specified' do
|
8
|
+
subject { described_class.new(view).to_s }
|
9
|
+
|
10
|
+
let(:expected) do
|
11
|
+
'<div
|
12
|
+
class="yashare-auto-init"
|
13
|
+
data-yashareQuickServices="vkontakte,facebook,twitter,lj"
|
14
|
+
data-yashareL10n="ru"
|
15
|
+
data-yashareType="button"></div>'.gsub(/\s+/, ' ')
|
16
|
+
end
|
17
|
+
|
18
|
+
it { is_expected.to eq(expected) }
|
19
|
+
end
|
20
|
+
|
21
|
+
context 'one service specified' do
|
22
|
+
subject { described_class.new(view, services: 'vkontakte').to_s }
|
23
|
+
|
24
|
+
let(:expected) do
|
25
|
+
'<div
|
26
|
+
class="yashare-auto-init"
|
27
|
+
data-yashareQuickServices="vkontakte"
|
28
|
+
data-yashareL10n="ru"
|
29
|
+
data-yashareType="button"></div>'.gsub(/\s+/, ' ')
|
30
|
+
end
|
31
|
+
|
32
|
+
it { is_expected.to eq(expected) }
|
33
|
+
end
|
34
|
+
|
35
|
+
context 'services specified' do
|
36
|
+
subject { described_class.new(view, services: ['vkontakte', 'lj']).to_s }
|
37
|
+
|
38
|
+
let(:expected) do
|
39
|
+
'<div
|
40
|
+
class="yashare-auto-init"
|
41
|
+
data-yashareQuickServices="vkontakte,lj"
|
42
|
+
data-yashareL10n="ru"
|
43
|
+
data-yashareType="button"></div>'.gsub(/\s+/, ' ')
|
44
|
+
end
|
45
|
+
|
46
|
+
it { is_expected.to eq(expected) }
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'language specified' do
|
50
|
+
subject { described_class.new(view, lang: 'en').to_s }
|
51
|
+
|
52
|
+
let(:expected) do
|
53
|
+
'<div
|
54
|
+
class="yashare-auto-init"
|
55
|
+
data-yashareQuickServices="vkontakte,facebook,twitter,lj"
|
56
|
+
data-yashareL10n="en"
|
57
|
+
data-yashareType="button"></div>'.gsub(/\s+/, ' ')
|
58
|
+
end
|
59
|
+
|
60
|
+
it { is_expected.to eq(expected) }
|
61
|
+
end
|
62
|
+
|
63
|
+
context 'image specified' do
|
64
|
+
subject { described_class.new(view, image: '/img.png').to_s }
|
65
|
+
|
66
|
+
let(:expected) do
|
67
|
+
'<div
|
68
|
+
class="yashare-auto-init"
|
69
|
+
data-yashareQuickServices="vkontakte,facebook,twitter,lj"
|
70
|
+
data-yashareL10n="ru"
|
71
|
+
data-yashareType="button"
|
72
|
+
data-yashareImage="/img.png"></div>'.gsub(/\s+/, ' ')
|
73
|
+
end
|
74
|
+
|
75
|
+
it { is_expected.to eq(expected) }
|
76
|
+
end
|
77
|
+
|
78
|
+
context 'image specified' do
|
79
|
+
subject { described_class.new(view, type: 'small').to_s }
|
80
|
+
|
81
|
+
let(:expected) do
|
82
|
+
'<div
|
83
|
+
class="yashare-auto-init"
|
84
|
+
data-yashareQuickServices="vkontakte,facebook,twitter,lj"
|
85
|
+
data-yashareL10n="ru"
|
86
|
+
data-yashareType="small"
|
87
|
+
data-yashareTheme="counter"></div>'.gsub(/\s+/, ' ')
|
88
|
+
end
|
89
|
+
|
90
|
+
it { is_expected.to eq(expected) }
|
91
|
+
end
|
92
|
+
end
|
93
|
+
end
|
data/yashare.gemspec
CHANGED
@@ -21,4 +21,5 @@ Gem::Specification.new do |gem|
|
|
21
21
|
gem.add_development_dependency 'actionpack', '~> 4'
|
22
22
|
gem.add_development_dependency 'rubocop', '~> 0.30'
|
23
23
|
gem.add_development_dependency 'cane', '~> 2.6', '>= 2.6.1'
|
24
|
+
gem.add_development_dependency 'codeclimate-test-reporter', '~> 0.4'
|
24
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: yashare
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.9'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Andrei Gridnev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-05-
|
11
|
+
date: 2015-05-18 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -86,6 +86,20 @@ dependencies:
|
|
86
86
|
- - ">="
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: 2.6.1
|
89
|
+
- !ruby/object:Gem::Dependency
|
90
|
+
name: codeclimate-test-reporter
|
91
|
+
requirement: !ruby/object:Gem::Requirement
|
92
|
+
requirements:
|
93
|
+
- - "~>"
|
94
|
+
- !ruby/object:Gem::Version
|
95
|
+
version: '0.4'
|
96
|
+
type: :development
|
97
|
+
prerelease: false
|
98
|
+
version_requirements: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - "~>"
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0.4'
|
89
103
|
description: Add and customize Yandex Share buttons to your Rails app
|
90
104
|
email:
|
91
105
|
- andrew.gridnev@gmail.com
|
@@ -107,6 +121,10 @@ files:
|
|
107
121
|
- lib/yashare/version.rb
|
108
122
|
- lib/yashare/widget.rb
|
109
123
|
- spec/spec_helper.rb
|
124
|
+
- spec/support/default.html
|
125
|
+
- spec/support/with_services.html
|
126
|
+
- spec/yashare/helpers_spec.rb
|
127
|
+
- spec/yashare/widget_spec.rb
|
110
128
|
- yashare.gemspec
|
111
129
|
homepage: https://github.com/andrewgr/yashare/
|
112
130
|
licenses:
|
@@ -134,3 +152,7 @@ specification_version: 4
|
|
134
152
|
summary: Yandex Share buttons for your Rails app
|
135
153
|
test_files:
|
136
154
|
- spec/spec_helper.rb
|
155
|
+
- spec/support/default.html
|
156
|
+
- spec/support/with_services.html
|
157
|
+
- spec/yashare/helpers_spec.rb
|
158
|
+
- spec/yashare/widget_spec.rb
|