social_linker 0.3 → 0.3.1
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 +4 -4
- data/app/helpers/view_helpers.rb +3 -3
- data/lib/social_linker/subject.rb +23 -3
- data/lib/social_linker/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA1:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 225497bfdb95c86ee81611426cf1f6a9fa2df7d1
|
|
4
|
+
data.tar.gz: ccd6669031947161cb984e6f75395d211346cd74
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 13c93737103b51862520cd92be7f2ce3cdbafc10f1ee788055de1a54cafe0a9e1c799ff3abb424715684c8b4b004d8814db0c6eaa794990dee320c3d253814db
|
|
7
|
+
data.tar.gz: d2c334fc96b5fb32782fa6ddce9d192f344135d2651e8f0e4d6558913af3ed9eb418ff9cdfaf083c656ce38d9a09d0389335c041da66a8d52cff7bcbb9c0f0d3
|
data/app/helpers/view_helpers.rb
CHANGED
|
@@ -38,10 +38,10 @@ module ViewHelpers
|
|
|
38
38
|
end
|
|
39
39
|
|
|
40
40
|
header_html << meta_tag("keywords", subject.tags.join(" "))
|
|
41
|
-
header_html << meta_tag("description", subject.summary)
|
|
41
|
+
header_html << meta_tag("description", subject.summary(true))
|
|
42
42
|
|
|
43
|
-
header_html << meta_tag("twitter:description", subject.summary)
|
|
44
|
-
header_html << meta_tag("og:description", subject.summary)
|
|
43
|
+
header_html << meta_tag("twitter:description", subject.summary(true))
|
|
44
|
+
header_html << meta_tag("og:description", subject.summary(true))
|
|
45
45
|
|
|
46
46
|
if subject.media
|
|
47
47
|
header_html << meta_tag("twitter:image:src", subject.media)
|
|
@@ -91,8 +91,8 @@ module SocialLinker
|
|
|
91
91
|
|
|
92
92
|
# default summary accessor
|
|
93
93
|
# @return String with summary
|
|
94
|
-
def summary
|
|
95
|
-
@options[:summary]
|
|
94
|
+
def summary(strip=false)
|
|
95
|
+
strip ? strip_string(@options[:summary], 300) : @options[:summary]
|
|
96
96
|
end
|
|
97
97
|
|
|
98
98
|
# default media accessor
|
|
@@ -158,8 +158,12 @@ module SocialLinker
|
|
|
158
158
|
@options[:subject] = @options[:title] unless @options[:subject]
|
|
159
159
|
@options[:via] = @options[:twitter_username] unless @options[:via]
|
|
160
160
|
@options[:url] = @options[:media] unless @options[:url]
|
|
161
|
+
raise ArgumentError, "#{url} is not a valid url" if @options[:url] and !@options[:url].include?('//')
|
|
162
|
+
|
|
161
163
|
@options[:text] = "#{@options[:title]} #{@options[:url]}" unless @options[:text] #facebook & whatsapp native
|
|
162
164
|
@options[:canonical_url] = @options[:url]
|
|
165
|
+
@options[:domain] = @options[:url].split(/\//)[0..2].join("/") if @options[:url] and !@options[:domain]
|
|
166
|
+
|
|
163
167
|
if @options[:url] and utm_parameters
|
|
164
168
|
unless @options[:url].match /utm_source/
|
|
165
169
|
combine_with = @options[:url].match(/\?/) ? "&" : "?"
|
|
@@ -194,13 +198,29 @@ module SocialLinker
|
|
|
194
198
|
@options[:body] += "\n\n#{hashtag_string(@options[:tags])}" if @options[:tags]
|
|
195
199
|
@options[:body] = nil if @options[:body].strip == ""
|
|
196
200
|
end
|
|
197
|
-
|
|
201
|
+
|
|
202
|
+
@options[:image_url] = prefix_domain(@options[:image_url],@options[:domain])
|
|
203
|
+
@options[:media] = prefix_domain(@options[:media],@options[:domain])
|
|
198
204
|
|
|
199
205
|
@options.each do |k,v|
|
|
200
206
|
@options[k] = v.strip if v and v.is_a? String
|
|
201
207
|
end
|
|
202
208
|
end
|
|
203
209
|
|
|
210
|
+
# It is assumed that paths are relative to the domainname if none is given
|
|
211
|
+
# @param [String] path to file (if it is already a full url, it will be passed along)
|
|
212
|
+
# @param [String] domain of the file
|
|
213
|
+
# @return String with full url
|
|
214
|
+
def prefix_domain path, domain
|
|
215
|
+
return_string = path
|
|
216
|
+
if path and !path.include?("//")
|
|
217
|
+
path.gsub!(/^\//,'')
|
|
218
|
+
domain.gsub!(/\/$/,'')
|
|
219
|
+
return_string = [domain,path].join("/")
|
|
220
|
+
end
|
|
221
|
+
return_string
|
|
222
|
+
end
|
|
223
|
+
|
|
204
224
|
# Returns the given options, extended with the (derived) defaults
|
|
205
225
|
#
|
|
206
226
|
# @return Hash with the options
|