sharing_tags 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.rubocop.yml +94 -0
- data/.travis.yml +1 -0
- data/Gemfile +2 -1
- data/Guardfile +21 -11
- data/README.md +8 -1
- data/Rakefile +16 -0
- data/Todo.md +4 -1
- data/app/assets/images/sharing_tags/icons/line.svg +9 -9
- data/app/assets/javascripts/sharing_tags.js +10 -0
- data/app/assets/javascripts/sharing_tags/init.js.coffee.erb +5 -4
- data/app/assets/javascripts/sharing_tags/links.js.coffee +9 -7
- data/app/assets/javascripts/sharing_tags/share.js.coffee +82 -62
- data/app/assets/javascripts/sharing_tags/share/callback.js.coffee +14 -0
- data/app/assets/javascripts/sharing_tags/share/facebook.js.coffee +82 -0
- data/app/assets/stylesheets/sharing_tags/wave_animation.css.sass +33 -0
- data/app/views/sharing_tags/meta/_open_graphs.html.slim +1 -1
- data/app/views/sharing_tags/meta/_twitter_card.html.slim +12 -9
- data/circle.yml +9 -0
- data/lib/generators/sharing_tags/install/install_generator.rb +12 -14
- data/lib/generators/sharing_tags/install/templates/initializer.rb +3 -0
- data/lib/sharing_tags.rb +0 -5
- data/lib/sharing_tags/action_controller/filters.rb +13 -10
- data/lib/sharing_tags/action_controller/helpers.rb +11 -9
- data/lib/sharing_tags/action_view/asset_helper.rb +39 -35
- data/lib/sharing_tags/action_view/button_helper.rb +62 -53
- data/lib/sharing_tags/action_view/meta_helper.rb +11 -8
- data/lib/sharing_tags/config.rb +3 -4
- data/lib/sharing_tags/configuration.rb +17 -18
- data/lib/sharing_tags/context.rb +11 -14
- data/lib/sharing_tags/engine.rb +11 -0
- data/lib/sharing_tags/network.rb +64 -30
- data/lib/sharing_tags/network/facebook.rb +11 -8
- data/lib/sharing_tags/railtie.rb +6 -9
- data/lib/sharing_tags/version.rb +1 -1
- data/sharing_tags.gemspec +1 -0
- data/spec/controllers/main_controller_spec.rb +2 -2
- data/spec/dummy/app/helpers/application_helper.rb +1 -0
- data/spec/generators/install_generator_spec.rb +8 -6
- data/spec/helpers/asset_helper_spec.rb +3 -2
- data/spec/helpers/button_helper_spec.rb +70 -76
- data/spec/helpers/meta_tags_helper_spec.rb +1 -2
- data/spec/javascripts/fixtures/facebook.json +3 -1
- data/spec/javascripts/sharing_tags/share/{facebook_share_spec.coffee → facebook_spec.coffee} +73 -12
- data/spec/javascripts/sharing_tags/share/vkontakte_spec.coffee +29 -0
- data/spec/javascripts/sharing_tags/share_spec.coffee +193 -0
- data/spec/javascripts/sharing_tags/sharing_tags_spec.coffee +9 -14
- data/spec/models/configuration_spec.rb +12 -14
- data/spec/models/network_spec.rb +1 -4
- data/spec/models/running_in_context_spec.rb +19 -6
- data/spec/spec_helper.rb +1 -2
- data/spec/support/generator_support.rb +1 -3
- data/spec/teaspoon_env.rb +39 -39
- data/spec/views/meta_tags/facebook_meta_tags_erb_spec.rb +16 -17
- data/spec/views/meta_tags/meta_tags_erb_spec.rb +5 -7
- metadata +29 -13
- data/app/assets/javascripts/sharing_tags.js.coffee +0 -9
- data/app/assets/javascripts/sharing_tags/share/base.js.coffee +0 -38
- data/app/assets/javascripts/sharing_tags/share/facebook.coffee +0 -57
- data/app/assets/javascripts/sharing_tags/share/vkontakte.js.coffee +0 -13
- data/bin/rspec +0 -16
- data/spec/javascripts/sharing_tags/share/vkontakte_share_spec.coffee +0 -31
@@ -0,0 +1,14 @@
|
|
1
|
+
class @SharingTags.Share.Callback
|
2
|
+
constructor: (@share)->
|
3
|
+
|
4
|
+
before_sharing: (provider)=>
|
5
|
+
@trigger("start_share", url: @share.url, provider: provider)
|
6
|
+
|
7
|
+
after_sharing: ->
|
8
|
+
@trigger("shared")
|
9
|
+
|
10
|
+
before_open_popup: (open_url, popup_window)=>
|
11
|
+
@trigger("open_popup", url: open_url, popup_window: popup_window)
|
12
|
+
|
13
|
+
trigger: (trigger_name, params...)->
|
14
|
+
jQuery?(window).trigger("sharing_tags.#{trigger_name}", params)
|
@@ -0,0 +1,82 @@
|
|
1
|
+
class @SharingTags.FacebookShare extends @SharingTags.Share
|
2
|
+
|
3
|
+
# available providers: sharer, fb_ui, dialog
|
4
|
+
@default_provider: "fb_ui"
|
5
|
+
|
6
|
+
app_id: null
|
7
|
+
return_url: null
|
8
|
+
provider: null
|
9
|
+
|
10
|
+
constructor: ({@app_id, @return_url, @provider})->
|
11
|
+
@provider = @detect_provider() if !@provider || @provider == "auto"
|
12
|
+
|
13
|
+
# todo: throw error for invalid provider
|
14
|
+
@constructor.init() if @provider is 'fb_ui' and not FB?
|
15
|
+
|
16
|
+
super
|
17
|
+
|
18
|
+
@init: (locale="en_US")->
|
19
|
+
if not FB?
|
20
|
+
jQuery.ajax(
|
21
|
+
url: "//connect.facebook.net/#{locale}/all.js"
|
22
|
+
dataType: "script"
|
23
|
+
cache: true
|
24
|
+
)
|
25
|
+
|
26
|
+
share: (provider = @provider)->
|
27
|
+
@callback.before_sharing(provider)
|
28
|
+
@["_#{provider}"]()
|
29
|
+
@
|
30
|
+
|
31
|
+
_sharer: ->
|
32
|
+
@_assert_vars "url"
|
33
|
+
@open_popup("http://www.facebook.com/sharer.php", u: @url)
|
34
|
+
|
35
|
+
_fb_ui: =>
|
36
|
+
@_assert_vars "url", "app_id"
|
37
|
+
return @constructor.init().done(@_fb_ui) if not FB?
|
38
|
+
|
39
|
+
FB?.ui(method: 'share', href: @url, app_id: @app_id, (response)=>
|
40
|
+
@callback.after_sharing(response)
|
41
|
+
# if response && !response.error_code
|
42
|
+
# @_after_callback(response)
|
43
|
+
# else
|
44
|
+
# # another callback
|
45
|
+
)
|
46
|
+
|
47
|
+
_dialog: (display = 'page')->
|
48
|
+
@_assert_vars 'url', 'return_url'
|
49
|
+
@open_popup("http://www.facebook.com/dialog/share", href: @url, redirect_uri: @return_url, app_id: @app_id, display: display)
|
50
|
+
|
51
|
+
# @note: mobile chrome and android browsers after sharing redirect to created post on Facebook
|
52
|
+
# @note: iphone facebook browser: after sharing redirected to shared post
|
53
|
+
_stream_share: ->
|
54
|
+
@_assert_vars 'url'
|
55
|
+
FB.ui(
|
56
|
+
method: 'stream.share',
|
57
|
+
u: @url
|
58
|
+
(response) ->
|
59
|
+
console?.log response
|
60
|
+
)
|
61
|
+
|
62
|
+
# # @note: iphone facebook browser - doesn't show page after sharing
|
63
|
+
# _fb_ui_feed = ->
|
64
|
+
# FB.ui(
|
65
|
+
# method: 'feed',
|
66
|
+
# name: "Name"
|
67
|
+
# description: "Description"
|
68
|
+
# link: @url,
|
69
|
+
# caption: "Sample caption",
|
70
|
+
# actions: {name: 'sample name', link: 'sharing link'},
|
71
|
+
# (response)=>
|
72
|
+
# @_after_callback(response)
|
73
|
+
# )
|
74
|
+
|
75
|
+
detect_provider: ->
|
76
|
+
if @_user_agent().match('CriOS')
|
77
|
+
"sharer"
|
78
|
+
else if @app_id
|
79
|
+
if @return_url then "dialog"
|
80
|
+
else "fb_ui"
|
81
|
+
else
|
82
|
+
"sharer"
|
@@ -0,0 +1,33 @@
|
|
1
|
+
@mixin create_keyframes_animation($name, $left_percent, $center_percent, $right_precent)
|
2
|
+
+keyframes($name)
|
3
|
+
0%
|
4
|
+
transform: scale(1)
|
5
|
+
#{$left_percent}%
|
6
|
+
transform: scale(1)
|
7
|
+
#{$center_percent}%
|
8
|
+
transform: scale(1.4)
|
9
|
+
#{$right_precent}%
|
10
|
+
transform: scale(1)
|
11
|
+
100%
|
12
|
+
transform: scale(1)
|
13
|
+
|
14
|
+
@mixin keyframes($name)
|
15
|
+
@keyframes #{$name}
|
16
|
+
@content
|
17
|
+
|
18
|
+
@mixin add_animation_on_sharing_button($index, $speed)
|
19
|
+
.sharing_tags-buttons__item
|
20
|
+
&:nth-child(#{$index})
|
21
|
+
a
|
22
|
+
animation: animate_sharing_buttons_#{$index} #{$speed}s infinite
|
23
|
+
|
24
|
+
@mixin create_wave_animation_on_sharing_buttons($count_of_buttons, $speed:2)
|
25
|
+
$step: 100 / $count_of_buttons
|
26
|
+
$half_step: $step / 2
|
27
|
+
@for $i from 1 through $count_of_buttons
|
28
|
+
$right: $i*$step
|
29
|
+
$center: $right - $half_step
|
30
|
+
$left: $center - $half_step
|
31
|
+
|
32
|
+
+create_keyframes_animation('animate_sharing_buttons_#{$i}', $left, $center, $right)
|
33
|
+
+add_animation_on_sharing_button($i, $speed)
|
@@ -8,7 +8,7 @@
|
|
8
8
|
meta property="og:image" content=meta.image
|
9
9
|
|
10
10
|
- if meta.page_url
|
11
|
-
meta property="og:url" content=meta.page_url
|
11
|
+
meta property="og:url" content=meta.page_url.html_safe
|
12
12
|
|
13
13
|
/https://developers.facebook.com/docs/sharing/opengraph#types
|
14
14
|
meta property="og:type" content="website"
|
@@ -1,20 +1,23 @@
|
|
1
|
-
meta name="twitter:card" content="summary"
|
2
1
|
|
3
2
|
- if meta.title
|
4
3
|
meta name="twitter:title" content=meta.title
|
5
4
|
|
6
5
|
- if meta.description
|
6
|
+
/ Page description less than 200 characters
|
7
7
|
meta name="twitter:description" content=meta.description
|
8
8
|
|
9
|
-
|
10
|
-
|
9
|
+
- if meta.page_url
|
10
|
+
meta name="twitter:url" content=meta.page_url.html_safe
|
11
|
+
|
12
|
+
- if meta.image
|
13
|
+
/<-- Twitter Summary card images must be at least 120x120px -->
|
14
|
+
meta name="twitter:image" content=meta.image
|
15
|
+
meta name="twitter:card" content="summary_large_image"
|
16
|
+
- else
|
17
|
+
meta name="twitter:card" content="summary"
|
18
|
+
|
19
|
+
|
11
20
|
/meta name="twitter:domain" content="www.aviasales.ru"
|
12
|
-
/<meta name="twitter:card" content="summary">
|
13
21
|
/<meta name="twitter:site" content="@publisher_handle">
|
14
|
-
/<meta name="twitter:title" content="Page Title">
|
15
|
-
/<meta name="twitter:description" content="Page description less than 200 characters">
|
16
22
|
/<meta name="twitter:creator" content="@author_handle">
|
17
|
-
/<-- Twitter Summary card images must be at least 120x120px -->
|
18
|
-
/<meta name="twitter:image" content="http://www.example.com/image.jpg">
|
19
|
-
/meta name="twitter:site" content="@aviasales"
|
20
23
|
|
data/circle.yml
ADDED
@@ -1,9 +1,9 @@
|
|
1
1
|
require 'rails/generators'
|
2
2
|
|
3
|
+
# rubocop:disable Metrics/MethodLength
|
3
4
|
module SharingTags
|
4
5
|
module Generators
|
5
6
|
class InstallGenerator < Rails::Generators::Base
|
6
|
-
|
7
7
|
source_root File.expand_path('../templates', __FILE__)
|
8
8
|
|
9
9
|
desc "Installs the SharingTags initializer into your application."
|
@@ -15,7 +15,7 @@ module SharingTags
|
|
15
15
|
desc: "Copy links partial"
|
16
16
|
|
17
17
|
def copy_initializer_file
|
18
|
-
if File.
|
18
|
+
if File.exist?("config/initializers/sharing_tags.rb")
|
19
19
|
say_skipped("create initializer sharing_tags.rb")
|
20
20
|
else
|
21
21
|
template 'initializer.rb', 'config/initializers/sharing_tags.rb'
|
@@ -26,7 +26,7 @@ module SharingTags
|
|
26
26
|
source_file = "app/assets/javascripts/application.js"
|
27
27
|
match_string = "sharing_tags"
|
28
28
|
|
29
|
-
insert_into_file_if source_file, match_string, after:
|
29
|
+
insert_into_file_if source_file, match_string, after: /\z/ do
|
30
30
|
"\n//= require #{match_string}"
|
31
31
|
end
|
32
32
|
end
|
@@ -39,7 +39,7 @@ module SharingTags
|
|
39
39
|
"*= require #{match_string}\n "
|
40
40
|
end
|
41
41
|
end
|
42
|
-
|
42
|
+
|
43
43
|
def add_layout
|
44
44
|
## slim
|
45
45
|
source_file = "app/views/layouts/application.html.slim"
|
@@ -64,7 +64,7 @@ module SharingTags
|
|
64
64
|
"\n <%= #{buttons_tags} %>\n"
|
65
65
|
end
|
66
66
|
|
67
|
-
##
|
67
|
+
## TODO: haml
|
68
68
|
end
|
69
69
|
|
70
70
|
def display_post_install
|
@@ -79,18 +79,16 @@ module SharingTags
|
|
79
79
|
|
80
80
|
def insert_into_file_if(source_file, find_string, **insert_into_file_options, &insert_into_file_block)
|
81
81
|
source_file_path = File.expand_path(source_file, destination_root)
|
82
|
+
return unless File.exist?(source_file_path)
|
82
83
|
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
insert_into_file source_file, insert_into_file_options, &insert_into_file_block
|
87
|
-
else
|
88
|
-
say_skipped("insert #{find_string} into #{source_file}")
|
89
|
-
end
|
84
|
+
source_content = File.binread(source_file_path)
|
85
|
+
if !source_content.include?(find_string)
|
86
|
+
insert_into_file source_file, insert_into_file_options, &insert_into_file_block
|
90
87
|
else
|
91
|
-
|
88
|
+
say_skipped("insert #{find_string} into #{source_file}")
|
92
89
|
end
|
93
90
|
end
|
94
91
|
end
|
95
92
|
end
|
96
|
-
end
|
93
|
+
end
|
94
|
+
# rubocop:enable Metrics/MethodLength
|
@@ -17,8 +17,11 @@ SharingTags.configure do
|
|
17
17
|
# app_id "123"
|
18
18
|
# title "Facebook sharing title"
|
19
19
|
# end
|
20
|
+
#
|
20
21
|
# twitter do
|
21
22
|
# title "Short title"
|
23
|
+
# description "Page description less than 200 characters"
|
24
|
+
# image "images must be at least 120x120px"
|
22
25
|
# end
|
23
26
|
|
24
27
|
# # for switch context call `sharing_tags_context(:user)` in controller action
|
data/lib/sharing_tags.rb
CHANGED
@@ -2,16 +2,12 @@ require "slim-rails"
|
|
2
2
|
require "role-rails"
|
3
3
|
|
4
4
|
module SharingTags
|
5
|
-
|
6
|
-
#extend ActiveSupport::Autoload
|
7
|
-
|
8
5
|
autoload :VERSION, 'sharing_tags/version'
|
9
6
|
autoload :Config, 'sharing_tags/config'
|
10
7
|
autoload :Configuration, 'sharing_tags/configuration'
|
11
8
|
autoload :Network, 'sharing_tags/network'
|
12
9
|
autoload :Context, 'sharing_tags/context'
|
13
10
|
|
14
|
-
|
15
11
|
module ActionView
|
16
12
|
autoload :MetaHelper, 'sharing_tags/action_view/meta_helper'
|
17
13
|
autoload :ButtonHelper, 'sharing_tags/action_view/button_helper'
|
@@ -33,7 +29,6 @@ module SharingTags
|
|
33
29
|
@config ||= Configuration.new
|
34
30
|
end
|
35
31
|
module_function :config
|
36
|
-
|
37
32
|
end
|
38
33
|
|
39
34
|
require 'sharing_tags/railtie' if defined?(Rails::Railtie)
|
@@ -1,13 +1,16 @@
|
|
1
|
-
module SharingTags
|
2
|
-
|
1
|
+
module SharingTags
|
2
|
+
module ActionController
|
3
|
+
module Filters
|
4
|
+
extend ActiveSupport::Concern
|
3
5
|
|
4
|
-
|
5
|
-
|
6
|
-
|
6
|
+
included do
|
7
|
+
append_before_filter :sharing_tags_clear_context
|
8
|
+
end
|
7
9
|
|
8
|
-
|
9
|
-
|
10
|
-
|
10
|
+
def sharing_tags_clear_context
|
11
|
+
logger.debug "SharingTags: clear context #{SharingTags.config.current_context.name}!" if logger.debug?
|
12
|
+
SharingTags.config.clear_context!
|
13
|
+
end
|
14
|
+
end
|
11
15
|
end
|
12
|
-
|
13
|
-
end
|
16
|
+
end
|
@@ -1,11 +1,13 @@
|
|
1
|
-
module SharingTags
|
1
|
+
module SharingTags
|
2
|
+
module ActionController
|
3
|
+
module Helpers
|
4
|
+
def sharing_tags
|
5
|
+
SharingTags.config.within_context_params(view_context)
|
6
|
+
end
|
2
7
|
|
3
|
-
|
4
|
-
|
8
|
+
def sharing_tags_context(name, *attrs)
|
9
|
+
SharingTags.config.switch_context(name, *attrs)
|
10
|
+
end
|
11
|
+
end
|
5
12
|
end
|
6
|
-
|
7
|
-
def sharing_tags_context(name, *attrs)
|
8
|
-
SharingTags.config.switch_context(name, *attrs)
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
13
|
+
end
|
@@ -1,37 +1,41 @@
|
|
1
1
|
require "non-stupid-digest-assets"
|
2
2
|
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
end
|
3
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
4
|
+
module SharingTags
|
5
|
+
module ActionView
|
6
|
+
module AssetHelper
|
7
|
+
def without_digest_asset_url(path, options = {})
|
8
|
+
options.merge!(digested: false)
|
9
|
+
|
10
|
+
add_image_to_non_digest_list(path)
|
11
|
+
url_to_image(path, options)
|
12
|
+
end
|
13
|
+
|
14
|
+
# redefine method Sprockets::Rails::Helper
|
15
|
+
# Computes asset path to public directory.
|
16
|
+
#
|
17
|
+
# Override this method for non digested assets
|
18
|
+
#
|
19
|
+
def compute_asset_path(path, options = {})
|
20
|
+
digested = options.delete(:digested)
|
21
|
+
digested = true if digested.nil?
|
22
|
+
|
23
|
+
if (digest_path = asset_digest_path(path, options))
|
24
|
+
path = digest_path if digested && digest_assets
|
25
|
+
path += "?body=1" if options[:debug]
|
26
|
+
File.join(assets_prefix || "/", path)
|
27
|
+
else
|
28
|
+
super
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def add_image_to_non_digest_list(asset_name)
|
35
|
+
return if ::NonStupidDigestAssets.whitelist.include?(asset_name)
|
36
|
+
::NonStupidDigestAssets.whitelist += [asset_name]
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
40
|
+
end
|
41
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
@@ -1,71 +1,80 @@
|
|
1
|
-
module SharingTags
|
1
|
+
module SharingTags
|
2
|
+
module ActionView
|
3
|
+
module ButtonHelper
|
4
|
+
def sharing_tags_buttons(*networks, **options)
|
5
|
+
networks = SharingTags::Network.lists if networks.empty?
|
6
|
+
|
7
|
+
# switching context
|
8
|
+
if options[:context].present?
|
9
|
+
SharingTags.config.switch_context(*options[:context]) do
|
10
|
+
render template: "sharing_tags/buttons.html.slim", locals: {networks: networks, options: options}
|
11
|
+
end
|
12
|
+
else
|
13
|
+
render template: "sharing_tags/buttons.html.slim", locals: {networks: networks, options: options}
|
14
|
+
end
|
15
|
+
end
|
2
16
|
|
3
|
-
|
4
|
-
|
17
|
+
def link_to_facebook_share(name_or_options = nil, &block)
|
18
|
+
share_to name_or_options, :facebook, [:app_id, :provider], &block
|
19
|
+
end
|
5
20
|
|
6
|
-
|
7
|
-
|
21
|
+
def link_to_vkontakte_share(name_or_options = nil, &block)
|
22
|
+
share_to name_or_options, :vkontakte, [:title, :description, :image], &block
|
23
|
+
end
|
8
24
|
|
9
|
-
|
10
|
-
|
25
|
+
def link_to_line_share(name_or_options = nil, &block)
|
26
|
+
share_to name_or_options, :line, [], &block
|
27
|
+
end
|
11
28
|
|
12
|
-
|
13
|
-
|
14
|
-
|
29
|
+
def link_to_google_share(name_or_options = nil, &block)
|
30
|
+
share_to name_or_options, :google, [], &block
|
31
|
+
end
|
15
32
|
|
16
|
-
|
17
|
-
|
18
|
-
|
33
|
+
def link_to_odnoklassniki_share(name_or_options = nil, &block)
|
34
|
+
share_to name_or_options, :odnoklassniki, [:title, :description], &block
|
35
|
+
end
|
19
36
|
|
20
|
-
|
21
|
-
|
22
|
-
|
37
|
+
def link_to_twitter_share(name_or_options = nil, &block)
|
38
|
+
share_to name_or_options, :twitter, [:title, :description], &block
|
39
|
+
end
|
23
40
|
|
24
|
-
|
25
|
-
|
26
|
-
|
41
|
+
def link_to_linkedin_share(name_or_options = nil, &block)
|
42
|
+
share_to name_or_options, :linkedin, [:title, :description], &block
|
43
|
+
end
|
27
44
|
|
28
|
-
|
29
|
-
share_link_to name_or_options, :odnoklassniki, [:title, :description], &block
|
30
|
-
end
|
45
|
+
private
|
31
46
|
|
32
|
-
|
33
|
-
|
34
|
-
|
47
|
+
# TODO: enable Metrics/*
|
48
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/MethodLength, Metrics/AbcSize
|
49
|
+
def share_to(name_or_options = nil, network = nil, data_params = [], &block)
|
50
|
+
params = sharing_tags[network]
|
51
|
+
data_attrs = params.get(*(data_params + [:network, :share_url]))
|
52
|
+
data_attrs[:context] = SharingTags.config.current_context.name
|
35
53
|
|
36
|
-
|
37
|
-
|
38
|
-
|
54
|
+
if block_given?
|
55
|
+
name_or_options = {} if !name_or_options || name_or_options.is_a?(String)
|
56
|
+
data_attrs.merge!(name_or_options.delete(:data)) if name_or_options[:data]
|
39
57
|
|
40
|
-
|
58
|
+
if name_or_options[:role]
|
59
|
+
name_or_options[:role] += " sharing_tags_share"
|
60
|
+
else
|
61
|
+
name_or_options[:role] = "sharing_tags_share"
|
62
|
+
end
|
41
63
|
|
42
|
-
|
43
|
-
params = sharing_tags[network]
|
44
|
-
data_attrs = params.get(*(data_params +[:network, :share_url]))
|
45
|
-
data_attrs[:context] = SharingTags.config.current_context.name
|
64
|
+
name_or_options.merge!(data: data_attrs, target: "_blank")
|
46
65
|
|
47
|
-
|
48
|
-
|
49
|
-
|
66
|
+
link_to params.page_url, name_or_options, &block
|
67
|
+
else
|
68
|
+
name_or_options = default_name(network) if name_or_options.nil?
|
50
69
|
|
51
|
-
|
52
|
-
|
53
|
-
else
|
54
|
-
name_or_options[:role] = "sharing_tags_share"
|
70
|
+
link_to name_or_options, params.page_url, data: data_attrs, role: "sharing_tags_share", target: "_blank", &block
|
71
|
+
end
|
55
72
|
end
|
73
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
56
74
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
else
|
61
|
-
name_or_options = default_name(network) if name_or_options.nil?
|
62
|
-
|
63
|
-
link_to name_or_options, params.page_url, data: data_attrs, role: "sharing_tags_share", target: "_blank", &block
|
75
|
+
def default_name(network)
|
76
|
+
image_tag "sharing_tags/icons/#{network}.svg"
|
77
|
+
end
|
64
78
|
end
|
65
|
-
end
|
66
|
-
|
67
|
-
def default_name(network)
|
68
|
-
image_tag "sharing_tags/icons/#{network}.svg"
|
69
|
-
end
|
70
|
-
|
79
|
+
end
|
71
80
|
end
|