Class: SharingTags::Network
- Inherits:
-
Object
- Object
- SharingTags::Network
show all
- Defined in:
- lib/sharing_tags/network.rb,
lib/sharing_tags/network/facebook.rb
Defined Under Namespace
Classes: Error, Facebook, NetworkRunningContext
Constant Summary
collapse
- NETWORKS =
%i( facebook google twitter vkontakte odnoklassniki linkedin )
- ATTRIBUTES =
%i( share_url title description page_url share_url_params link_params
image_url image digested_image digested_image_url )
Instance Attribute Summary collapse
Class Method Summary
collapse
Instance Method Summary
collapse
-
#attributes_for(context_params = nil, default_params = Config.new) ⇒ Object
-
#clear! ⇒ Object
-
#description(value = nil, &block) ⇒ Object
-
#digested_image_url(*arguments, &block) ⇒ Object
(also: #digested_image)
TODO: add image_size TODO: add_image_type.
-
#image_url(*arguments, &block) ⇒ Object
(also: #image)
TODO: activate rubycop Metrics rubocop:disable Metrics/AbcSize image_url(new_image = nil, size = nil, content_type = nil, options, &block).
-
#initialize(name, context = nil) ⇒ Network
constructor
A new instance of Network.
-
#page_url(new_url = nil, &block) ⇒ Object
-
#share_url(url = nil, &block) ⇒ Object
-
#share_url_params(params = nil, &block) ⇒ Object
(also: #link_params)
-
#title(new_title = nil, &block) ⇒ Object
Constructor Details
#initialize(name, context = nil) ⇒ Network
Returns a new instance of Network.
45
46
47
48
49
50
|
# File 'lib/sharing_tags/network.rb', line 45
def initialize(name, context = nil)
@name = name
@context = context
@running_context = NetworkRunningContext.new(self, context)
clear!
end
|
Instance Attribute Details
#attributes ⇒ Object
Returns the value of attribute attributes.
37
38
39
|
# File 'lib/sharing_tags/network.rb', line 37
def attributes
@attributes
end
|
#name ⇒ Object
Returns the value of attribute name.
37
38
39
|
# File 'lib/sharing_tags/network.rb', line 37
def name
@name
end
|
Class Method Details
.available_attributes ⇒ Object
56
57
58
|
# File 'lib/sharing_tags/network.rb', line 56
def self.available_attributes
ATTRIBUTES
end
|
.lists ⇒ Object
41
42
43
|
# File 'lib/sharing_tags/network.rb', line 41
def self.lists
NETWORKS
end
|
Instance Method Details
#attributes_for(context_params = nil, default_params = Config.new) ⇒ Object
114
115
116
117
118
119
120
121
122
123
124
125
126
|
# File 'lib/sharing_tags/network.rb', line 114
def attributes_for(context_params = nil, default_params = Config.new)
attrs = @attributes.each_with_object(default_params.dup) do |(a_name, value), result|
result[a_name] = get_value(value, context_params)
end
attrs[:share_url] = attrs[:page_url].dup if !attrs[:share_url] && attrs[:page_url]
attrs[:share_url] = add_params_to_url(attrs[:share_url], attrs[:share_url_params]) if attrs[:share_url] && attrs[:share_url_params].present?
attrs[:network] = name if attrs.present?
attrs
end
|
#clear! ⇒ Object
52
53
54
|
# File 'lib/sharing_tags/network.rb', line 52
def clear!
@attributes = {}
end
|
#description(value = nil, &block) ⇒ Object
68
69
70
|
# File 'lib/sharing_tags/network.rb', line 68
def description(value = nil, &block)
attributes[:description] = store_value(value, &block)
end
|
#digested_image_url(*arguments, &block) ⇒ Object
Also known as:
digested_image
TODO: add image_size TODO: add_image_type
96
97
98
99
100
101
102
|
# File 'lib/sharing_tags/network.rb', line 96
def digested_image_url(*arguments, &block)
options = arguments.
options.merge!(digested: false)
wrap_block = proc { |*args| without_digest_asset_url(block.call(*args)) } if block_given?
image_url(*arguments, options, &wrap_block)
end
|
#image_url(*arguments, &block) ⇒ Object
Also known as:
image
TODO: activate rubycop Metrics rubocop:disable Metrics/AbcSize image_url(new_image = nil, size = nil, content_type = nil, options, &block)
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
|
# File 'lib/sharing_tags/network.rb', line 75
def image_url(*arguments, &block)
options = arguments.
new_image, size, content_type = arguments
block = proc { without_digest_asset_url(new_image) } if options[:digested] == false && block_given? == false
attributes[:image] = store_value(new_image, &block)
size, content_type = new_image, size if block_given?
attributes[:image_size] = store_value(size.split("x").map(&:to_i)) if size
attributes[:image_content_type] = store_value(content_type) if content_type
end
|
#page_url(new_url = nil, &block) ⇒ Object
105
106
107
|
# File 'lib/sharing_tags/network.rb', line 105
def page_url(new_url = nil, &block)
attributes[:page_url] = store_value(new_url, &block)
end
|
#share_url(url = nil, &block) ⇒ Object
60
61
62
|
# File 'lib/sharing_tags/network.rb', line 60
def share_url(url = nil, &block)
attributes[:share_url] = store_value(url, &block)
end
|
#share_url_params(params = nil, &block) ⇒ Object
Also known as:
link_params
109
110
111
|
# File 'lib/sharing_tags/network.rb', line 109
def share_url_params(params = nil, &block)
attributes[:share_url_params] = store_value(params, &block)
end
|
#title(new_title = nil, &block) ⇒ Object
64
65
66
|
# File 'lib/sharing_tags/network.rb', line 64
def title(new_title = nil, &block)
attributes[:title] = store_value(new_title, &block)
end
|