39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
|
# File 'lib/showcase/traits/share.rb', line 39
def share(name = nil, &block)
PROVIDERS.each do |social, settings|
link_name = [ name, social, "share" ].map(&:presence).compact.join("_")
link_to link_name do |c|
meta = Helpers::ConfigObject.new(self, &block).to_struct
html_options = meta.html_options || {}
params = Hash[
settings[:params].map do |param, meta_key|
values = [:"#{social}_#{meta_key}", meta_key].map { |key| meta.send(key) }
[ param, values.find(&:presence) ]
end
]
c.url "#{settings[:url]}?#{params.to_query}"
c.label settings[:label]
c.html_options = html_options.reverse_merge(target: '_blank')
end
end
end
|