badges2svg 0.1.3 → 0.1.4

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: c925547728c1059011d3d247b6387aa6c77bf9ec
4
- data.tar.gz: f0bb39f66ee88fda11df12cacdaa463b711385b9
3
+ metadata.gz: dc70948fada36a2eef0619ca3de85a3fcc91d77c
4
+ data.tar.gz: 84446cb58e89ad23f56766d1f5416f5c9ae38b65
5
5
  SHA512:
6
- metadata.gz: db0b2e6518a4ab8c6de2c85feb32b567c9071442e127877eb1e255b9cbde57340e1e4190affe3ed362138338342fbf3f513ea78d0431a5738879395b188ef3d7
7
- data.tar.gz: 5f1b7b262715e3747001735ac8a6ecd3acdc5874cab62ff74ab700a77bee9aafdc9ecab572782f509a5a5f1b5d5416199a81a15beb403209286eb1a5d5428feb
6
+ metadata.gz: 7bb577256b9eaf9f8e30a7582ed718ccd7eb364c602674d2901973630ab3e7be94fa273de41e66ca0dba6641f03375c91fd3db33e9510af1eb33c017f9fecdbc
7
+ data.tar.gz: 4d5bc8dfba2cefc429fa26c16fa287bd81d75cc4fc70ab163901bd024476244c068b6de522315c6844c76e059f369e08097021c1e6d4a73c4ce1de7222bd58e3
checksums.yaml.gz.sig ADDED
Binary file
data.tar.gz.sig ADDED
Binary file
data/lib/badges2svg.rb CHANGED
@@ -1,26 +1,48 @@
1
+ # This module’s main method is {BadgesToSVG#replace}. It’s used to parse a
2
+ # string and replace links to PNG badge images with resolution-independent
3
+ # (SVG) ones. This is used by a command-line tool called +badges2svg+.
1
4
  module BadgesToSVG
2
5
 
6
+ # @return [String] default protocol
7
+ attr_reader :protocol
8
+
9
+ # @return [String] default domain
10
+ attr_reader :domain
11
+
3
12
  @protocol = 'https'
4
- @domain = 'img.shields.io'
13
+ @domain = 'img.shields.io'
5
14
 
6
15
  class << self
7
16
 
8
- # see http://shields.io/
17
+ # Rules for PNG to SVG replacements. This array is intentionally ordered,
18
+ # because some rules might match the same pattern, so the greedier ones
19
+ # should go first. A rule is a hash with the following keys:
20
+ # - +:name+: the rule's name. This must be unique.
21
+ # - +:pattern+ the PNG URL pattern. See {BadgesToSVG#compile_pattern} for a
22
+ # pattern overview.
23
+ # - +:string+ the URL replacement. The protocol shouldn't be specified. If
24
+ # you wish to use the +shields.io+ start your replacement with a slash
25
+ # (+/+).
26
+ # - +:domain+ (optional): if you specified a custom domain in the +:string+
27
+ # key, set this one to +true+ to tell +BadgesToSVG+ not to prepend the
28
+ # default domain.
9
29
  RULES = [
10
30
  { :name => :travis_branch,
11
31
  :pattern => 'https?://(?:secure.)?travis-ci.org/%{user}/%{repo}.png' +
12
32
  '\\?branch=%{branch}',
13
- :string => '/travis/%{user}/%{repo}/%{branch}.svg'
33
+ :string => 'travis-ci.org/%{user}/%{repo}.svg?branch=%{branch}',
34
+ :domain => true
14
35
  },
15
36
  {
16
37
  :name => :travis,
17
38
  :pattern => 'https?://(?:secure.)?travis-ci.org/%{user}/%{repo}.png',
18
- :string => '/travis/%{user}/%{repo}.svg'
39
+ :string => 'travis-ci.org/%{user}/%{repo}.svg',
40
+ :domain => true
19
41
  },
20
42
  {
21
- :name => :gittip,
22
- :pattern => 'https?://img.shields.io/gittip/%{user}.png',
23
- :string => '/gittip/%{user}.svg'
43
+ :name => :gratipay,
44
+ :pattern => 'https?://img.shields.io/gittip/%{user}.(?:png|svg)',
45
+ :string => '/gratipay/user/%{user}.svg'
24
46
  },
25
47
  {
26
48
  :name => :coveralls_branch,
@@ -36,7 +58,8 @@ module BadgesToSVG
36
58
  {
37
59
  :name => :gemnasium,
38
60
  :pattern => 'https?://gemnasium.com/%{user}/%{repo}.png',
39
- :string => '/gemnasium/%{user}/%{repo}.svg'
61
+ :string => 'gemnasium.com/%{user}/%{repo}.svg',
62
+ :domain => true
40
63
  },
41
64
  {
42
65
  :name => :code_climate,
@@ -64,7 +87,6 @@ module BadgesToSVG
64
87
  :pattern => 'https?://poser.pugx.org/%{user}/%{repo}/version.png',
65
88
  :string => '/packagist/v/%{user}/%{repo}.svg'
66
89
  },
67
-
68
90
  {
69
91
  :name => :packagist_downloads,
70
92
  :pattern => 'https?://poser.pugx.org/%{user}/%{repo}/d/total.png',
@@ -75,7 +97,12 @@ module BadgesToSVG
75
97
  :pattern => 'https?://pypip.in/d/%{repo}/badge.png',
76
98
  :string => '/pypi/dm/%{repo}.svg'
77
99
  },
78
-
100
+ {
101
+ :name => :inch_ci,
102
+ :pattern => 'https?://inch-ci.org/github/%{user}/%{repo}.png\\?branch=%{branch}',
103
+ :string => 'inch-ci.org/github/%{user}/%{repo}.svg?branch=%{branch}',
104
+ :domain => true,
105
+ },
79
106
  {
80
107
  :name => :misc_png,
81
108
  :pattern => 'https?://img.shields.io/%{path}.png',
@@ -83,25 +110,55 @@ module BadgesToSVG
83
110
  },
84
111
  ]
85
112
 
113
+ # @return [String] current gem version
86
114
  def version
87
- '0.1.3'
115
+ '0.1.4'
88
116
  end
89
117
 
118
+ # Create a root URL. If nothing is passed, it uses the default protocol and
119
+ # default domain
120
+ # @param opts [Hash] use this parameter to override default protocol
121
+ # (+:protocol+) and (+:domain+).
122
+ # @see BadgesToSVG#protocol
123
+ # @see BadgesToSVG#domain
90
124
  def root_url(opts={})
91
125
  "#{opts[:protocol] || @protocol}://#{opts[:domain] || @domain}"
92
126
  end
93
127
 
94
- def compile_pattern(pat, *a)
95
- pat = pat.gsub(/\./, '\\.')
96
- Regexp.new ("\\b#{pat.gsub(/%\{(\w+)\}/, "(?<\\1>.+?)")}\\b")
128
+ # Compile a pattern into a regular expression. Patterns are used as handy
129
+ # shortcuts to extract a part of an URL. A pattern written as +%{foo}+ in a
130
+ # string is compiled into a +Regexp+ that matches an alphanumeric word into
131
+ # a group called <i>foo</i>.
132
+ # @param pattern [String]
133
+ # @return [Regexp] compiled pattern
134
+ def compile_pattern(pattern)
135
+ # don't use .gsub! here or it’ll modify the variable itself, outside of
136
+ # the function call
137
+ pattern = pattern.gsub(/\./, '\\.')
138
+ Regexp.new ("\\b#{pattern.gsub(/%\{(\w+)\}/, "(?<\\1>.+?)")}\\b")
97
139
  end
98
140
 
99
- def replace content, opts={}
141
+ # Replace PNG image URLs with SVG ones when possible in a given string
142
+ # content. This is meant to be used on a README or similar file.
143
+ # @param content [String]
144
+ # @param opts [Hash] this hash is passed to {BadgesToSVG#root_url} and thus
145
+ # can be used to override the default protocol and
146
+ # domain.
147
+ # @return [String] the same content with replaced URLs
148
+ # @see RULES
149
+ def replace(content, opts={})
100
150
  root = root_url(opts)
101
151
  RULES.each do |r|
152
+ if r[:domain]
153
+ rule_opts = {:protocol => r[:protocol], :domain => ''}
154
+ myroot = root_url({}.update(opts).update(rule_opts))
155
+ else
156
+ myroot = root
157
+ end
158
+
102
159
  pat = compile_pattern(r[:pattern])
103
- repl = root + r[:string].gsub(/%\{(\w+)\}/, "\\\\k<\\1>")
104
- content.gsub!(pat, repl)
160
+ replacement = myroot + r[:string].gsub(/%\{(\w+)\}/, "\\\\k<\\1>")
161
+ content.gsub!(pat, replacement)
105
162
  end
106
163
 
107
164
  content
data/tests/tests.rb CHANGED
@@ -92,43 +92,61 @@ class BadgesToSVGTests < Test::Unit::TestCase
92
92
 
93
93
  ## travis
94
94
 
95
- def test_replace_one_travis_https
95
+ def test_replace_one_travis_https_secure
96
96
  ct1 = "# README\n\nHello ![](https://secure.travis-ci.org/usr/re.png)"
97
- ct2 = "# README\n\nHello ![](https://img.shields.io/travis/usr/re.svg)"
97
+ ct2 = "# README\n\nHello ![](https://travis-ci.org/usr/re.svg)"
98
+ assert_equal(ct2, BadgesToSVG.replace(ct1))
99
+ end
100
+
101
+ def test_replace_one_travis_https
102
+ ct1 = "# README\n\nHello ![](https://travis-ci.org/usr/re.png)"
103
+ ct2 = "# README\n\nHello ![](https://travis-ci.org/usr/re.svg)"
98
104
  assert_equal(ct2, BadgesToSVG.replace(ct1))
99
105
  end
100
106
 
101
107
  def test_replace_one_travis_http
102
108
  ct1 = "# README\n\nHello ![](http://travis-ci.org/usr/re.png)"
103
- ct2 = "# README\n\nHello ![](https://img.shields.io/travis/usr/re.svg)"
109
+ ct2 = "# README\n\nHello ![](https://travis-ci.org/usr/re.svg)"
104
110
  assert_equal(ct2, BadgesToSVG.replace(ct1))
105
111
  end
106
112
 
107
113
  ## travis_branch
108
114
 
109
- def test_replace_one_travis_branch_https
115
+ def test_replace_one_travis_branch_https_secure
110
116
  ct1 = "# README\n\nHello ![](https://secure.travis-ci.org/usr/re.png?branch=bx)"
111
- ct2 = "# README\n\nHello ![](https://img.shields.io/travis/usr/re/bx.svg)"
117
+ ct2 = "# README\n\nHello ![](https://travis-ci.org/usr/re.svg?branch=bx)"
118
+ assert_equal(ct2, BadgesToSVG.replace(ct1))
119
+ end
120
+
121
+ def test_replace_one_travis_branch_https
122
+ ct1 = "# README\n\nHello ![](https://travis-ci.org/usr/re.png?branch=bx)"
123
+ ct2 = "# README\n\nHello ![](https://travis-ci.org/usr/re.svg?branch=bx)"
112
124
  assert_equal(ct2, BadgesToSVG.replace(ct1))
113
125
  end
114
126
 
115
127
  def test_replace_one_travis_branch_http
116
128
  ct1 = "# README\n\nHello ![](http://travis-ci.org/usr/re.png?branch=aa)"
117
- ct2 = "# README\n\nHello ![](https://img.shields.io/travis/usr/re/aa.svg)"
129
+ ct2 = "# README\n\nHello ![](https://travis-ci.org/usr/re.svg?branch=aa)"
118
130
  assert_equal(ct2, BadgesToSVG.replace(ct1))
119
131
  end
120
132
 
121
- ## gittip
133
+ ## gratipay
122
134
 
123
- def test_replace_one_gittip_http
135
+ def test_replace_one_gittip_gratipay_http
124
136
  ct1 = "here is a badge: ![](http://img.shields.io/gittip/sferik.png)"
125
- ct2 = "here is a badge: ![](https://img.shields.io/gittip/sferik.svg)"
137
+ ct2 = "here is a badge: ![](https://img.shields.io/gratipay/user/sferik.svg)"
126
138
  assert_equal(ct2, BadgesToSVG.replace(ct1))
127
139
  end
128
140
 
129
- def test_replace_one_gittip_https
141
+ def test_replace_one_gittip_gratipay_https
130
142
  ct1 = "here is a badge: ![](https://img.shields.io/gittip/sferik.png)"
131
- ct2 = "here is a badge: ![](https://img.shields.io/gittip/sferik.svg)"
143
+ ct2 = "here is a badge: ![](https://img.shields.io/gratipay/user/sferik.svg)"
144
+ assert_equal(ct2, BadgesToSVG.replace(ct1))
145
+ end
146
+
147
+ def test_replace_one_gittip_gratipay_svg
148
+ ct1 = "here is a badge: ![](http://img.shields.io/gittip/sferik.svg)"
149
+ ct2 = "here is a badge: ![](https://img.shields.io/gratipay/user/sferik.svg)"
132
150
  assert_equal(ct2, BadgesToSVG.replace(ct1))
133
151
  end
134
152
 
@@ -188,13 +206,13 @@ class BadgesToSVGTests < Test::Unit::TestCase
188
206
 
189
207
  def test_replace_one_gemnasium_http
190
208
  ct1 = "![](http://gemnasium.com/sferik/t.png)"
191
- ct2 = "![](https://img.shields.io/gemnasium/sferik/t.svg)"
209
+ ct2 = "![](https://gemnasium.com/sferik/t.svg)"
192
210
  assert_equal(ct2, BadgesToSVG.replace(ct1))
193
211
  end
194
212
 
195
213
  def test_replace_one_gemnasium_https
196
214
  ct1 = "![](https://gemnasium.com/sferik/t.png)"
197
- ct2 = "![](https://img.shields.io/gemnasium/sferik/t.svg)"
215
+ ct2 = "![](https://gemnasium.com/sferik/t.svg)"
198
216
  assert_equal(ct2, BadgesToSVG.replace(ct1))
199
217
  end
200
218
 
@@ -276,17 +294,25 @@ class BadgesToSVGTests < Test::Unit::TestCase
276
294
  assert_equal(ct2, BadgesToSVG.replace(ct1))
277
295
  end
278
296
 
297
+ ## inch-ci
298
+
299
+ def test_replace_one_inch_ci
300
+ ct1 = '![Inline docs](http://inch-ci.org/github/bfontaine/Graphs.rb.png?branch=master)'
301
+ ct2 = '![Inline docs](https://inch-ci.org/github/bfontaine/Graphs.rb.svg?branch=master)'
302
+ assert_equal(ct2, BadgesToSVG.replace(ct1))
303
+ end
304
+
279
305
  ## misc
280
306
 
281
307
  def test_replace_misc_png_http
282
308
  ct1 = "![](http://img.shields.io/foo/bar-qux/zzz.png)"
283
- ct2 = ct1.sub(/\.png/, '.svg').sub(/http:/, 'https:')
309
+ ct2 = "![](https://img.shields.io/foo/bar-qux/zzz.svg)"
284
310
  assert_equal(ct2, BadgesToSVG.replace(ct1))
285
311
  end
286
312
 
287
313
  def test_replace_misc_png_https
288
314
  ct1 = "![](https://img.shields.io/foo/bar-qux/zzz.png)"
289
- ct2 = ct1.sub(/\.png/, '.svg').sub(/http:/, 'https:')
315
+ ct2 = "![](https://img.shields.io/foo/bar-qux/zzz.svg)"
290
316
  assert_equal(ct2, BadgesToSVG.replace(ct1))
291
317
  end
292
318
 
metadata CHANGED
@@ -1,83 +1,105 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: badges2svg
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Baptiste Fontaine
8
8
  autorequire:
9
9
  bindir: bin
10
- cert_chain: []
11
- date: 2014-03-14 00:00:00.000000000 Z
10
+ cert_chain:
11
+ - |
12
+ -----BEGIN CERTIFICATE-----
13
+ MIIDaDCCAlCgAwIBAgIBATANBgkqhkiG9w0BAQUFADA9MRAwDgYDVQQDDAdiYXRp
14
+ Zm9uMRUwEwYKCZImiZPyLGQBGRYFeWFob28xEjAQBgoJkiaJk/IsZAEZFgJmcjAe
15
+ Fw0xNTEyMjMwMTExMTZaFw0xNjEyMjIwMTExMTZaMD0xEDAOBgNVBAMMB2JhdGlm
16
+ b24xFTATBgoJkiaJk/IsZAEZFgV5YWhvbzESMBAGCgmSJomT8ixkARkWAmZyMIIB
17
+ IjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEA0en8u9i10EQtkp3SUnXnXo0W
18
+ UISZyvp2kS22c2/FXYg566dtfkp3pwBOZi3gvRYAKpmXAwbynOANdm2bfzQiG+Br
19
+ 0966dfY0SIbFuhaueJ8JUm5o/nxxCiKxuvCFs5899SJxyzmD3NNVzjTdrSU6UTgx
20
+ Q7K/r2MRYxBmPBbi8wdxyP1Ko36o9BJdLNrUiAVec1VXOlqA9Iw8CyrlG3V1snNl
21
+ efNVzZ+sMCkR73IyxRRwRgPws2jo2/8LfKcL+J3mz4ekBs4PoyOCWCnPlpBjAwkx
22
+ OzzDCjpxYbn/SYNHC8MxVdgap7jEX75ogkfpGOrAEdiPASnc2nFKqbJNxX7hCQID
23
+ AQABo3MwcTAJBgNVHRMEAjAAMAsGA1UdDwQEAwIEsDAdBgNVHQ4EFgQU2BKQg2pq
24
+ izVT9CkLdQo+nHNlvpQwGwYDVR0RBBQwEoEQYmF0aWZvbkB5YWhvby5mcjAbBgNV
25
+ HRIEFDASgRBiYXRpZm9uQHlhaG9vLmZyMA0GCSqGSIb3DQEBBQUAA4IBAQBkPKEW
26
+ urPeZb+IHuqWMqpzL/42fU4QuVUYDswLq+V0tXwnHo+okAq00Xh0yr0OaDBvm0mW
27
+ al9ZGC0RzaSQa+9mPd0t39oaWdtY7TOxQX3OC3vxdZ794gqyQgNxOmajFl22NY01
28
+ vxMAeZOu+IC5s2pQyUG0Gsq2sRbquW1mj8OC8KI3WWcECqGFOIOdXYTsqVqhwcN1
29
+ OpgZkC/pnOJanbP2ex2OHjlwFlpQ2PPAhoIG3mU1HEYXBZuP7+DUgNNgpopX83A5
30
+ 0df+9hsqme8UngbwGqM1XgU4dUlXNaoHejAm/d9IrRPvqE2oFsS9ytHShth2bC43
31
+ LPBfw/xSG5R4RjMC
32
+ -----END CERTIFICATE-----
33
+ date: 2016-03-24 00:00:00.000000000 Z
12
34
  dependencies:
13
35
  - !ruby/object:Gem::Dependency
14
36
  name: trollop
15
37
  requirement: !ruby/object:Gem::Requirement
16
38
  requirements:
17
- - - ~>
39
+ - - "~>"
18
40
  - !ruby/object:Gem::Version
19
41
  version: '2.0'
20
42
  type: :runtime
21
43
  prerelease: false
22
44
  version_requirements: !ruby/object:Gem::Requirement
23
45
  requirements:
24
- - - ~>
46
+ - - "~>"
25
47
  - !ruby/object:Gem::Version
26
48
  version: '2.0'
27
49
  - !ruby/object:Gem::Dependency
28
50
  name: simplecov
29
51
  requirement: !ruby/object:Gem::Requirement
30
52
  requirements:
31
- - - ~>
53
+ - - "~>"
32
54
  - !ruby/object:Gem::Version
33
55
  version: '0.8'
34
56
  type: :development
35
57
  prerelease: false
36
58
  version_requirements: !ruby/object:Gem::Requirement
37
59
  requirements:
38
- - - ~>
60
+ - - "~>"
39
61
  - !ruby/object:Gem::Version
40
62
  version: '0.8'
41
63
  - !ruby/object:Gem::Dependency
42
64
  name: rake
43
65
  requirement: !ruby/object:Gem::Requirement
44
66
  requirements:
45
- - - ~>
67
+ - - "~>"
46
68
  - !ruby/object:Gem::Version
47
69
  version: '10.1'
48
70
  type: :development
49
71
  prerelease: false
50
72
  version_requirements: !ruby/object:Gem::Requirement
51
73
  requirements:
52
- - - ~>
74
+ - - "~>"
53
75
  - !ruby/object:Gem::Version
54
76
  version: '10.1'
55
77
  - !ruby/object:Gem::Dependency
56
78
  name: test-unit
57
79
  requirement: !ruby/object:Gem::Requirement
58
80
  requirements:
59
- - - ~>
81
+ - - "~>"
60
82
  - !ruby/object:Gem::Version
61
83
  version: '2.5'
62
84
  type: :development
63
85
  prerelease: false
64
86
  version_requirements: !ruby/object:Gem::Requirement
65
87
  requirements:
66
- - - ~>
88
+ - - "~>"
67
89
  - !ruby/object:Gem::Version
68
90
  version: '2.5'
69
91
  - !ruby/object:Gem::Dependency
70
92
  name: coveralls
71
93
  requirement: !ruby/object:Gem::Requirement
72
94
  requirements:
73
- - - ~>
95
+ - - "~>"
74
96
  - !ruby/object:Gem::Version
75
97
  version: '0.7'
76
98
  type: :development
77
99
  prerelease: false
78
100
  version_requirements: !ruby/object:Gem::Requirement
79
101
  requirements:
80
- - - ~>
102
+ - - "~>"
81
103
  - !ruby/object:Gem::Version
82
104
  version: '0.7'
83
105
  description: Parse a markdown file and replace PNG badges with SVG ones.
@@ -100,19 +122,20 @@ require_paths:
100
122
  - lib
101
123
  required_ruby_version: !ruby/object:Gem::Requirement
102
124
  requirements:
103
- - - '>='
125
+ - - ">="
104
126
  - !ruby/object:Gem::Version
105
127
  version: '0'
106
128
  required_rubygems_version: !ruby/object:Gem::Requirement
107
129
  requirements:
108
- - - '>='
130
+ - - ">="
109
131
  - !ruby/object:Gem::Version
110
132
  version: '0'
111
133
  requirements: []
112
134
  rubyforge_project:
113
- rubygems_version: 2.2.1
135
+ rubygems_version: 2.5.1
114
136
  signing_key:
115
137
  specification_version: 4
116
138
  summary: Replace GitHub PNG badges into SVG ones
117
139
  test_files:
118
140
  - tests/tests.rb
141
+ has_rdoc:
metadata.gz.sig ADDED
Binary file