social_linker 0.1.0 → 0.1.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: 44693d7049496654e418b3baeb7d3d5480583396
4
- data.tar.gz: afb9f90e4bcd35e49df107244a9d4a7cb0803ba6
3
+ metadata.gz: 6036e3cb0b45698770be9b32a5030ee099fffe83
4
+ data.tar.gz: e9a5d85d8e26ff3da2c85012965b673704cbbb04
5
5
  SHA512:
6
- metadata.gz: 8421d72c3578625c81353d66907ba4bf8695b1e97c9c370a816d1f2f4088ac2c9a43aa9fd5ff8ebbc623f60c74760e8fc992b7487bbcbcab5ec94f95f3a5e78b
7
- data.tar.gz: 23bed364f087ceb4eb1d06959980c3ec95a71e216dbeb01c439d47d73d17a446176ca61bc2c8fcf31b60757c5175a1e78a911538a8e13962bc1c63fa0bebaa26
6
+ metadata.gz: 51cc1e4caa195d860cc5a3ce535b5e871f1d0e611bab09a160a3863966ab072f65b0260e2fcdb7c94fc2f6197b0665ab13bab774e44dd5f5a3d71ee92a9be245
7
+ data.tar.gz: 2c025dd4c94309859b8821e8ddb2678abbea5a622bc81567871cc80d978b08be365b497c257e0f3acb96d4931d8644b1bea12186c22ef11e69149ffd7e2eea9f
data/.gitignore CHANGED
@@ -7,3 +7,4 @@
7
7
  /pkg/
8
8
  /spec/reports/
9
9
  /tmp/
10
+ *.gem
data/README.md CHANGED
@@ -1,6 +1,6 @@
1
1
  # SocialLinker
2
2
 
3
- SocialLinker is able to generate the most needed share links for you. You should use generated links, instead of the share buttons provided by the platforms themselves, to protect your user's privacy, and this gem makes it easy for you to do so.
3
+ SocialLinker is able to generate the most common share links for you, without depending on JavaScript. You should use generated links, instead of the share buttons provided by the platforms themselves, to protect your user's privacy, and this gem makes it easy for you to do so.
4
4
 
5
5
  ## Installation
6
6
 
@@ -38,9 +38,9 @@ Which will deliver you the following url:
38
38
 
39
39
  mailto:emailaddress?subject=Example%20website&body=Example.com%20is%20the%20typical%20URL%20you%20would%20want%20to%20use%20in%20explanations%20anyway.%0A%0Ahttp%3A%2F%2Fexample.com%2F
40
40
 
41
- Or to save you the copy paste:
41
+ Or to save you the copy-paste:
42
42
 
43
- [TestMailLink](mailto:mailto:emailaddress?subject=Example%20website&body=Example.com%20is%20the%20typical%20URL%20you%20would%20want%20to%20use%20in%20explanations%20anyway.%0A%0Ahttp%3A%2F%2Fexample.com%2F)
43
+ [TestMailLink](mailto:emailaddress?subject=Example%20website&body=Example.com%20is%20the%20typical%20URL%20you%20would%20want%20to%20use%20in%20explanations%20anyway.%0A%0Ahttp%3A%2F%2Fexample.com%2F)
44
44
 
45
45
  The supported options are:
46
46
 
data/lib/social_linker.rb CHANGED
@@ -3,7 +3,13 @@ require "erb"
3
3
  include ERB::Util
4
4
 
5
5
  module SocialLinker
6
+
7
+ # The main class of SocialLinker is the `SocialLinker::Subject`-class.
6
8
  class Subject
9
+
10
+ # Constant defining how the different share-url's look like and their parameters;
11
+ # the parameters can be set in the options directly, or will be derived from more
12
+ # generic options
7
13
  SHARE_TEMPLATES = {
8
14
  email: {
9
15
  base: "mailto:emailaddress?",
@@ -32,6 +38,10 @@ module SocialLinker
32
38
 
33
39
  }
34
40
 
41
+ # convert an array of strings to a Twitter-like hashtag-string
42
+ #
43
+ # @param [Array] tags to be converted to string
44
+ # @return [String] containing a Twitter-style tag-list
35
45
  def hashtag_string(tags)
36
46
  string = (tags and tags.count > 0) ? "##{tags.collect{|a| a.to_s.strip.gsub('#','')}.join(" #")}" : nil
37
47
  if string and string.length > 60
@@ -40,10 +50,47 @@ module SocialLinker
40
50
  string
41
51
  end
42
52
 
53
+ # default url accessor
54
+ #
55
+ # @return String with url
56
+ def url
57
+ @options[:url]
58
+ end
59
+
60
+ # default title accessor
61
+ # @return String with title
62
+ def title
63
+ @options[:title]
64
+ end
65
+
66
+ # default summary accessor
67
+ # @return String with summary
68
+ def summary
69
+ @options[:summary]
70
+ end
71
+
72
+ # default media accessor
73
+ # @return String with media-url
74
+ def media
75
+ @options[:media]
76
+ end
77
+
78
+ # default tags accessor
79
+ # @return Array<String> with tags
80
+ def tags
81
+ @options[:media]
82
+ end
83
+
84
+ # puts quotes around a string
85
+ # @return [String] now with quotes.
43
86
  def quote_string(string)
44
87
  "“#{string}”" if string and string.to_s.strip != ""
45
88
  end
46
89
 
90
+ # strips a string to the max length taking into account quoting
91
+ # @param [String] string that is about to be shortened
92
+ # @param [Integer] max_length of the string to be shortened (default 100)
93
+ # @return [String] shortened to the max lenght
47
94
  def strip_string(string, max_length=100)
48
95
  if string and string.length > max_length
49
96
  elipsis = "…"
@@ -56,12 +103,15 @@ module SocialLinker
56
103
  string
57
104
  end
58
105
 
106
+ # Initialize the SocialLinker::Subject
107
+ #
59
108
  # options accepts:
60
109
  # * tags
61
110
  # * url
62
111
  # * title
63
112
  # * image_url
64
-
113
+ #
114
+ # @params [hash] options as defined above
65
115
  def initialize(options={})
66
116
  @options = options
67
117
  @options[:u] = @options[:url] unless options[:u]
@@ -73,8 +123,8 @@ module SocialLinker
73
123
  @options[:url] = @options[:media] unless @options[:url]
74
124
 
75
125
  unless @options[:status]
76
- hash_string = hashtag_string(@options[:tags])
77
- max_length = (hash_string ? hash_string.length : 0) + 12 + 4 #hashstring + url length (shortened) + spaces
126
+ hash_string = @options[:tags] ? hashtag_string(@options[:tags][0..2]) : ""
127
+ max_length = 140 - ((hash_string ? hash_string.length : 0) + 12 + 4) #hashstring + url length (shortened) + spaces
78
128
  @options[:status] = "#{quote_string(strip_string(@options[:title],max_length))} #{@options[:url]} #{hash_string}"
79
129
  end
80
130
 
@@ -93,12 +143,19 @@ module SocialLinker
93
143
  end
94
144
  end
95
145
 
146
+ # Returns the given options, extended with the (derived) defaults
147
+ #
148
+ # @return Hash with the options
96
149
  def options
97
150
  @options
98
151
  end
99
152
 
153
+ # Generates a share link for each of the predefined platforms in the `SHARE_TEMPLATES` constant
154
+ #
155
+ # @param [Symbol] platform to generate the link for
100
156
  def share_link(platform)
101
157
  share_options = SHARE_TEMPLATES[platform]
158
+ raise "No share template defined" unless share_options
102
159
  params = options.keys & share_options[:params]
103
160
  if params.include?(:description) and !params.include?(:title)
104
161
  @options[:description] = @options[:title]
@@ -106,5 +163,17 @@ module SocialLinker
106
163
 
107
164
  return share_options[:base]+params.collect{|k| "#{k}=#{url_encode(options[k])}"}.join('&')
108
165
  end
166
+
167
+ # Catches method missing and tries to resolve them in either an appropriate share link or option value
168
+ def method_missing(m,*args)
169
+ share_link_matcher = m.to_s.match(/([a-z]*)_share_link/)
170
+ if share_link_matcher
171
+ return share_link(share_link_matcher[1].to_sym)
172
+ elsif options[m]
173
+ return options[m]
174
+ else
175
+ super
176
+ end
177
+ end
109
178
  end
110
179
  end
@@ -1,3 +1,3 @@
1
1
  module SocialLinker
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: social_linker
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - murb
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-06-27 00:00:00.000000000 Z
11
+ date: 2016-07-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler