sharing_tags 0.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.coveralls.yml +1 -0
- data/.gitignore +19 -0
- data/.rspec +4 -0
- data/.travis.yml +15 -0
- data/Gemfile +13 -0
- data/Guardfile +7 -0
- data/LICENSE.txt +22 -0
- data/README.md +112 -0
- data/Rakefile +14 -0
- data/app/assets/fonts/socicon-webfont.eot +0 -0
- data/app/assets/fonts/socicon-webfont.svg +112 -0
- data/app/assets/fonts/socicon-webfont.ttf +0 -0
- data/app/assets/fonts/socicon-webfont.woff +0 -0
- data/app/assets/fonts/socicon-webfont.woff2 +0 -0
- data/app/assets/javascripts/sharing_tags/links.js.coffee +11 -0
- data/app/assets/javascripts/sharing_tags/share.coffee +48 -0
- data/app/views/sharing_tags/_open_graphs.html.slim +21 -0
- data/app/views/sharing_tags/_schema_tags.html.slim +8 -0
- data/app/views/sharing_tags/_twitter_card.html.slim +20 -0
- data/app/views/sharing_tags/meta_tags.html.slim +16 -0
- data/bin/rspec +16 -0
- data/lib/generators/sharing_tags/install/install_generator.rb +18 -0
- data/lib/generators/sharing_tags/install/templates/initializer.rb +18 -0
- data/lib/generators/sharing_tags.rb +18 -0
- data/lib/sharing_tags/action_controller/filters.rb +13 -0
- data/lib/sharing_tags/action_controller/helpers.rb +7 -0
- data/lib/sharing_tags/action_view/helpers.rb +57 -0
- data/lib/sharing_tags/config.rb +33 -0
- data/lib/sharing_tags/configuration.rb +80 -0
- data/lib/sharing_tags/context.rb +96 -0
- data/lib/sharing_tags/engine.rb +6 -0
- data/lib/sharing_tags/network/facebook.rb +14 -0
- data/lib/sharing_tags/network.rb +102 -0
- data/lib/sharing_tags/railtie.rb +29 -0
- data/lib/sharing_tags/version.rb +3 -0
- data/lib/sharing_tags.rb +37 -0
- data/sharing_tags.gemspec +37 -0
- data/spec/controllers/main_controller_spec.rb +105 -0
- data/spec/dummy/.gitignore +16 -0
- data/spec/dummy/Gemfile +40 -0
- data/spec/dummy/Gemfile.lock +125 -0
- data/spec/dummy/README.rdoc +28 -0
- data/spec/dummy/Rakefile +6 -0
- data/spec/dummy/app/assets/images/.keep +0 -0
- data/spec/dummy/app/assets/javascripts/application.js +15 -0
- data/spec/dummy/app/assets/stylesheets/application.css +15 -0
- data/spec/dummy/app/controllers/application_controller.rb +5 -0
- data/spec/dummy/app/controllers/concerns/.keep +0 -0
- data/spec/dummy/app/controllers/main_controller.rb +25 -0
- data/spec/dummy/app/helpers/application_helper.rb +2 -0
- data/spec/dummy/app/mailers/.keep +0 -0
- data/spec/dummy/app/models/.keep +0 -0
- data/spec/dummy/app/models/concerns/.keep +0 -0
- data/spec/dummy/app/views/layouts/application.html.erb +15 -0
- data/spec/dummy/app/views/main/index.html.slim +16 -0
- data/spec/dummy/app/views/main/photo.html.slim +1 -0
- data/spec/dummy/app/views/main/profile.html.slim +1 -0
- data/spec/dummy/bin/bundle +3 -0
- data/spec/dummy/bin/rails +8 -0
- data/spec/dummy/bin/rake +8 -0
- data/spec/dummy/bin/spring +18 -0
- data/spec/dummy/config/application.rb +23 -0
- data/spec/dummy/config/boot.rb +4 -0
- data/spec/dummy/config/database.yml +25 -0
- data/spec/dummy/config/environment.rb +5 -0
- data/spec/dummy/config/environments/development.rb +37 -0
- data/spec/dummy/config/environments/production.rb +79 -0
- data/spec/dummy/config/environments/test.rb +38 -0
- data/spec/dummy/config/initializers/assets.rb +8 -0
- data/spec/dummy/config/initializers/backtrace_silencers.rb +7 -0
- data/spec/dummy/config/initializers/cookies_serializer.rb +3 -0
- data/spec/dummy/config/initializers/filter_parameter_logging.rb +4 -0
- data/spec/dummy/config/initializers/inflections.rb +16 -0
- data/spec/dummy/config/initializers/mime_types.rb +4 -0
- data/spec/dummy/config/initializers/session_store.rb +3 -0
- data/spec/dummy/config/initializers/sharing_tags.rb +62 -0
- data/spec/dummy/config/initializers/wrap_parameters.rb +14 -0
- data/spec/dummy/config/locales/en.yml +23 -0
- data/spec/dummy/config/routes.rb +61 -0
- data/spec/dummy/config/secrets.yml +22 -0
- data/spec/dummy/config.ru +4 -0
- data/spec/dummy/db/seeds.rb +7 -0
- data/spec/dummy/lib/assets/.keep +0 -0
- data/spec/dummy/lib/tasks/.keep +0 -0
- data/spec/dummy/log/.keep +0 -0
- data/spec/dummy/public/404.html +67 -0
- data/spec/dummy/public/422.html +67 -0
- data/spec/dummy/public/500.html +66 -0
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/robots.txt +5 -0
- data/spec/dummy/vendor/assets/javascripts/.keep +0 -0
- data/spec/dummy/vendor/assets/stylesheets/.keep +0 -0
- data/spec/generators/install_generator_spec.rb +50 -0
- data/spec/helpers/share_link_helper_spec.rb +185 -0
- data/spec/models/configuration_spec.rb +180 -0
- data/spec/models/context_spec.rb +28 -0
- data/spec/models/network_spec.rb +6 -0
- data/spec/models/running_in_context_spec.rb +57 -0
- data/spec/spec_helper.rb +41 -0
- data/spec/support/generator_support.rb +11 -0
- data/spec/views/facebook_meta_tags_erb_spec.rb +60 -0
- data/spec/views/meta_tags_erb_spec.rb +67 -0
- metadata +409 -0
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
/ Open graph markup for Facebook
|
|
2
|
+
= render "sharing_tags/open_graphs", meta: sharing_tags.facebook if sharing_tags.facebook.present?
|
|
3
|
+
|
|
4
|
+
/ Twitter Card data
|
|
5
|
+
= render "sharing_tags/twitter_card", meta: sharing_tags.twitter if sharing_tags.twitter.present?
|
|
6
|
+
|
|
7
|
+
/ Schema.org markup for Google+
|
|
8
|
+
= render "sharing_tags/schema_tags", meta: sharing_tags.google if sharing_tags.google.present?
|
|
9
|
+
|
|
10
|
+
/ Vkontakte https://vk.com/dev/share_details
|
|
11
|
+
/ TODO:
|
|
12
|
+
/link rel="image_src" href="/site-preview.jpg"
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
/meta name=”description” content=”155 characters of message matching text with a call to action goes here”
|
|
16
|
+
/<title>Up to 70 Characters of Keyword-relevant text here</title>
|
data/bin/rspec
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
#!/usr/bin/env ruby
|
|
2
|
+
#
|
|
3
|
+
# This file was generated by Bundler.
|
|
4
|
+
#
|
|
5
|
+
# The application 'rspec' is installed as part of a gem, and
|
|
6
|
+
# this file is here to facilitate running it.
|
|
7
|
+
#
|
|
8
|
+
|
|
9
|
+
require 'pathname'
|
|
10
|
+
ENV['BUNDLE_GEMFILE'] ||= File.expand_path("../../Gemfile",
|
|
11
|
+
Pathname.new(__FILE__).realpath)
|
|
12
|
+
|
|
13
|
+
require 'rubygems'
|
|
14
|
+
require 'bundler/setup'
|
|
15
|
+
|
|
16
|
+
load Gem.bin_path('rspec-core', 'rspec')
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
require 'rails/generators'
|
|
2
|
+
|
|
3
|
+
module SharingTags
|
|
4
|
+
module Generators
|
|
5
|
+
class InstallGenerator < Rails::Generators::Base
|
|
6
|
+
|
|
7
|
+
source_root File.expand_path('../templates', __FILE__)
|
|
8
|
+
|
|
9
|
+
def copy_initializer_file
|
|
10
|
+
template 'initializer.rb', 'config/initializers/sharing_tags.rb'
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# todo: add javascript files to applications.js
|
|
14
|
+
# todo add styles application.css
|
|
15
|
+
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# This file was generated by the `rails generate sharing_tags:install` command.
|
|
2
|
+
|
|
3
|
+
SharingTags.configure do
|
|
4
|
+
|
|
5
|
+
# global configuration
|
|
6
|
+
title "Global site title"
|
|
7
|
+
description "Global site description"
|
|
8
|
+
page_url { root_url }
|
|
9
|
+
image { image_url('img.jpg') }
|
|
10
|
+
|
|
11
|
+
# # for switch context call `sharing_tags.switch_context_to(:user)` in controller action
|
|
12
|
+
# context :user do
|
|
13
|
+
# title "User site title"
|
|
14
|
+
# description "User site description"
|
|
15
|
+
# page_url { profile_url }
|
|
16
|
+
# end
|
|
17
|
+
|
|
18
|
+
end
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
# Weirdly named generators namespace (should be `RSpec`) for compatability with
|
|
2
|
+
# rails loading.
|
|
3
|
+
module SharingTags
|
|
4
|
+
# @private
|
|
5
|
+
module Generators
|
|
6
|
+
# @private
|
|
7
|
+
class Base < ::Rails::Generators::NamedBase
|
|
8
|
+
|
|
9
|
+
# def self.source_root(path = nil)
|
|
10
|
+
# if path
|
|
11
|
+
# @_rspec_source_root = path
|
|
12
|
+
# else
|
|
13
|
+
# @_rspec_source_root ||= File.expand_path(File.join(File.dirname(__FILE__), 'rspec', generator_name, 'templates'))
|
|
14
|
+
# end
|
|
15
|
+
# end
|
|
16
|
+
end
|
|
17
|
+
end
|
|
18
|
+
end
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
module SharingTags::ActionController::Filters
|
|
2
|
+
extend ActiveSupport::Concern
|
|
3
|
+
|
|
4
|
+
included do
|
|
5
|
+
append_before_filter :sharing_tags_clear_context
|
|
6
|
+
end
|
|
7
|
+
|
|
8
|
+
def sharing_tags_clear_context
|
|
9
|
+
logger.debug "SharingTags: clear context #{SharingTags.config.current_context.name}!" if logger.debug?
|
|
10
|
+
SharingTags.config.clear_context!
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
end
|
|
@@ -0,0 +1,57 @@
|
|
|
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
|
|
11
|
+
|
|
12
|
+
def link_to_facebook_share(name = "Facebook", &block)
|
|
13
|
+
share_link_to name, :facebook, [], &block
|
|
14
|
+
end
|
|
15
|
+
|
|
16
|
+
def link_to_vkontakte_share(name = "Vkontakte", &block)
|
|
17
|
+
share_link_to name, :vkontakte, [:title, :description, :image], &block
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def link_to_odnoklassniki_share(name = "Odnoklassniki", &block)
|
|
21
|
+
share_link_to name, :odnoklassniki, [:title, :description], &block
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def link_to_twitter_share(name = "Twitter", &block)
|
|
25
|
+
share_link_to name, :twitter, [:title, :description], &block
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
# @share@ya-target.share_button.tw data-network="twitter" data-target='bot.share_match.tw' a
|
|
29
|
+
# @share@ya-target.share_button.fb data-network="facebook" data-target='bot.share_match.fb' b
|
|
30
|
+
# @share@ya-target.share_button.vk data-network="vkontakte" data-target='bot.share_match.vk' ;
|
|
31
|
+
# @share@ya-target.share_button.ok data-network="odnoklassniki" data-target='bot.share_match.ok' .
|
|
32
|
+
|
|
33
|
+
private
|
|
34
|
+
|
|
35
|
+
def share_link_to(name_or_options = nil, network = nil, data_params = [], &block)
|
|
36
|
+
params = sharing_tags[network]
|
|
37
|
+
data_attrs = params.get(*(data_params +[:network, :share_url]))
|
|
38
|
+
|
|
39
|
+
if block_given?
|
|
40
|
+
name_or_options = {} if !name_or_options || name_or_options.is_a?(String)
|
|
41
|
+
data_attrs.merge!(name_or_options.delete(:data)) if name_or_options[:data]
|
|
42
|
+
|
|
43
|
+
if name_or_options[:role]
|
|
44
|
+
name_or_options[:role] += " sharing_tags_share"
|
|
45
|
+
else
|
|
46
|
+
name_or_options[:role] = "sharing_tags_share"
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
name_or_options.merge!(data: data_attrs, target: "_blank")
|
|
50
|
+
|
|
51
|
+
link_to params.page_url, name_or_options, &block
|
|
52
|
+
else
|
|
53
|
+
link_to name_or_options, params.page_url, data: data_attrs, role: "sharing_tags_share", target: "_blank", &block
|
|
54
|
+
end
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
end
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
require "hashie/mash"
|
|
2
|
+
|
|
3
|
+
module SharingTags
|
|
4
|
+
class Config < ::Hashie::Mash
|
|
5
|
+
|
|
6
|
+
# todo: initialize default param as Config.new
|
|
7
|
+
|
|
8
|
+
# note: temporary code for working construction sharing_tags.switch_context_to
|
|
9
|
+
def switch_context_to(name, *attrs)
|
|
10
|
+
Rails.logger.debug "SharingTags: switch context from #{SharingTags.config.current_context.name} to #{name}"
|
|
11
|
+
SharingTags.config.switch_context(name, *attrs)
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def divide_by_keys(lists)
|
|
15
|
+
second_part = self.class.new
|
|
16
|
+
|
|
17
|
+
lists.each do |divide_key|
|
|
18
|
+
second_part[divide_key] =
|
|
19
|
+
if self.key?(divide_key)
|
|
20
|
+
self.delete(divide_key)
|
|
21
|
+
else
|
|
22
|
+
self.class.new
|
|
23
|
+
end
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
[second_part, self]
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def get(*keys)
|
|
30
|
+
dup.select { |key, _| keys.include?(key.to_sym) }
|
|
31
|
+
end
|
|
32
|
+
end
|
|
33
|
+
end
|
|
@@ -0,0 +1,80 @@
|
|
|
1
|
+
module SharingTags
|
|
2
|
+
class Configuration
|
|
3
|
+
|
|
4
|
+
NETWORKS = %i{ google facebook twitter }
|
|
5
|
+
|
|
6
|
+
def initialize
|
|
7
|
+
clear!
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def context(name, &block)
|
|
11
|
+
raise "please define context block params" unless block_given?
|
|
12
|
+
(@contexts[name] ||= Context.new(name, self)).instance_exec(&block)
|
|
13
|
+
end
|
|
14
|
+
|
|
15
|
+
def switch_context(name = nil, *args)
|
|
16
|
+
clean_params!
|
|
17
|
+
@current_context_params = args
|
|
18
|
+
@prev_context = current_context
|
|
19
|
+
|
|
20
|
+
@current_context =
|
|
21
|
+
if name
|
|
22
|
+
@contexts[name]
|
|
23
|
+
else
|
|
24
|
+
default_context
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
alias switch_context_to switch_context
|
|
28
|
+
|
|
29
|
+
def clear!
|
|
30
|
+
@contexts = {}
|
|
31
|
+
@default_context = Context.new(:default, self)
|
|
32
|
+
@current_context = nil
|
|
33
|
+
@running_context = nil
|
|
34
|
+
clean_params!
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def params
|
|
38
|
+
# @params ||= fetch_params
|
|
39
|
+
@params = fetch_params
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def within_context_params(running_context_instance)
|
|
43
|
+
@running_context = running_context_instance
|
|
44
|
+
params
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
def running_context
|
|
48
|
+
@running_context
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def current_context
|
|
52
|
+
@current_context || default_context
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def clean_params!
|
|
56
|
+
@params = nil
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
def clear_context!
|
|
60
|
+
@current_context = nil
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
private
|
|
64
|
+
|
|
65
|
+
def fetch_params
|
|
66
|
+
default_context_params = default_context.params(@current_context_params)
|
|
67
|
+
return default_context_params unless @current_context
|
|
68
|
+
@current_context.params(@current_context_params, default_context_params)
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
def method_missing(method_name, *arguments, &block)
|
|
72
|
+
current_context.send(method_name, *arguments, &block)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def default_context
|
|
76
|
+
@default_context
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
end
|
|
80
|
+
end
|
|
@@ -0,0 +1,96 @@
|
|
|
1
|
+
module SharingTags
|
|
2
|
+
class Context
|
|
3
|
+
|
|
4
|
+
attr_reader :name
|
|
5
|
+
attr_reader :configuraton
|
|
6
|
+
|
|
7
|
+
def initialize(name, configuraton)
|
|
8
|
+
@name = name
|
|
9
|
+
@networks = {}
|
|
10
|
+
@configuraton = configuraton
|
|
11
|
+
|
|
12
|
+
Network.lists.each do |name|
|
|
13
|
+
self.send(name)
|
|
14
|
+
end
|
|
15
|
+
end
|
|
16
|
+
|
|
17
|
+
def [](network)
|
|
18
|
+
@networks[network]
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def twitter(&block)
|
|
22
|
+
(@networks[:twitter] ||= Network.new(:twitter, self)).tap do |twitter|
|
|
23
|
+
twitter.instance_exec(&block) if block_given?
|
|
24
|
+
end
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
def facebook(&block)
|
|
28
|
+
(@networks[:facebook] ||= Network::Facebook.new(:facebook, self)).tap do |facebook|
|
|
29
|
+
facebook.instance_exec(&block) if block_given?
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def google(&block)
|
|
34
|
+
(@networks[:google] ||= Network.new(:google, self)).tap do |google|
|
|
35
|
+
google.instance_exec(&block) if block_given?
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
def vkontakte(&block)
|
|
40
|
+
(@networks[:vkontakte] ||= Network.new(:vkontakte, self)).tap do |vkontakte|
|
|
41
|
+
vkontakte.instance_exec(&block) if block_given?
|
|
42
|
+
end
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
def odnoklassniki(&block)
|
|
46
|
+
(@networks[:odnoklassniki] ||= Network.new(:odnoklassniki, self)).tap do |vkontakte|
|
|
47
|
+
vkontakte.instance_exec(&block) if block_given?
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def params(context_args = nil, default_config_params = Config.new)
|
|
52
|
+
@context_params = fetch_params(context_args, default_config_params)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
def default_network
|
|
56
|
+
@default_network ||= Network.new(:default, self)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
private
|
|
60
|
+
|
|
61
|
+
def fetch_params(context_args = nil, default_config_params = Config.new)
|
|
62
|
+
default_context_params = fetch_default_context_params(context_args, default_config_params || Config.new)
|
|
63
|
+
|
|
64
|
+
@networks.inject(Config.new) do |result, (name, network)|
|
|
65
|
+
param = (result[name] ||= Config.new)
|
|
66
|
+
|
|
67
|
+
default_network_params = default_context_params[name]
|
|
68
|
+
param.deep_update network.attributes_for(context_args, default_network_params)
|
|
69
|
+
|
|
70
|
+
result[name] = param
|
|
71
|
+
result
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def fetch_default_context_params(context_args = nil, default_config_params = Config.new)
|
|
76
|
+
# divide networks_default_params into to groups default network params and context params
|
|
77
|
+
context_default_params, config_network_defaults = default_config_params.divide_by_keys(Network.lists)
|
|
78
|
+
|
|
79
|
+
context_network_defaults = default_network.attributes_for(context_args, config_network_defaults)
|
|
80
|
+
|
|
81
|
+
context_default_params.each_value do |params|
|
|
82
|
+
params.deep_update(context_network_defaults)
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
context_default_params
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
def method_missing(method_name, *arguments, &block)
|
|
89
|
+
unless default_network.class.available_attributes.include?(method_name.to_sym)
|
|
90
|
+
raise Network::Error.new("Error didn't find #{method_name} attribute in network")
|
|
91
|
+
end
|
|
92
|
+
default_network.send(method_name, *arguments, &block)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
end
|
|
96
|
+
end
|
|
@@ -0,0 +1,102 @@
|
|
|
1
|
+
module SharingTags
|
|
2
|
+
class Network
|
|
3
|
+
|
|
4
|
+
class Error < StandardError
|
|
5
|
+
end
|
|
6
|
+
|
|
7
|
+
NETWORKS = %i( facebook google twitter vkontakte odnoklassniki )
|
|
8
|
+
|
|
9
|
+
ATTRIBUTES = %i( share_url title description image_url image page_url share_url_params link_params )
|
|
10
|
+
|
|
11
|
+
attr_reader :name, :attributes
|
|
12
|
+
|
|
13
|
+
autoload :Facebook, 'sharing_tags/network/facebook'
|
|
14
|
+
|
|
15
|
+
def self.lists
|
|
16
|
+
NETWORKS
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
def initialize(name, context = nil)
|
|
20
|
+
@name = name
|
|
21
|
+
@context = context
|
|
22
|
+
@attributes = {}
|
|
23
|
+
@share_url_params = nil
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def self.available_attributes
|
|
27
|
+
ATTRIBUTES
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def share_url(url = nil, &block)
|
|
31
|
+
attributes[:share_url] = store_value(url, &block)
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def title(new_title = nil, &block)
|
|
35
|
+
attributes[:title] = store_value(new_title, &block)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def description(value = nil, &block)
|
|
39
|
+
attributes[:description] = store_value(value, &block)
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def image_url(new_image = nil, size = nil, content_type = nil, &block)
|
|
43
|
+
attributes[:image] = store_value(new_image, &block)
|
|
44
|
+
|
|
45
|
+
# add size and content type for block value
|
|
46
|
+
size, content_type = new_image, size if block_given?
|
|
47
|
+
|
|
48
|
+
attributes[:image_size] = store_value(size.split("x")) if size
|
|
49
|
+
attributes[:image_content_type] = store_value(content_type) if content_type
|
|
50
|
+
end
|
|
51
|
+
alias :image :image_url
|
|
52
|
+
|
|
53
|
+
# todo: add image_size
|
|
54
|
+
# todo: add_image_type
|
|
55
|
+
|
|
56
|
+
def page_url(new_url = nil, &block)
|
|
57
|
+
attributes[:page_url] = store_value(new_url, &block)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def share_url_params(params = nil, &block)
|
|
61
|
+
@share_url_params = store_value(params, &block)
|
|
62
|
+
end
|
|
63
|
+
alias :link_params :share_url_params
|
|
64
|
+
|
|
65
|
+
def attributes_for(context_params = nil, default_params = Config.new)
|
|
66
|
+
# todo: merge default params after get all values of attributes
|
|
67
|
+
@attributes.inject(default_params.dup) do |result, (name, value)|
|
|
68
|
+
result[name] = get_value(value, context_params)
|
|
69
|
+
result
|
|
70
|
+
end.tap do |attrs|
|
|
71
|
+
#todo: fix assign share_url from page_url
|
|
72
|
+
attrs[:share_url] = attrs[:page_url].dup if !attrs[:share_url] && attrs[:page_url]
|
|
73
|
+
attrs[:share_url] = ("#{attrs[:share_url]}?" + @share_url_params.to_query) if attrs[:share_url] && @share_url_params
|
|
74
|
+
|
|
75
|
+
attrs[:network] = name if attrs.present?
|
|
76
|
+
end
|
|
77
|
+
end
|
|
78
|
+
|
|
79
|
+
protected
|
|
80
|
+
|
|
81
|
+
def store_value(val, &block)
|
|
82
|
+
if block_given?
|
|
83
|
+
block
|
|
84
|
+
else
|
|
85
|
+
val
|
|
86
|
+
end
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
def get_value(value, context_params)
|
|
90
|
+
if value.is_a?(Proc)
|
|
91
|
+
if running_context = @context.configuraton.running_context
|
|
92
|
+
# execute proc within the view context with context_params
|
|
93
|
+
running_context.instance_exec(*context_params, &value)
|
|
94
|
+
else
|
|
95
|
+
value.call(context_params)
|
|
96
|
+
end
|
|
97
|
+
else
|
|
98
|
+
value
|
|
99
|
+
end
|
|
100
|
+
end
|
|
101
|
+
end
|
|
102
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
module SharingTags
|
|
2
|
+
class Railtie < Rails::Railtie
|
|
3
|
+
|
|
4
|
+
# config.eager_load_namespaces << SharingTags
|
|
5
|
+
|
|
6
|
+
generators do
|
|
7
|
+
require "generators/sharing_tags/install/install_generator"
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
# rake_tasks do
|
|
11
|
+
# load "rspec/rails/tasks/rspec.rake"
|
|
12
|
+
# end
|
|
13
|
+
|
|
14
|
+
initializer "sharing_tags.configure_view_controller" do |app|
|
|
15
|
+
ActiveSupport.on_load :action_view do
|
|
16
|
+
include SharingTags::ActionView::Helpers
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
ActiveSupport.on_load :action_controller do
|
|
20
|
+
include SharingTags::ActionController::Helpers
|
|
21
|
+
include SharingTags::ActionController::Filters
|
|
22
|
+
|
|
23
|
+
# todo add filter for clear context
|
|
24
|
+
# append_filter :clear_context!
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
|
|
28
|
+
end
|
|
29
|
+
end
|
data/lib/sharing_tags.rb
ADDED
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
require "sharing_tags/engine"
|
|
2
|
+
|
|
3
|
+
module SharingTags
|
|
4
|
+
|
|
5
|
+
#extend ActiveSupport::Autoload
|
|
6
|
+
|
|
7
|
+
autoload :VERSION, 'sharing_tags/version'
|
|
8
|
+
autoload :Config, 'sharing_tags/config'
|
|
9
|
+
autoload :Configuration, 'sharing_tags/configuration'
|
|
10
|
+
autoload :Network, 'sharing_tags/network'
|
|
11
|
+
autoload :Context, 'sharing_tags/context'
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
module ActionView
|
|
15
|
+
autoload :Helpers, 'sharing_tags/action_view/helpers'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
module ActionController
|
|
19
|
+
autoload :Helpers, 'sharing_tags/action_controller/helpers'
|
|
20
|
+
autoload :Filters, 'sharing_tags/action_controller/filters'
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def configure(&block)
|
|
24
|
+
config.clear! # cleanup config before calling configure
|
|
25
|
+
config.instance_exec(&block)
|
|
26
|
+
end
|
|
27
|
+
module_function :configure
|
|
28
|
+
|
|
29
|
+
def config
|
|
30
|
+
@config ||= Configuration.new
|
|
31
|
+
end
|
|
32
|
+
module_function :config
|
|
33
|
+
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
require 'sharing_tags/railtie' if defined?(Rails::Railtie)
|
|
37
|
+
require 'sharing_tags/engine' if defined?(Rails)
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
# coding: utf-8
|
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
|
+
require 'sharing_tags/version'
|
|
5
|
+
|
|
6
|
+
Gem::Specification.new do |spec|
|
|
7
|
+
spec.name = "sharing_tags"
|
|
8
|
+
spec.version = SharingTags::VERSION
|
|
9
|
+
spec.authors = ["Anatoliy Kovalchuk"]
|
|
10
|
+
spec.email = ["kr00lix@gmail.com"]
|
|
11
|
+
spec.summary = %q{ Generate sharing tags for different contexts }
|
|
12
|
+
spec.description = %q{ Describe your sharing information for different contexts in one simple configuration file. }
|
|
13
|
+
spec.homepage = "https://github.com/Kr00lIX/sharing_tags"
|
|
14
|
+
spec.license = "MIT"
|
|
15
|
+
|
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
|
19
|
+
spec.require_paths = ["lib"]
|
|
20
|
+
|
|
21
|
+
spec.add_dependency 'rails', "~> 4.0"
|
|
22
|
+
spec.add_dependency 'hashie', "~> 3.4"
|
|
23
|
+
spec.add_dependency 'slim', "~> 3.0"
|
|
24
|
+
|
|
25
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
|
26
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
|
27
|
+
spec.add_development_dependency "rspec", "~> 3.2"
|
|
28
|
+
spec.add_development_dependency "rspec-nc", "~> 0.2"
|
|
29
|
+
spec.add_development_dependency 'rspec-rails', "~> 3.2"
|
|
30
|
+
spec.add_development_dependency 'rspec-html-matchers', "~> 0.7"
|
|
31
|
+
spec.add_development_dependency 'ammeter', '1.1.2'
|
|
32
|
+
spec.add_development_dependency "guard", "~> 2.12"
|
|
33
|
+
spec.add_development_dependency "guard-rspec", "~> 4.5"
|
|
34
|
+
spec.add_development_dependency 'sqlite3', "~> 1.3"
|
|
35
|
+
spec.add_development_dependency 'pry', "~> 0.10"
|
|
36
|
+
|
|
37
|
+
end
|