sharing_tags 0.0.4 → 0.0.5

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: 3fb8c1d07875574b3d1b8ffdc8fffaf3efc75eba
4
- data.tar.gz: 30e8054db58fe3489b38be7ed6e37c05756132aa
3
+ metadata.gz: 15a3570cb3592d651f7f2381b4afe5177ee9d8b6
4
+ data.tar.gz: b4e3e9d2278551f4a82b82505d721bbc61a5a87b
5
5
  SHA512:
6
- metadata.gz: bd42efa3c9565c6bac5dfb98fe4e0f8e85c784f1943b548d6586d8e8959c8d1975531e26b72655cadaedb16492619aa1e6587fda2d543ff44528e8592457ecbc
7
- data.tar.gz: 5c5271f36b61cdb02900053639cfcabfd834d861d54b6c6bf9997634b9a0743736f949683cf02f55f8f36271bfaf2292a97ded35bc0af4b0f2feb4d3916b1f95
6
+ metadata.gz: 7c8b64a0c2b281dd60369be5ce4151be7bd8a8f503547b9f5d1468e2f71398294874515bbe0e8ed0d712e8431ee8f15bd6ba5396c57af3970bf75aed209d8316
7
+ data.tar.gz: b015f781dce51ac9718562cce9180ff8551b6d4aa6cc91739e9b7d765e362ef6da957b156a5743bb352dde4bb83b4481bd087785009e2c4ac61be3fb456ef269
data/Guardfile CHANGED
@@ -4,6 +4,8 @@ guard 'rspec', cmd: "bundle exec rspec" do
4
4
  watch(%r{^spec/.+_spec\.rb$})
5
5
  watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
6
6
 
7
+ watch(%r{^lib/sharing_tags/(.+)\.rb$}) { |m| "spec/models/#{m[1]}_spec.rb" }
8
+
7
9
  end
8
10
 
9
11
  guard :teaspoon do
@@ -11,5 +13,5 @@ guard :teaspoon do
11
13
  watch(%r{^app/assets/javascripts/sharing_tags/(.+).coffee}) { |m| "#{m[1]}_spec" }
12
14
 
13
15
  # Specs / Helpers
14
- watch(%r{^spec/javascripts/**/(.*)})
16
+ watch(%r{^spec/javascripts/(.+)})
15
17
  end
data/README.md CHANGED
@@ -1,4 +1,4 @@
1
- # sharing_tags [![Gem Version](https://badge.fury.io/rb/sharing_tags.svg)](http://badge.fury.io/rb/sharing_tags) ![Build Status](https://secure.travis-ci.org/Kr00lIX/sharing_tags.svg?branch=master) ![Code Climate](https://codeclimate.com/github/Kr00lIX/sharing_tags/badges/gpa.svg) ![Security](https://hakiri.io/github/Kr00lIX/sharing_tags/master.svg) [![Coverage Status](https://coveralls.io/repos/Kr00lIX/sharing_tags/badge.svg)](https://coveralls.io/r/Kr00lIX/sharing_tags)
1
+ # sharing_tags [![Gem Version](https://badge.fury.io/rb/sharing_tags.svg)](http://badge.fury.io/rb/sharing_tags) ![Build Status](https://secure.travis-ci.org/Kr00lIX/sharing_tags.svg?branch=master) ![Code Climate](https://codeclimate.com/github/Kr00lIX/sharing_tags/badges/gpa.svg) [![Coverage Status](https://coveralls.io/repos/Kr00lIX/sharing_tags/badge.svg)](https://coveralls.io/r/Kr00lIX/sharing_tags)
2
2
 
3
3
 
4
4
  **sharing_tags** is a gem for adding social sharing buttons to your Rails app.
data/Todo.md ADDED
@@ -0,0 +1,11 @@
1
+ # TODO
2
+
3
+ * Write specs
4
+ * Run js and ruby specs by default rake task
5
+ * Add default values to image networks
6
+ * Correct merge values in default context and defined
7
+ * Define network list
8
+ * Render icons with links
9
+ * Add to install task sample of view and require assets
10
+ * Add recommendation about image size and length of text
11
+ * Add version to sharing tags: append ?version=1 to links and assets
@@ -12,7 +12,9 @@ module SharingTags
12
12
 
13
13
 
14
14
  module ActionView
15
- autoload :Helpers, 'sharing_tags/action_view/helpers'
15
+ autoload :MetaHelper, 'sharing_tags/action_view/meta_helper'
16
+ autoload :ButtonHelper, 'sharing_tags/action_view/button_helper'
17
+ autoload :AssetHelper, 'sharing_tags/action_view/asset_helper'
16
18
  end
17
19
 
18
20
  module ActionController
@@ -0,0 +1,37 @@
1
+ require "non-stupid-digest-assets"
2
+
3
+ module SharingTags::ActionView::AssetHelper
4
+
5
+ def without_digest_asset_url(path, options = {})
6
+ options.merge!(digested: false)
7
+
8
+ add_image_to_non_digest_list(path)
9
+ asset_url(path, options)
10
+ end
11
+
12
+ # redefine method Sprockets::Rails::Helper
13
+ # Computes asset path to public directory.
14
+ #
15
+ # Override this method for non digested assets
16
+ #
17
+ def compute_asset_path(path, options = {})
18
+ digested = options.delete(:digested)
19
+ digested = true if digested.nil?
20
+
21
+ if digest_path = asset_digest_path(path, options)
22
+ path = digest_path if digested && digest_assets
23
+ path += "?body=1" if options[:debug]
24
+ File.join(assets_prefix || "/", path)
25
+ else
26
+ super
27
+ end
28
+ end
29
+
30
+ private
31
+
32
+ def add_image_to_non_digest_list(asset_name)
33
+ return if ::NonStupidDigestAssets.whitelist.include?(asset_name)
34
+ ::NonStupidDigestAssets.whitelist += [ asset_name ]
35
+ end
36
+
37
+ end
@@ -1,13 +1,4 @@
1
- module SharingTags::ActionView::Helpers
2
-
3
- def sharing_tags
4
- SharingTags.config.within_context_params(self)
5
- end
6
-
7
- def render_sharing_tags
8
- logger.debug "SharingTags: Render meta tags context=#{SharingTags.config.current_context.name}, params=#{sharing_tags.to_hash.inspect}"
9
- render template: "sharing_tags/meta_tags"
10
- end
1
+ module SharingTags::ActionView::ButtonHelper
11
2
 
12
3
  def link_to_facebook_share(name = "Facebook", &block)
13
4
  share_link_to name, :facebook, [], &block
@@ -48,5 +39,4 @@ module SharingTags::ActionView::Helpers
48
39
  link_to name_or_options, params.page_url, data: data_attrs, role: "sharing_tags_share", target: "_blank", &block
49
40
  end
50
41
  end
51
-
52
42
  end
@@ -0,0 +1,10 @@
1
+ module SharingTags::ActionView::MetaHelper
2
+
3
+ def sharing_tags
4
+ SharingTags.config.within_context_params(self)
5
+ end
6
+
7
+ def render_sharing_tags
8
+ render template: "sharing_tags/meta_tags"
9
+ end
10
+ end
@@ -3,6 +3,8 @@ module SharingTags
3
3
 
4
4
  NETWORKS = %i{ google facebook twitter }
5
5
 
6
+ attr_accessor :running_context
7
+
6
8
  def initialize
7
9
  clear!
8
10
  end
@@ -44,10 +46,6 @@ module SharingTags
44
46
  params
45
47
  end
46
48
 
47
- def running_context
48
- @running_context
49
- end
50
-
51
49
  def current_context
52
50
  @current_context || default_context
53
51
  end
@@ -1,6 +1,8 @@
1
1
  module SharingTags
2
2
  class Network
3
3
 
4
+ # todo: add default values
5
+
4
6
  class Error < StandardError
5
7
  end
6
8
 
@@ -19,6 +21,10 @@ module SharingTags
19
21
  def initialize(name, context = nil)
20
22
  @name = name
21
23
  @context = context
24
+ clear!
25
+ end
26
+
27
+ def clear!
22
28
  @attributes = {}
23
29
  @share_url_params = nil
24
30
  end
@@ -39,13 +45,22 @@ module SharingTags
39
45
  attributes[:description] = store_value(value, &block)
40
46
  end
41
47
 
42
- def image_url(new_image = nil, size = nil, content_type = nil, &block)
48
+ # def image_url(new_image = nil, size = nil, content_type = nil, options, &block)
49
+ def image_url(*arguments, &block)
50
+ options = arguments.extract_options!
51
+ new_image, size, content_type = arguments
52
+
53
+ if options[:digested] == false && !block_given?
54
+ block = lambda { without_digest_asset_url(new_image) }
55
+ end
56
+
57
+ # todo: add another class for storing image
43
58
  attributes[:image] = store_value(new_image, &block)
44
59
 
45
60
  # add size and content type for block value
46
61
  size, content_type = new_image, size if block_given?
47
62
 
48
- attributes[:image_size] = store_value(size.split("x")) if size
63
+ attributes[:image_size] = store_value(size.split("x").map(&:to_i)) if size
49
64
  attributes[:image_content_type] = store_value(content_type) if content_type
50
65
  end
51
66
  alias :image :image_url
@@ -88,7 +103,8 @@ module SharingTags
88
103
 
89
104
  def get_value(value, context_params)
90
105
  if value.is_a?(Proc)
91
- if running_context = @context.configuraton.running_context
106
+
107
+ if @context && running_context = @context.configuraton.running_context
92
108
  # execute proc within the view context with context_params
93
109
  running_context.instance_exec(*context_params, &value)
94
110
  else
@@ -13,15 +13,17 @@ module SharingTags
13
13
 
14
14
  initializer "sharing_tags.configure_view_controller" do |app|
15
15
  ActiveSupport.on_load :action_view do
16
- include SharingTags::ActionView::Helpers
16
+ include SharingTags::ActionView::MetaHelper
17
+ include SharingTags::ActionView::ButtonHelper
18
+
19
+ # @note: load AssetHelper after sprockets helper
20
+ include Sprockets::Rails::Helper if defined?(Sprockets::Rails::Helper) && !include?(Sprockets::Rails::Helper)
21
+ include SharingTags::ActionView::AssetHelper
17
22
  end
18
23
 
19
24
  ActiveSupport.on_load :action_controller do
20
25
  include SharingTags::ActionController::Helpers
21
26
  include SharingTags::ActionController::Filters
22
-
23
- # todo add filter for clear context
24
- # append_filter :clear_context!
25
27
  end
26
28
  end
27
29
 
@@ -1,3 +1,3 @@
1
1
  module SharingTags
2
- VERSION = "0.0.4"
2
+ VERSION = "0.0.5"
3
3
  end
@@ -22,6 +22,7 @@ Gem::Specification.new do |spec|
22
22
  spec.add_dependency 'hashie', '~> 3.4'
23
23
  spec.add_dependency 'slim', '~> 3.0'
24
24
  spec.add_dependency 'coffee-script', '~> 2.3'
25
+ spec.add_dependency 'non-stupid-digest-assets', '~> 1.0'
25
26
 
26
27
  spec.add_development_dependency 'bundler', '~> 1.7'
27
28
  spec.add_development_dependency 'rake', '~> 10.0'
@@ -0,0 +1,29 @@
1
+ require "non-stupid-digest-assets"
2
+
3
+ RSpec.describe SharingTags::ActionView::AssetHelper, :type => :helper do
4
+
5
+ describe "#without_digest_asset_url" do
6
+ before do
7
+ SharingTags.configure do
8
+ image "http://img.png"
9
+ end
10
+ end
11
+
12
+ let(:image) { "image_path/image.png" }
13
+
14
+ subject { helper.without_digest_asset_url(image) }
15
+
16
+ it "expect exist method" do
17
+ expect(helper).to be_respond_to(:without_digest_asset_url)
18
+ end
19
+
20
+ it "expect return non digested url" do
21
+ is_expected.to be_eql("http://test.host/image_path/image.png")
22
+ end
23
+
24
+ it "add to non digest gem" do
25
+ NonStupidDigestAssets.whitelist = []
26
+ expect{ is_expected }.to change(::NonStupidDigestAssets, :whitelist)
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,36 @@
1
+
2
+ RSpec.describe SharingTags::ActionView::MetaHelper, :type => :helper do
3
+
4
+ describe "#sharing_tags" do
5
+ pending
6
+ end
7
+
8
+ describe "#render_sharing_tags" do
9
+ before do
10
+ SharingTags.configure do
11
+ title "Sharing title"
12
+ description "Sharing description"
13
+ page_url "http://a.b"
14
+ image "http://img.png"
15
+ end
16
+ end
17
+
18
+ it "generate open graph meta tags" do
19
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:title", content: "Sharing title"}
20
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:description", content: "Sharing description"}
21
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:image", content: "http://img.png"}
22
+ end
23
+
24
+ it "generate schema meta tags" do
25
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "name", content: "Sharing title"}
26
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "description", content: "Sharing description"}
27
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "image", content: "http://img.png"}
28
+ end
29
+
30
+ it "generate twitter card meta tags" do
31
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {name: "twitter:title", content: "Sharing title"}
32
+ expect(helper.render_sharing_tags).to have_tag "meta", with: {name: "twitter:description", content: "Sharing description"}
33
+ end
34
+ end
35
+
36
+ end
@@ -1,49 +1,5 @@
1
1
 
2
- RSpec.describe SharingTags::ActionView::Helpers, :type => :helper do
3
-
4
- before do
5
- SharingTags.configure do
6
- facebook do
7
- title "fb title"
8
- description "fb desc"
9
- share_url "http://c.d"
10
- page_url "#"
11
- image "http://img.png"
12
- end
13
- end
14
- end
15
-
16
- describe "#sharing_tags" do
17
- pending
18
- end
19
-
20
- describe "#render_sharing_tags" do
21
- before do
22
- SharingTags.configure do
23
- title "Sharing title"
24
- description "Sharing description"
25
- page_url "http://a.b"
26
- image "http://img.png"
27
- end
28
- end
29
-
30
- it "generate open graph meta tags" do
31
- expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:title", content: "Sharing title"}
32
- expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:description", content: "Sharing description"}
33
- expect(helper.render_sharing_tags).to have_tag "meta", with: {property: "og:image", content: "http://img.png"}
34
- end
35
-
36
- it "generate schema meta tags" do
37
- expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "name", content: "Sharing title"}
38
- expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "description", content: "Sharing description"}
39
- expect(helper.render_sharing_tags).to have_tag "meta", with: {itemprop: "image", content: "http://img.png"}
40
- end
41
-
42
- it "generate twitter card meta tags" do
43
- expect(helper.render_sharing_tags).to have_tag "meta", with: {name: "twitter:title", content: "Sharing title"}
44
- expect(helper.render_sharing_tags).to have_tag "meta", with: {name: "twitter:description", content: "Sharing description"}
45
- end
46
- end
2
+ RSpec.describe SharingTags::ActionView::ButtonHelper, :type => :helper do
47
3
 
48
4
  describe "#link_to_facebook_share" do
49
5
  before do
@@ -1,6 +1,89 @@
1
- describe SharingTags::Network do
1
+ module SharingTags
2
+
3
+ describe Network do
4
+ let!(:config) { Configuration.new }
5
+ let!(:context) { Context.new(:test, config) }
6
+ let!(:network) { Network.new(:test, context) }
7
+
8
+ after do
9
+ network.clear!
10
+ end
11
+
12
+ it "expect get's list of available networks" do
13
+ expect(Network.lists).to include(:facebook, :twitter, :google, :vkontakte)
14
+ end
15
+
16
+ it "expect network name is a test" do
17
+ expect(network.name).to be_eql(:test)
18
+ end
19
+
20
+ describe "#image" do
21
+ let(:running_class_context) do
22
+ Class.new do
23
+ def some_helper(path)
24
+ "helper/#{path}/done"
25
+ end
26
+
27
+ def without_digest_asset_url(path)
28
+ "non_digested/#{path}"
29
+ end
30
+ end
31
+ end
32
+
33
+ before do
34
+ config.running_context = running_class_context.new
35
+ end
36
+
37
+ subject { network.attributes_for.image}
38
+
39
+ it "add network image through asset_url " do
40
+ network.image "sharing/image.png"
41
+ is_expected.to be_present
42
+
43
+ is_expected.to be == "sharing/image.png"
44
+ end
45
+
46
+ it "define image by proc and run it in running_class_context" do
47
+ network.image { some_helper("sharing/image.png") }
48
+ is_expected.to be == "helper/sharing/image.png/done"
49
+ end
50
+
51
+ describe "non digested image" do
52
+ it "expect non digested path for full image attributes" do
53
+ network.image "sharing/image.png", "100x500", "image/jpeg", digested: false
54
+
55
+ expect(network.attributes_for.image).to be == "non_digested/sharing/image.png"
56
+ expect(network.attributes_for.image_size).to be == [100, 500]
57
+ expect(network.attributes_for.image_content_type).to be == "image/jpeg"
58
+ end
59
+
60
+ it "expect correct image path without content type" do
61
+ network.image "sharing/image.png", "100x500", digested: false
62
+
63
+ expect(network.attributes_for.image).to be == "non_digested/sharing/image.png"
64
+ expect(network.attributes_for.image_size).to be == [100, 500]
65
+ expect(network.attributes_for.image_content_type).to be_nil
66
+ end
67
+
68
+ it "expect correct image path without content type and size" do
69
+ network.image "sharing/image.png", digested: false
70
+
71
+ expect(network.attributes_for.image).to be == "non_digested/sharing/image.png"
72
+ expect(network.attributes_for.image_size).to be_nil
73
+ expect(network.attributes_for.image_content_type).to be_nil
74
+ end
75
+
76
+ it "expect correct image path without content type and size" do
77
+ network.image "sharing/image.png", digested: false
78
+
79
+ expect(network.attributes_for.image).to be == "non_digested/sharing/image.png"
80
+ expect(network.attributes_for.image_size).to be_nil
81
+ expect(network.attributes_for.image_content_type).to be_nil
82
+ end
83
+ end
84
+
85
+ end
2
86
 
3
- it "expect get's list of available networks" do
4
- expect(SharingTags::Network.lists).to include(:facebook, :twitter, :google, :vkontakte)
5
87
  end
88
+
6
89
  end
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.4
4
+ version: 0.0.5
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-07 00:00:00.000000000 Z
11
+ date: 2015-04-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -66,6 +66,20 @@ dependencies:
66
66
  - - "~>"
67
67
  - !ruby/object:Gem::Version
68
68
  version: '2.3'
69
+ - !ruby/object:Gem::Dependency
70
+ name: non-stupid-digest-assets
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.0'
76
+ type: :runtime
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '1.0'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: bundler
71
85
  requirement: !ruby/object:Gem::Requirement
@@ -266,6 +280,7 @@ files:
266
280
  - LICENSE.txt
267
281
  - README.md
268
282
  - Rakefile
283
+ - Todo.md
269
284
  - app/assets/javascripts/sharing_tags/links.js.coffee
270
285
  - app/assets/javascripts/sharing_tags/share.coffee
271
286
  - app/views/sharing_tags/_open_graphs.html.slim
@@ -278,7 +293,9 @@ files:
278
293
  - lib/sharing_tags.rb
279
294
  - lib/sharing_tags/action_controller/filters.rb
280
295
  - lib/sharing_tags/action_controller/helpers.rb
281
- - lib/sharing_tags/action_view/helpers.rb
296
+ - lib/sharing_tags/action_view/asset_helper.rb
297
+ - lib/sharing_tags/action_view/button_helper.rb
298
+ - lib/sharing_tags/action_view/meta_helper.rb
282
299
  - lib/sharing_tags/config.rb
283
300
  - lib/sharing_tags/configuration.rb
284
301
  - lib/sharing_tags/context.rb
@@ -344,6 +361,8 @@ files:
344
361
  - spec/dummy/vendor/assets/javascripts/.keep
345
362
  - spec/dummy/vendor/assets/stylesheets/.keep
346
363
  - spec/generators/install_generator_spec.rb
364
+ - spec/helpers/asset_helper_spec.rb
365
+ - spec/helpers/meta_tags_helper_spec.rb
347
366
  - spec/helpers/share_link_helper_spec.rb
348
367
  - spec/javascripts/sharing_tags/sharing_tags_spec.coffee
349
368
  - spec/javascripts/spec_helper.coffee
@@ -437,6 +456,8 @@ test_files:
437
456
  - spec/dummy/vendor/assets/javascripts/.keep
438
457
  - spec/dummy/vendor/assets/stylesheets/.keep
439
458
  - spec/generators/install_generator_spec.rb
459
+ - spec/helpers/asset_helper_spec.rb
460
+ - spec/helpers/meta_tags_helper_spec.rb
440
461
  - spec/helpers/share_link_helper_spec.rb
441
462
  - spec/javascripts/sharing_tags/sharing_tags_spec.coffee
442
463
  - spec/javascripts/spec_helper.coffee