badges2svg 0.1.0
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 +7 -0
- data/bin/badges2svg +26 -0
- data/lib/badges2svg.rb +104 -0
- data/tests/tests.rb +245 -0
- metadata +118 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 85ed3f975ac572f368e96138a1faffed45c08879
|
4
|
+
data.tar.gz: 4b03e753f135fcebc11ef4a6ddfc24f26169017f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8914c8c2e49d53b73f8ee53159c731b082827d076203bbcd12b76cf8369b69e47b9d746cc9226dcb3551a27bc672eb91aee33ec37ab12bdc9ca4babe351d9dd6
|
7
|
+
data.tar.gz: 1871ed4504be163892781a8393fa76534fe2fe5c95da957d089351cd301f2a277faf4458b678071d0479f609e8fbb5dbed242cfcd8f359df79dc9d31854839e9
|
data/bin/badges2svg
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
|
4
|
+
require 'trollop'
|
5
|
+
require 'badges2svg'
|
6
|
+
|
7
|
+
opts = Trollop.options do
|
8
|
+
version "badges2svg #{BadgesToSVG.version}"
|
9
|
+
banner <<-EOS
|
10
|
+
badges2svg is a tool to replace your PNG GitHub badges into SVG ones.
|
11
|
+
|
12
|
+
Usage:
|
13
|
+
badges2svg <file>
|
14
|
+
EOS
|
15
|
+
end
|
16
|
+
|
17
|
+
if ARGV.empty?
|
18
|
+
puts 'Error: No file provided. Use -h or --help to see the help.'
|
19
|
+
exit 1
|
20
|
+
end
|
21
|
+
|
22
|
+
content = File.read(ARGV[0])
|
23
|
+
|
24
|
+
File.open(ARGV[0], 'w') do |f|
|
25
|
+
f.write(BadgesToSVG.replace(content))
|
26
|
+
end
|
data/lib/badges2svg.rb
ADDED
@@ -0,0 +1,104 @@
|
|
1
|
+
module BadgesToSVG
|
2
|
+
class << self
|
3
|
+
|
4
|
+
ROOT = 'https://img.shields.io'
|
5
|
+
|
6
|
+
# see http://shields.io/
|
7
|
+
RULES = [
|
8
|
+
{ :name => :travis_branch,
|
9
|
+
:pattern => 'https?://(?:secure.)?travis-ci.org/%{user}/%{repo}.png' +
|
10
|
+
'\\?branch=%{branch}',
|
11
|
+
:string => '/travis/%{user}/%{repo}/%{branch}.svg'
|
12
|
+
},
|
13
|
+
{
|
14
|
+
:name => :travis,
|
15
|
+
:pattern => 'https?://(?:secure.)?travis-ci.org/%{user}/%{repo}.png',
|
16
|
+
:string => '/travis/%{user}/%{repo}.svg'
|
17
|
+
},
|
18
|
+
{
|
19
|
+
:name => :gittip,
|
20
|
+
:pattern => 'https?://img.shields.io/gittip/%{user}.png',
|
21
|
+
:string => '/gittip/%{user}.svg'
|
22
|
+
},
|
23
|
+
{
|
24
|
+
:name => :coveralls_branch,
|
25
|
+
:pattern => 'https?://coveralls.io/repos/%{user}/%{repo}/badge.png' +
|
26
|
+
'\\?branch=%{branch}',
|
27
|
+
:string => '/coveralls/%{user}/%{repo}/%{branch}.svg'
|
28
|
+
},
|
29
|
+
{
|
30
|
+
:name => :coveralls,
|
31
|
+
:pattern => 'https?://coveralls.io/repos/%{user}/%{repo}/badge.png',
|
32
|
+
:string => '/coveralls/%{user}/%{repo}.svg'
|
33
|
+
},
|
34
|
+
{
|
35
|
+
:name => :gemnasium,
|
36
|
+
:pattern => 'https?://gemnasium.com/%{user}/%{repo}.png',
|
37
|
+
:string => '/gemnasium/%{user}/%{repo}.svg'
|
38
|
+
},
|
39
|
+
{
|
40
|
+
:name => :code_climate,
|
41
|
+
:pattern => 'https://codeclimate.com/github/%{user}/%{repo}.png',
|
42
|
+
:string => '/codeclimate/github/%{user}/%{repo}.svg'
|
43
|
+
},
|
44
|
+
|
45
|
+
{
|
46
|
+
:name => :gem_version,
|
47
|
+
:pattern => 'https?://badge.fury.io/rb/%{repo}(?:@2x)?.png',
|
48
|
+
:string => '/gem/v/%{repo}.svg'
|
49
|
+
},
|
50
|
+
{
|
51
|
+
:name => :npm_version,
|
52
|
+
:pattern => 'https?://badge.fury.io/js/%{repo}(?:@2x)?.png',
|
53
|
+
:string => '/npm/v/%{repo}.svg'
|
54
|
+
},
|
55
|
+
{
|
56
|
+
:name => :pypi_version,
|
57
|
+
:pattern => 'https?://badge.fury.io/py/%{repo}(?:@2x)?.png',
|
58
|
+
:string => '/pypi/v/%{repo}.svg'
|
59
|
+
},
|
60
|
+
{
|
61
|
+
:name => :packagist_version,
|
62
|
+
:pattern => 'https?://poser.pugx.org/%{user}/%{repo}/version.png',
|
63
|
+
:string => '/packagist/v/%{user}/%{repo}.svg'
|
64
|
+
},
|
65
|
+
|
66
|
+
{
|
67
|
+
:name => :packagist_downloads,
|
68
|
+
:pattern => 'https?://poser.pugx.org/%{user}/%{repo}/d/total.png',
|
69
|
+
:string => '/packagist/dm/%{user}/%{repo}.svg'
|
70
|
+
},
|
71
|
+
{
|
72
|
+
:name => :pypi_downloads,
|
73
|
+
:pattern => 'https?://pypip.in/d/%{repo}/badge.png',
|
74
|
+
:string => '/pypi/dm/%{repo}.svg'
|
75
|
+
},
|
76
|
+
|
77
|
+
{
|
78
|
+
:name => :misc_png,
|
79
|
+
:pattern => 'https?://img.shields.io/%{path}.png',
|
80
|
+
:string => '/%{path}.svg'
|
81
|
+
},
|
82
|
+
]
|
83
|
+
|
84
|
+
def version
|
85
|
+
'0.1.0'
|
86
|
+
end
|
87
|
+
|
88
|
+
def compile_pattern(pat, *a)
|
89
|
+
pat = pat.gsub(/\./, '\\.')
|
90
|
+
Regexp.new ("\\b#{pat.gsub(/%\{(\w+)\}/, "(?<\\1>.+?)")}\\b")
|
91
|
+
end
|
92
|
+
|
93
|
+
def replace ct
|
94
|
+
content = ct.clone
|
95
|
+
RULES.each do |r|
|
96
|
+
content.gsub!(compile_pattern(r[:pattern]),
|
97
|
+
ROOT + r[:string].gsub(/%\{(\w+)\}/, "\\\\k<\\1>"))
|
98
|
+
end
|
99
|
+
|
100
|
+
content
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
104
|
+
end
|
data/tests/tests.rb
ADDED
@@ -0,0 +1,245 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
# -*- coding: UTF-8 -*-
|
3
|
+
|
4
|
+
require 'coveralls'
|
5
|
+
Coveralls.wear!
|
6
|
+
|
7
|
+
require 'test/unit'
|
8
|
+
require 'simplecov'
|
9
|
+
|
10
|
+
test_dir = File.expand_path( File.dirname(__FILE__) )
|
11
|
+
|
12
|
+
SimpleCov.formatter = Coveralls::SimpleCov::Formatter
|
13
|
+
SimpleCov.start { add_filter '/tests/' }
|
14
|
+
|
15
|
+
require 'badges2svg'
|
16
|
+
|
17
|
+
for t in Dir.glob( File.join( test_dir, '*_tests.rb' ) )
|
18
|
+
require t
|
19
|
+
end
|
20
|
+
|
21
|
+
class BadgesToSVGTests < Test::Unit::TestCase
|
22
|
+
|
23
|
+
# == BadgesToSVG#version == #
|
24
|
+
|
25
|
+
def test_version
|
26
|
+
assert(BadgesToSVG.version =~ /^\d+\.\d+\.\d+/)
|
27
|
+
end
|
28
|
+
|
29
|
+
# == BadgesToSVG#compile_pattern == #
|
30
|
+
|
31
|
+
def test_compile_pattern_empty
|
32
|
+
assert_equal(/\b\b/, BadgesToSVG.compile_pattern(""))
|
33
|
+
end
|
34
|
+
|
35
|
+
def test_compile_pattern_no_special_chars
|
36
|
+
assert_equal(/\bfoobar\b/, BadgesToSVG.compile_pattern("foobar"))
|
37
|
+
assert_equal(/\bq-a yo\b/, BadgesToSVG.compile_pattern("q-a yo"))
|
38
|
+
end
|
39
|
+
|
40
|
+
def test_compile_pattern_with_special_chars
|
41
|
+
assert_equal(/\bfoo\.bar\b/, BadgesToSVG.compile_pattern("foo.bar"))
|
42
|
+
assert_equal(/\ba?\b/, BadgesToSVG.compile_pattern("a?"))
|
43
|
+
end
|
44
|
+
|
45
|
+
def test_compile_pattern_with_one_field_name
|
46
|
+
assert_equal(/\b(?<abc>.+?)\b/, BadgesToSVG.compile_pattern("%{abc}"))
|
47
|
+
assert_equal(/\ba?\b/, BadgesToSVG.compile_pattern("a?"))
|
48
|
+
end
|
49
|
+
|
50
|
+
def test_compile_pattern_with_multiple_field_names
|
51
|
+
assert_equal(/\b(?<a>.+?)\/(?<b>.+?)\b/,
|
52
|
+
BadgesToSVG.compile_pattern("%{a}/%{b}"))
|
53
|
+
end
|
54
|
+
|
55
|
+
# == BadgesToSVG#replace == #
|
56
|
+
|
57
|
+
def test_replace_empty_file
|
58
|
+
assert_equal("", BadgesToSVG.replace(""))
|
59
|
+
end
|
60
|
+
|
61
|
+
def test_replace_simple_file
|
62
|
+
ct = "# README\n\nHello World!"
|
63
|
+
assert_equal(ct, BadgesToSVG.replace(ct))
|
64
|
+
end
|
65
|
+
|
66
|
+
## travis
|
67
|
+
|
68
|
+
def test_replace_one_travis_https
|
69
|
+
ct1 = "# README\n\nHello "
|
70
|
+
ct2 = "# README\n\nHello "
|
71
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
72
|
+
end
|
73
|
+
|
74
|
+
def test_replace_one_travis_http
|
75
|
+
ct1 = "# README\n\nHello "
|
76
|
+
ct2 = "# README\n\nHello "
|
77
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
78
|
+
end
|
79
|
+
|
80
|
+
## travis_branch
|
81
|
+
|
82
|
+
def test_replace_one_travis_branch_https
|
83
|
+
ct1 = "# README\n\nHello "
|
84
|
+
ct2 = "# README\n\nHello "
|
85
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
86
|
+
end
|
87
|
+
|
88
|
+
def test_replace_one_travis_branch_http
|
89
|
+
ct1 = "# README\n\nHello "
|
90
|
+
ct2 = "# README\n\nHello "
|
91
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
92
|
+
end
|
93
|
+
|
94
|
+
## gittip
|
95
|
+
|
96
|
+
def test_replace_one_gittip_http
|
97
|
+
ct1 = "here is a badge: "
|
98
|
+
ct2 = "here is a badge: "
|
99
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
100
|
+
end
|
101
|
+
|
102
|
+
def test_replace_one_gittip_https
|
103
|
+
ct1 = "here is a badge: "
|
104
|
+
ct2 = "here is a badge: "
|
105
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
106
|
+
end
|
107
|
+
|
108
|
+
## coveralls
|
109
|
+
|
110
|
+
def test_replace_one_coveralls_http
|
111
|
+
ct1 = "hello "
|
112
|
+
ct2 = "hello "
|
113
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
114
|
+
end
|
115
|
+
|
116
|
+
def test_replace_one_coveralls_https
|
117
|
+
ct1 = "hello "
|
118
|
+
ct2 = "hello "
|
119
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
120
|
+
end
|
121
|
+
|
122
|
+
## coveralls_branch
|
123
|
+
|
124
|
+
def test_replace_one_coveralls_branch_http
|
125
|
+
ct1 = "hello "
|
126
|
+
ct2 = "hello "
|
127
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
128
|
+
end
|
129
|
+
|
130
|
+
def test_replace_one_coveralls_branch_https
|
131
|
+
ct1 = "hello "
|
132
|
+
ct2 = "hello "
|
133
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
134
|
+
end
|
135
|
+
|
136
|
+
## gemnasium
|
137
|
+
|
138
|
+
def test_replace_one_gemnasium_http
|
139
|
+
ct1 = ""
|
140
|
+
ct2 = ""
|
141
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
142
|
+
end
|
143
|
+
|
144
|
+
def test_replace_one_gemnasium_https
|
145
|
+
ct1 = ""
|
146
|
+
ct2 = ""
|
147
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
148
|
+
end
|
149
|
+
|
150
|
+
## code_climate
|
151
|
+
|
152
|
+
def test_replace_one_code_climate
|
153
|
+
ct1 = ""
|
154
|
+
ct2 = ""
|
155
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
156
|
+
end
|
157
|
+
|
158
|
+
## *_version
|
159
|
+
|
160
|
+
### gem
|
161
|
+
|
162
|
+
def test_replace_one_gem_version
|
163
|
+
ct1 = ""
|
164
|
+
ct2 = ""
|
165
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
166
|
+
end
|
167
|
+
|
168
|
+
def test_replace_one_gem_version_retina
|
169
|
+
ct1 = ""
|
170
|
+
ct2 = ""
|
171
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
172
|
+
end
|
173
|
+
|
174
|
+
### pypi
|
175
|
+
|
176
|
+
def test_replace_one_pypi_version
|
177
|
+
ct1 = ''
|
178
|
+
ct2 = ''
|
179
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
180
|
+
end
|
181
|
+
|
182
|
+
def test_replace_one_pypi_version_retina
|
183
|
+
ct1 = ''
|
184
|
+
ct2 = ''
|
185
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
186
|
+
end
|
187
|
+
|
188
|
+
### npm
|
189
|
+
|
190
|
+
def test_replace_one_npm_version
|
191
|
+
ct1 = ''
|
192
|
+
ct2 = ''
|
193
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
194
|
+
end
|
195
|
+
|
196
|
+
def test_replace_one_npm_version_retina
|
197
|
+
ct1 = ''
|
198
|
+
ct2 = ''
|
199
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
200
|
+
end
|
201
|
+
|
202
|
+
### packagist
|
203
|
+
|
204
|
+
def test_replace_one_packagist_version
|
205
|
+
ct1 = ''
|
206
|
+
ct2 = ''
|
207
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
208
|
+
end
|
209
|
+
|
210
|
+
## *_downloads
|
211
|
+
|
212
|
+
### pypi
|
213
|
+
|
214
|
+
def test_replace_one_pypi_downloads
|
215
|
+
ct1 = ''
|
216
|
+
ct2 = ''
|
217
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
218
|
+
end
|
219
|
+
|
220
|
+
### packagist
|
221
|
+
|
222
|
+
def test_replace_one_packagist_downloads
|
223
|
+
ct1 = ''
|
224
|
+
ct2 = ''
|
225
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
226
|
+
end
|
227
|
+
|
228
|
+
## misc
|
229
|
+
|
230
|
+
def test_replace_misc_png_http
|
231
|
+
ct1 = ""
|
232
|
+
ct2 = ct1.sub(/\.png/, '.svg').sub(/http:/, 'https:')
|
233
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
234
|
+
end
|
235
|
+
|
236
|
+
def test_replace_misc_png_https
|
237
|
+
ct1 = ""
|
238
|
+
ct2 = ct1.sub(/\.png/, '.svg').sub(/http:/, 'https:')
|
239
|
+
assert_equal(ct2, BadgesToSVG.replace(ct1))
|
240
|
+
end
|
241
|
+
|
242
|
+
end
|
243
|
+
|
244
|
+
|
245
|
+
exit Test::Unit::AutoRunner.run
|
metadata
ADDED
@@ -0,0 +1,118 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: badges2svg
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Baptiste Fontaine
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-03-04 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: trollop
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '2.0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '2.0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: simplecov
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0.8'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0.8'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ~>
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.1'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ~>
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.1'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: test-unit
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '2.5'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '2.5'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: coveralls
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0.7'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0.7'
|
83
|
+
description: Parse a markdown file and replace PNG badges with SVG ones.
|
84
|
+
email: b@ptistefontaine.fr
|
85
|
+
executables:
|
86
|
+
- badges2svg
|
87
|
+
extensions: []
|
88
|
+
extra_rdoc_files: []
|
89
|
+
files:
|
90
|
+
- bin/badges2svg
|
91
|
+
- lib/badges2svg.rb
|
92
|
+
- tests/tests.rb
|
93
|
+
homepage: https://github.com/bfontaine/badges2svg
|
94
|
+
licenses:
|
95
|
+
- MIT
|
96
|
+
metadata: {}
|
97
|
+
post_install_message:
|
98
|
+
rdoc_options: []
|
99
|
+
require_paths:
|
100
|
+
- lib
|
101
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
102
|
+
requirements:
|
103
|
+
- - '>='
|
104
|
+
- !ruby/object:Gem::Version
|
105
|
+
version: '0'
|
106
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - '>='
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
requirements: []
|
112
|
+
rubyforge_project:
|
113
|
+
rubygems_version: 2.2.1
|
114
|
+
signing_key:
|
115
|
+
specification_version: 4
|
116
|
+
summary: Replace GitHub PNG badges into SVG ones
|
117
|
+
test_files:
|
118
|
+
- tests/tests.rb
|