sharing_tags 0.0.7 → 0.0.8

Sign up to get free protection for your applications and to get access to all the features.
Files changed (29) hide show
  1. checksums.yaml +4 -4
  2. data/app/assets/javascripts/sharing_tags/init.js.coffee.erb +10 -0
  3. data/app/assets/javascripts/sharing_tags/share/base.js.coffee +38 -0
  4. data/app/assets/javascripts/sharing_tags/share/facebook.coffee +9 -44
  5. data/app/assets/javascripts/sharing_tags/share/vkontakte.js.coffee +13 -0
  6. data/app/assets/javascripts/sharing_tags/share.js.coffee +11 -8
  7. data/app/assets/javascripts/sharing_tags.js.coffee +2 -0
  8. data/app/views/sharing_tags/button/_line.html.slim +2 -0
  9. data/app/views/sharing_tags/meta/_open_graphs.html.slim +4 -0
  10. data/lib/generators/sharing_tags/install/install_generator.rb +45 -28
  11. data/lib/sharing_tags/action_view/asset_helper.rb +1 -1
  12. data/lib/sharing_tags/action_view/button_helper.rb +9 -2
  13. data/lib/sharing_tags/action_view/meta_helper.rb +1 -1
  14. data/lib/sharing_tags/context.rb +6 -0
  15. data/lib/sharing_tags/network.rb +13 -3
  16. data/lib/sharing_tags/version.rb +1 -1
  17. data/lib/sharing_tags.rb +1 -1
  18. data/sharing_tags.gemspec +1 -1
  19. data/spec/controllers/main_controller_spec.rb +2 -2
  20. data/spec/generators/install_generator_spec.rb +95 -13
  21. data/spec/helpers/asset_helper_spec.rb +1 -1
  22. data/spec/javascripts/fixtures/facebook.json +9 -2
  23. data/spec/javascripts/fixtures/vkontakte.json +8 -0
  24. data/spec/javascripts/sharing_tags/share/facebook_share_spec.coffee +25 -0
  25. data/spec/javascripts/sharing_tags/share/vkontakte_share_spec.coffee +31 -0
  26. data/spec/support/generator_support.rb +13 -0
  27. data/spec/views/meta_tags/facebook_meta_tags_erb_spec.rb +2 -0
  28. metadata +12 -5
  29. data/app/assets/javascripts/sharing_tags/init.js.coffee +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 5fb477566fe6d310fe532406ac33317b51a35826
4
- data.tar.gz: 4cbc0cce2a9f871533146f65f09a5a3a6e274543
3
+ metadata.gz: 22ce4f33d58d62d83309ce208af04cb753687b29
4
+ data.tar.gz: 58c19bba59871eb7a2f5df143087d1e551ba4b1f
5
5
  SHA512:
6
- metadata.gz: 04d3e69d58ed8925d52913d4b5ad77e4e4e11a81322aba836ba1ccf66aa2a7a77204782bdc951004273fa261f9b29d025498bb81d29814bf4790686349761e28
7
- data.tar.gz: 182188e1a0e6267f740d5ff6c3c307e58e3de46eab0af85576e7c9d4f633da607de51fd0c83f98885dd2f6bb48dd3542e4dbc06308e0f993a308c27a4b097c06
6
+ metadata.gz: 74976814d96090a576b36759c90e90cedf0ae4250d11e22ec9d76fe89044133d4ff5a32449ffbfa2b72778bc8adda31a4ec0e8181a159a8b5eb9f0128fc34f26
7
+ data.tar.gz: d70c620e3a0169860137e5ce2d65050572439d7a46b271e236ead72aaf5644c5d2449a690fb34aa35676316bec960504f70f7675dd0ce2e47de18de2340628fa
@@ -0,0 +1,10 @@
1
+ <% fb = SharingTags.config.current_context[:facebook] %>
2
+
3
+ <% if fb && app_id = fb.attributes[:app_id] %>
4
+ @fbAsyncInit = ->
5
+ FB.init(
6
+ appId: '<%= app_id %>',
7
+ version: 'v2.3'
8
+ )
9
+ @SharingTags.FacebookShare.init()
10
+ <% end %>
@@ -0,0 +1,38 @@
1
+ class @SharingTags.BaseShare
2
+
3
+ url: null
4
+ title: null
5
+ description: null
6
+
7
+ constructor: ({@url, @title, @description})->
8
+ @_assert_vars 'url'
9
+
10
+ _open_popup: (api_url, params)->
11
+ share_url = if params then "#{api_url}?#{$.param(params)}" else api_url
12
+ share_window = window.open share_url, 'Sharing', 'width=740,height=440'
13
+
14
+ clearInterval(@interval)
15
+ iteration = 0
16
+ @interval = setInterval((=>
17
+ iteration++
18
+ if @_checkSharing(share_url, share_window, iteration)
19
+ clearInterval @interval
20
+ jQuery("body").trigger("sharing_tags.shared") if jQuery
21
+ ), 500)
22
+
23
+ _checkSharing: (share_url, share_window, iteration)=>
24
+ # console.log("check desktop sharing", share_url, share_window, iteration)
25
+ share_window?.closed || iteration >= 15
26
+
27
+ _after_callback: =>
28
+ jQuery?("body").trigger("sharing_tags.shared")
29
+
30
+ _assert_vars: (vars...)->
31
+ for var_name in vars
32
+ if ! @[var_name]
33
+ arguments_list = ''
34
+ arguments_list += " #{var_name}: '#{@[var_name]}'" for arg, val in vars
35
+ throw new SharingTags.Error("Error could not initialize sharing class, with params: #{arguments_list}")
36
+
37
+ _user_agent: ->
38
+ window.navigator?.userAgent
@@ -1,39 +1,3 @@
1
- class @SharingTags.BaseShare
2
-
3
- url: null
4
- title: null
5
- description: null
6
-
7
- constructor: ({@url, @title, @description})->
8
- @_assert_vars 'url'
9
-
10
- _open_popup: (api_url, params)->
11
- share_url = if params then "#{api_url}?#{$.param(params)}" else api_url
12
- share_window = window.open share_url, 'Sharing', 'width=740,height=440'
13
-
14
- clearInterval(@interval)
15
- iteration = 0
16
- @interval = setInterval((=>
17
- iteration++
18
- if @_checkSharing(share_url, share_window, iteration)
19
- clearInterval @interval
20
- jQuery("body").trigger("sharing_tags.shared") if jQuery
21
- ), 500)
22
-
23
- _checkSharing: (share_url, share_window, iteration)=>
24
- # console.log("check desktop sharing", share_url, share_window, iteration)
25
- share_window?.closed || iteration >= 15
26
-
27
- _after_callback: =>
28
- jQuery?("body").trigger("sharing_tags.shared")
29
-
30
- _assert_vars: (vars...)->
31
- for var_name in vars
32
- if ! @[var_name]
33
- arguments_list = ''
34
- arguments_list += " #{var_name}: '#{@[var_name]}'" for arg, val in vars
35
- throw new SharingTags.Error("Error could not initialize sharing class, with params: #{arguments_list}")
36
-
37
1
  class @SharingTags.FacebookShare extends @SharingTags.BaseShare
38
2
 
39
3
  # available providers: sharer, fb_ui, dialog
@@ -44,7 +8,7 @@ class @SharingTags.FacebookShare extends @SharingTags.BaseShare
44
8
  provider: null
45
9
 
46
10
  constructor: ({@app_id, @return_url, @provider})->
47
- @provider = @_detect_provider() if !@provider
11
+ @provider = @detect_provider() if !@provider
48
12
 
49
13
  # todo: throw error for invalid provider
50
14
  @constructor.init() if @provider is 'fb_ui' and not FB?
@@ -83,10 +47,11 @@ class @SharingTags.FacebookShare extends @SharingTags.BaseShare
83
47
  @_open_popup("http://www.facebook.com/dialog/share", href: @url, redirect_uri: @return_url, app_id: @app_id, display: display)
84
48
 
85
49
 
86
- _detect_provider: ->
87
- # todo: detect provider by params
88
- # try fb_ui url, app_id
89
- # try dialog url, return_url
90
- # try sharer url
91
-
92
- @constructor.default_provider
50
+ detect_provider: ->
51
+ if @_user_agent().match('CriOS')
52
+ "sharer"
53
+ else if @app_id
54
+ if @return_url then "dialog"
55
+ else "fb_ui"
56
+ else
57
+ "sharer"
@@ -0,0 +1,13 @@
1
+ class @SharingTags.VkontakteShare extends @SharingTags.BaseShare
2
+
3
+ constructor: ({@url, @title, @description, @image})->
4
+ super
5
+
6
+ share: ->
7
+ @_open_popup(
8
+ "http://vk.com/share.php",
9
+ url: @url,
10
+ title: @title,
11
+ description: @description,
12
+ image: @image
13
+ )
@@ -9,6 +9,11 @@ class @SharingTags
9
9
 
10
10
  class @Share
11
11
 
12
+ @line: ({url}, callback) ->
13
+ url = 'http://www.jetradar.co.th/promo/hotel?lang=th'
14
+ share_url = "http://line.me/R/msg/text/?#{encodeURIComponent(url)}"
15
+ @_share(null, force_url: share_url, callback)
16
+
12
17
  @facebook: ({url, app_id}, callback) ->
13
18
  if app_id
14
19
  social_share = new SharingTags.FacebookShare url: url, app_id: app_id
@@ -20,13 +25,8 @@ class @SharingTags
20
25
  @_share("http://twitter.com/intent/tweet", text: message, url: url, callback)
21
26
 
22
27
  @vkontakte: ({title, url, message, image}, callback) ->
23
- @_share('http://vk.com/share.php',
24
- url: url,
25
- title: title,
26
- description: message,
27
- image: image,
28
- callback
29
- )
28
+ social_share = new SharingTags.VkontakteShare url: url, title: title, description: message, image: image
29
+ social_share.share()
30
30
 
31
31
  @google: ({url}, callback) ->
32
32
  @_share("https://plus.google.com/share", url: url, callback)
@@ -45,7 +45,10 @@ class @SharingTags
45
45
  )
46
46
 
47
47
  @_share: (api_url, params, callback) ->
48
- share_url = if params then "#{api_url}?#{$.param(params)}" else api_url
48
+ share_url = if params.force_url
49
+ params.force_url
50
+ else
51
+ if params then "#{api_url}?#{$.param(params)}" else api_url
49
52
  share_window = window.open share_url, 'Sharing', 'width=740,height=440'
50
53
 
51
54
  clearInterval(@interval)
@@ -1,4 +1,6 @@
1
1
  #= require sharing_tags/share
2
+ #= require sharing_tags/share/base
2
3
  #= require sharing_tags/share/facebook
4
+ #= require sharing_tags/share/vkontakte
3
5
  #= require sharing_tags/links
4
6
  #= require sharing_tags/init
@@ -0,0 +1,2 @@
1
+ = link_to_line_share do
2
+ = image_tag 'sharing_tags/icons/vkontakte.svg'
@@ -19,3 +19,7 @@ meta property="og:type" content="website"
19
19
  - if meta.image_size
20
20
  meta property="og:image:width" content=meta.image_size.first
21
21
  meta property="og:image:height" content=meta.image_size.last
22
+
23
+ - if meta.app_id
24
+ meta property="fb:app_id" content=meta.app_id
25
+
@@ -15,7 +15,6 @@ module SharingTags
15
15
  desc: "Copy links partial"
16
16
 
17
17
  def copy_initializer_file
18
-
19
18
  if File.exists?("config/initializers/sharing_tags.rb")
20
19
  say_skipped("create initializer sharing_tags.rb")
21
20
  else
@@ -25,44 +24,47 @@ module SharingTags
25
24
 
26
25
  def add_javascripts
27
26
  source_file = "app/assets/javascripts/application.js"
28
- skip_js = false
29
-
30
- # todo: move to method
31
- if File.exists? source_file
32
- original_js = File.binread(source_file)
33
-
34
- update_application_js = ->(source) do
35
- if original_js.include?(source)
36
- skip_js = true
37
- else
38
- insert_into_file source_file, "\n//= require '#{source}'", :after => %r{\Z}
39
- end
40
- end
27
+ match_string = "sharing_tags"
41
28
 
42
- update_application_js["sharing_tags/share"]
43
- update_application_js["sharing_tags/links"]
44
- else
45
- skip_js = true
29
+ insert_into_file_if source_file, match_string, after: %r{\z} do
30
+ "\n//= require #{match_string}"
46
31
  end
47
-
48
- say_skipped("insert into #{source_file}") if skip_js
49
32
  end
50
33
 
51
34
  def add_styles
52
35
  source_file = "app/assets/stylesheets/application.css"
36
+ match_string = "sharing_tags"
53
37
 
54
- if File.exists? source_file
55
- insert_into_file source_file, :before => "*/" do
56
- "\n *= require 'sharing_tags'\n\n"
57
- end
58
- else
59
- say_skipped("insert into #{source_file}")
38
+ insert_into_file_if source_file, match_string, before: "*/" do
39
+ "*= require #{match_string}\n "
60
40
  end
61
41
  end
62
42
 
63
43
  def add_layout
64
- # todo add = render_sharing_tags to head
65
- # and add = sharing_tags_buttons to body
44
+ ## slim
45
+ source_file = "app/views/layouts/application.html.slim"
46
+ render_meta_tags = "render_sharing_tags"
47
+ buttons_tags = "sharing_tags_buttons"
48
+
49
+ insert_into_file_if(source_file, render_meta_tags, before: "body") do
50
+ " \n = #{render_meta_tags}\n\n "
51
+ end
52
+
53
+ insert_into_file_if(source_file, buttons_tags, after: "body") do
54
+ "\n = #{buttons_tags}\n"
55
+ end
56
+
57
+ ## erb
58
+ source_file = "app/views/layouts/application.html.erb"
59
+ insert_into_file_if(source_file, render_meta_tags, before: "</head>") do
60
+ " <%= #{render_meta_tags} %>\n"
61
+ end
62
+
63
+ insert_into_file_if(source_file, buttons_tags, after: "<body>") do
64
+ "\n <%= #{buttons_tags} %>\n"
65
+ end
66
+
67
+ ## todo: haml
66
68
  end
67
69
 
68
70
  def display_post_install
@@ -74,6 +76,21 @@ module SharingTags
74
76
  def say_skipped(message)
75
77
  say_status("skipped", message, :yellow)
76
78
  end
79
+
80
+ def insert_into_file_if(source_file, find_string, **insert_into_file_options, &insert_into_file_block)
81
+ source_file_path = File.expand_path(source_file, destination_root)
82
+
83
+ if File.exists? source_file_path
84
+ source_content = File.binread(source_file_path)
85
+ if not source_content.include? find_string
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
90
+ else
91
+ # say_skipped("not found #{source_file}")
92
+ end
93
+ end
77
94
  end
78
95
  end
79
96
  end
@@ -6,7 +6,7 @@ module SharingTags::ActionView::AssetHelper
6
6
  options.merge!(digested: false)
7
7
 
8
8
  add_image_to_non_digest_list(path)
9
- asset_url(path, options)
9
+ url_to_image(path, options)
10
10
  end
11
11
 
12
12
  # redefine method Sprockets::Rails::Helper
@@ -3,8 +3,11 @@ module SharingTags::ActionView::ButtonHelper
3
3
  def sharing_tags_buttons(*networks)
4
4
  options = networks.extract_options!
5
5
  networks = SharingTags::Network.lists if networks.empty?
6
- # todo: add params for switching context
7
- render template: "sharing_tags/buttons", locals: {networks: networks, options: options}
6
+
7
+ # switching context
8
+ SharingTags.config.switch_context(*options[:context]) if options[:context].present?
9
+
10
+ render template: "sharing_tags/buttons.html.slim", locals: {networks: networks, options: options}
8
11
  end
9
12
 
10
13
  def link_to_facebook_share(name_or_options = nil, &block)
@@ -15,6 +18,10 @@ module SharingTags::ActionView::ButtonHelper
15
18
  share_link_to name_or_options, :vkontakte, [:title, :description, :image], &block
16
19
  end
17
20
 
21
+ def link_to_line_share(name_or_options = nil, &block)
22
+ share_link_to name_or_options, :line, [], &block
23
+ end
24
+
18
25
  def link_to_google_share(name_or_options = nil, &block)
19
26
  share_link_to name_or_options, :google, [], &block
20
27
  end
@@ -5,6 +5,6 @@ module SharingTags::ActionView::MetaHelper
5
5
  end
6
6
 
7
7
  def render_sharing_tags
8
- render template: "sharing_tags/meta_tags"
8
+ render template: "sharing_tags/meta_tags.html.slim"
9
9
  end
10
10
  end
@@ -42,6 +42,12 @@ module SharingTags
42
42
  end
43
43
  end
44
44
 
45
+ def line(&block)
46
+ (@networks[:line] ||= Network.new(:line, self)).tap do |line|
47
+ line.instance_exec(&block) if block_given?
48
+ end
49
+ end
50
+
45
51
  def odnoklassniki(&block)
46
52
  (@networks[:odnoklassniki] ||= Network.new(:odnoklassniki, self)).tap do |vkontakte|
47
53
  vkontakte.instance_exec(&block) if block_given?
@@ -6,9 +6,10 @@ module SharingTags
6
6
  class Error < StandardError
7
7
  end
8
8
 
9
- NETWORKS = %i( facebook google twitter vkontakte odnoklassniki )
9
+ NETWORKS = %i( facebook google twitter vkontakte odnoklassniki line)
10
10
 
11
- ATTRIBUTES = %i( share_url title description image_url image page_url share_url_params link_params )
11
+ ATTRIBUTES = %i( share_url title description page_url share_url_params link_params
12
+ image_url image digested_image digested_image_url )
12
13
 
13
14
  attr_reader :name, :attributes
14
15
 
@@ -51,7 +52,7 @@ module SharingTags
51
52
  new_image, size, content_type = arguments
52
53
 
53
54
  if options[:digested] == false && !block_given?
54
- block = lambda { without_digest_asset_url(new_image) }
55
+ block = proc { without_digest_asset_url(new_image) }
55
56
  end
56
57
 
57
58
  # todo: add another class for storing image
@@ -68,6 +69,15 @@ module SharingTags
68
69
  # todo: add image_size
69
70
  # todo: add_image_type
70
71
 
72
+ def digested_image_url(*arguments, &block)
73
+ options = arguments.extract_options!
74
+ options.merge!(:digested => false)
75
+
76
+ wrap_block = proc { |*args| without_digest_asset_url(block.call(*args)) } if block_given?
77
+ image_url(*arguments, options, &wrap_block)
78
+ end
79
+ alias :digested_image :digested_image_url
80
+
71
81
  def page_url(new_url = nil, &block)
72
82
  attributes[:page_url] = store_value(new_url, &block)
73
83
  end
@@ -1,3 +1,3 @@
1
1
  module SharingTags
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
data/lib/sharing_tags.rb CHANGED
@@ -1,4 +1,4 @@
1
- require "sharing_tags/engine"
1
+ require "slim-rails"
2
2
 
3
3
  module SharingTags
4
4
 
data/sharing_tags.gemspec CHANGED
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
20
20
 
21
21
  spec.add_dependency 'rails', '~> 4.0'
22
22
  spec.add_dependency 'hashie', '~> 3.4'
23
- spec.add_dependency 'slim', '~> 3.0'
23
+ spec.add_dependency 'slim-rails', '~> 3.0'
24
24
  spec.add_dependency 'coffee-script', '~> 2.3'
25
25
  spec.add_dependency 'non-stupid-digest-assets', '~> 1.0'
26
26
 
@@ -36,7 +36,7 @@ RSpec.describe MainController, :type => :controller do
36
36
  it "expect render meta_tags" do
37
37
  expect(response.status).to eq(200)
38
38
  expect(response).to render_template(:index)
39
- expect(response).to render_template('sharing_tags/meta_tags')
39
+ expect(response).to render_template('sharing_tags/meta_tags.html.slim')
40
40
  end
41
41
 
42
42
  it "expect update default data for facebook" do
@@ -95,7 +95,7 @@ RSpec.describe MainController, :type => :controller do
95
95
  it "expect render meta_tags" do
96
96
  expect(response.status).to eq(200)
97
97
  expect(response).to render_template(:profile)
98
- expect(response).to render_template('sharing_tags/meta_tags')
98
+ expect(response).to render_template('sharing_tags/meta_tags.html.slim')
99
99
  end
100
100
  end
101
101
 
@@ -32,30 +32,112 @@ describe SharingTags::Generators::InstallGenerator, type: :generator do
32
32
  end
33
33
  end
34
34
 
35
- describe 'assets' do
35
+ describe 'assets:javascripts' do
36
36
 
37
- describe "javascripts" do
37
+ describe "application.js" do
38
+ let(:file_path) { "app/assets/javascripts/application.js" }
39
+ subject { file file_path }
40
+
41
+ before do
42
+ touch_file file_path
43
+ run_generator
44
+ end
45
+
46
+ it "expect added require sharing_tags " do
47
+ generator_command = '= require sharing_tags'
48
+ is_expected.to contain(generator_command)
49
+ end
50
+ end
51
+
52
+ describe "application.coffee" do
38
53
  pending
39
54
  end
55
+ end
56
+
57
+ describe 'assets:stylesheets' do
40
58
 
41
- describe "stylesheets" do
59
+ describe "application.css" do
60
+ let(:file_path) { "app/assets/stylesheets/application.css" }
61
+ subject { file file_path }
42
62
 
43
- it "expect add require styles for existing file"
44
- it "expect skip if style added "
45
- it "expect skip if file doesnot exists"
63
+ before do
64
+ create_file file_path, "/**/"
65
+ subject
66
+ run_generator
67
+ end
46
68
 
69
+ it "expect added require sharing_tags " do
70
+ generator_command = '= require sharing_tags'
71
+ is_expected.to contain(generator_command)
72
+ end
47
73
  end
48
74
 
49
- # subject { file 'app/controllers/sessions_controller.rb'}
75
+ describe "application.sass" do
76
+ pending
77
+ end
50
78
 
51
- # it { is_expected_to have_method :index }
79
+ describe "application.scss" do
80
+ pending
81
+ end
52
82
  end
53
83
 
54
- describe 'view' do
55
- pending
56
- # subject { file 'app/views/sessions/new.html.erb'}
57
- #
58
- # it { is_expected_to have_correct_syntax }
84
+ describe 'view:layouts' do
85
+ let(:file_path) { "app/views/layouts/application.html.slim" }
86
+ subject { file file_path }
87
+
88
+ describe "application.html.slim" do
89
+ let(:layout) { %{
90
+ html
91
+ header
92
+ title Some title
93
+ body
94
+ p Text block
95
+ } }
96
+
97
+ before do
98
+ create_file file_path, layout
99
+ run_generator
100
+ end
101
+
102
+ it "expect added render_sharing_tags " do
103
+ generator_command = '= render_sharing_tags'
104
+ is_expected.to contain(generator_command)
105
+ end
106
+
107
+ # it { is_expected.to have_correct_syntax }
108
+ end
109
+
110
+ describe "application.html.erb" do
111
+ before do
112
+ create_file file_path, layout
113
+ run_generator
114
+ end
115
+
116
+ subject { file file_path }
117
+
118
+ let(:layout) { %{
119
+ <html>
120
+ <head>
121
+ <title>Some title</title>
122
+ </head>
123
+ <body>
124
+ <p>Text block</p>
125
+ </body>
126
+ </html>
127
+ } }
128
+ let(:file_path) { "app/views/layouts/application.html.erb" }
129
+
130
+ it "expect added render_sharing_tags " do
131
+ generator_command = '<%= render_sharing_tags %>'
132
+ is_expected.to contain(generator_command)
133
+ end
134
+
135
+ it { is_expected.to have_correct_syntax }
136
+ end
137
+
138
+ describe "application.html.haml" do
139
+ pending
140
+ end
59
141
  end
60
142
 
61
143
  describe "after install" do
@@ -18,7 +18,7 @@ RSpec.describe SharingTags::ActionView::AssetHelper, :type => :helper do
18
18
  end
19
19
 
20
20
  it "expect return non digested url" do
21
- is_expected.to be_eql("http://test.host/image_path/image.png")
21
+ is_expected.to be_eql("http://test.host/images/image_path/image.png")
22
22
  end
23
23
 
24
24
  it "add to non digest gem" do
@@ -3,8 +3,7 @@
3
3
  "url": "http://full.url",
4
4
  "title": "Title full",
5
5
  "description": "Description",
6
- "app_id": "123",
7
- "return_url": "http://return.url"
6
+ "app_id": "123"
8
7
  },
9
8
 
10
9
  "partial": {
@@ -13,6 +12,14 @@
13
12
  "description": "Description"
14
13
  },
15
14
 
15
+ "returned": {
16
+ "url": "http://full.url",
17
+ "title": "Title full",
18
+ "description": "Description",
19
+ "app_id": "123",
20
+ "return_url": "http://return.url"
21
+ },
22
+
16
23
  "fb_ui": {
17
24
  "url": "http://fb_ui.url",
18
25
  "app_id": "123",
@@ -0,0 +1,8 @@
1
+ {
2
+ "full": {
3
+ "url": "http://full.url",
4
+ "title": "Title full",
5
+ "description": "Description",
6
+ "image": "http://image.url"
7
+ }
8
+ }
@@ -1,4 +1,5 @@
1
1
  #=require sharing_tags/share
2
+ #=require sharing_tags/share/base
2
3
  #=require sharing_tags/share/facebook
3
4
 
4
5
  fixture.preload("facebook.json")
@@ -155,3 +156,27 @@ describe "SharingTags.FacebookShare", ->
155
156
  @share._fb_ui()
156
157
  expect(@share.constructor.init).toHaveBeenCalled()
157
158
  expect(@share._fb_ui).toHaveBeenCalled()
159
+
160
+ describe "#detect_provider", ->
161
+
162
+ it "expect to receive sharer provider for iOS Chrome browser", ->
163
+ @share = new subject(@fb_fixture.full)
164
+ ios_chrome_agent = "Mozilla/5.0 (iPhone; U; CPU iPhone OS 5_1_1 like Mac OS X; en) AppleWebKit/534.46.0 (KHTML, like Gecko) CriOS/19.0.1084.60 Mobile/9B206 Safari/7534.48.3"
165
+ spyOn(@share, "_user_agent").andReturn ios_chrome_agent
166
+
167
+ expect(@share.detect_provider()).toBe "sharer"
168
+
169
+ it "expect to receive fb_ui provider for sharing with app_id params", ->
170
+ @share = new subject(@fb_fixture.full)
171
+ expect(@share.app_id).toBeDefined()
172
+ expect(@share.detect_provider()).toBe "fb_ui"
173
+
174
+ it "expect to receive dialog provider for sharing with app_id and return url params", ->
175
+ @share = new subject(@fb_fixture.returned)
176
+ expect(@share.app_id).toBeDefined()
177
+ expect(@share.return_url).toBeDefined()
178
+ expect(@share.detect_provider()).toBe "dialog"
179
+
180
+ it "expect to receive fb_ui provider for sharing with app_id params", ->
181
+ @share = new subject(@fb_fixture.partial)
182
+ expect(@share.detect_provider()).toBe "sharer"
@@ -0,0 +1,31 @@
1
+ #=require sharing_tags/share
2
+ #=require sharing_tags/share/base
3
+ #=require sharing_tags/share/vkontakte
4
+
5
+ fixture.preload("vkontakte.json")
6
+
7
+ describe "SharingTags.VkontakteShare", ->
8
+
9
+ subject = SharingTags.VkontakteShare
10
+
11
+ beforeEach ->
12
+ @vk_fixture = fixture.load("vkontakte.json")[0]
13
+
14
+ it "expect defined class", ->
15
+ expect( SharingTags ).toBeDefined()
16
+ expect( SharingTags.VkontakteShare ).toBeDefined()
17
+
18
+ describe "#share", ->
19
+ beforeEach ->
20
+ @vk = @vk_fixture.full
21
+ @share = new subject(@vk)
22
+
23
+ it "expect open popup", ->
24
+ spyOn(@share, "_open_popup")
25
+
26
+ @share.share()
27
+ expect(@share._open_popup).toHaveBeenCalled()
28
+ expect(@share._open_popup).toHaveBeenCalledWith(
29
+ "http://vk.com/share.php",
30
+ jasmine.objectContaining(url: @vk.url, image: @vk.image, title: @vk.title, description: @vk.description)
31
+ )
@@ -1,5 +1,18 @@
1
1
  module GeneratorSupport
2
2
 
3
+ def create_file(file_path, content = '')
4
+ full_file_path = File.expand_path(file_path, destination_root)
5
+ FileUtils.mkdir_p File.dirname(full_file_path)
6
+ File.write full_file_path, content
7
+ end
8
+
9
+ def touch_file(file_path)
10
+ full_file_path = File.expand_path(file_path, destination_root)
11
+
12
+ FileUtils.mkdir_p File.dirname(full_file_path)
13
+ FileUtils.touch full_file_path
14
+ end
15
+
3
16
  def cleanup_destination_root
4
17
  FileUtils.rm_rf destination_root
5
18
  end
@@ -13,6 +13,7 @@ RSpec.describe "sharing_tags/meta_tags", :type => :view do
13
13
  description "Facebook description"
14
14
  page_url "http://a.b"
15
15
  image_url "http://img.jpg", "100x200", "image/jpeg"
16
+ app_id "12345"
16
17
  end
17
18
  end
18
19
  end
@@ -26,6 +27,7 @@ RSpec.describe "sharing_tags/meta_tags", :type => :view do
26
27
  expect(rendered).to have_tag "meta", with: {property: "og:image:width", content: "100"}
27
28
  expect(rendered).to have_tag "meta", with: {property: "og:image:height",content: "200"}
28
29
  expect(rendered).to have_tag "meta", with: {property: "og:url", content: "http://a.b"}
30
+ expect(rendered).to have_tag "meta", with: {property: "fb:app_id", content: "12345"}
29
31
  end
30
32
  end
31
33
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sharing_tags
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Anatoliy Kovalchuk
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-04-29 00:00:00.000000000 Z
11
+ date: 2015-05-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -39,7 +39,7 @@ dependencies:
39
39
  - !ruby/object:Gem::Version
40
40
  version: '3.4'
41
41
  - !ruby/object:Gem::Dependency
42
- name: slim
42
+ name: slim-rails
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
45
  - - "~>"
@@ -287,14 +287,17 @@ files:
287
287
  - app/assets/images/sharing_tags/icons/twitter.svg
288
288
  - app/assets/images/sharing_tags/icons/vkontakte.svg
289
289
  - app/assets/javascripts/sharing_tags.js.coffee
290
- - app/assets/javascripts/sharing_tags/init.js.coffee
290
+ - app/assets/javascripts/sharing_tags/init.js.coffee.erb
291
291
  - app/assets/javascripts/sharing_tags/links.js.coffee
292
292
  - app/assets/javascripts/sharing_tags/share.js.coffee
293
+ - app/assets/javascripts/sharing_tags/share/base.js.coffee
293
294
  - app/assets/javascripts/sharing_tags/share/facebook.coffee
295
+ - app/assets/javascripts/sharing_tags/share/vkontakte.js.coffee
294
296
  - app/assets/stylesheets/sharing_tags.css.sass
295
297
  - app/assets/stylesheets/sharing_tags/icons.css.sass
296
298
  - app/views/sharing_tags/button/_facebook.html.slim
297
299
  - app/views/sharing_tags/button/_google.html.slim
300
+ - app/views/sharing_tags/button/_line.html.slim
298
301
  - app/views/sharing_tags/button/_odnoklassniki.html.slim
299
302
  - app/views/sharing_tags/button/_twitter.html.slim
300
303
  - app/views/sharing_tags/button/_vkontakte.html.slim
@@ -382,7 +385,9 @@ files:
382
385
  - spec/helpers/button_helper_spec.rb
383
386
  - spec/helpers/meta_tags_helper_spec.rb
384
387
  - spec/javascripts/fixtures/facebook.json
388
+ - spec/javascripts/fixtures/vkontakte.json
385
389
  - spec/javascripts/sharing_tags/share/facebook_share_spec.coffee
390
+ - spec/javascripts/sharing_tags/share/vkontakte_share_spec.coffee
386
391
  - spec/javascripts/sharing_tags/sharing_tags_spec.coffee
387
392
  - spec/javascripts/spec_helper.coffee
388
393
  - spec/models/configuration_spec.rb
@@ -414,7 +419,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
414
419
  version: '0'
415
420
  requirements: []
416
421
  rubyforge_project:
417
- rubygems_version: 2.2.2
422
+ rubygems_version: 2.4.5
418
423
  signing_key:
419
424
  specification_version: 4
420
425
  summary: Generate sharing tags for different contexts
@@ -479,7 +484,9 @@ test_files:
479
484
  - spec/helpers/button_helper_spec.rb
480
485
  - spec/helpers/meta_tags_helper_spec.rb
481
486
  - spec/javascripts/fixtures/facebook.json
487
+ - spec/javascripts/fixtures/vkontakte.json
482
488
  - spec/javascripts/sharing_tags/share/facebook_share_spec.coffee
489
+ - spec/javascripts/sharing_tags/share/vkontakte_share_spec.coffee
483
490
  - spec/javascripts/sharing_tags/sharing_tags_spec.coffee
484
491
  - spec/javascripts/spec_helper.coffee
485
492
  - spec/models/configuration_spec.rb
@@ -1,2 +0,0 @@
1
-
2
- @SharingTags.FacebookShare.init()