social_linker 0.3 → 0.3.1

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: 5c3db60b8186c8555f88a031d0bb93228630dc27
4
- data.tar.gz: 10b7a36a98551d9d017b3b089cc28af4594f3b70
3
+ metadata.gz: 225497bfdb95c86ee81611426cf1f6a9fa2df7d1
4
+ data.tar.gz: ccd6669031947161cb984e6f75395d211346cd74
5
5
  SHA512:
6
- metadata.gz: 8e16b1ef40ad811b71d2de74112f7490724b46276022ee1ea46da7b6fb590dd7896bd0a9a7a48686624cc6afaf692a67cd27fd70c4a84d4db27015ef92190721
7
- data.tar.gz: 6c4f099066e9dcbc0b804a2329402edb3b9a0facb13b5777727fbaf65886da7288027e95ba081ebca588f97d518cf014e5a27f98cf7ea0bccd6e7f64814ac353
6
+ metadata.gz: 13c93737103b51862520cd92be7f2ce3cdbafc10f1ee788055de1a54cafe0a9e1c799ff3abb424715684c8b4b004d8814db0c6eaa794990dee320c3d253814db
7
+ data.tar.gz: d2c334fc96b5fb32782fa6ddce9d192f344135d2651e8f0e4d6558913af3ed9eb418ff9cdfaf083c656ce38d9a09d0389335c041da66a8d52cff7bcbb9c0f0d3
@@ -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
- @options[:domain] = @options[:url].split(/\//)[0..2].join("/") if @options[:url] and !@options[:domain]
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
@@ -1,3 +1,3 @@
1
1
  module SocialLinker
2
- VERSION = "0.3"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_linker
3
3
  version: !ruby/object:Gem::Version
4
- version: '0.3'
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - murb