badges2svg 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: 85ed3f975ac572f368e96138a1faffed45c08879
4
- data.tar.gz: 4b03e753f135fcebc11ef4a6ddfc24f26169017f
3
+ metadata.gz: 28a67d37ccc465a931a6ec0c49e13a2415496abc
4
+ data.tar.gz: da121e220315080aff3d776924e87917dfbbbb5f
5
5
  SHA512:
6
- metadata.gz: 8914c8c2e49d53b73f8ee53159c731b082827d076203bbcd12b76cf8369b69e47b9d746cc9226dcb3551a27bc672eb91aee33ec37ab12bdc9ca4babe351d9dd6
7
- data.tar.gz: 1871ed4504be163892781a8393fa76534fe2fe5c95da957d089351cd301f2a277faf4458b678071d0479f609e8fbb5dbed242cfcd8f359df79dc9d31854839e9
6
+ metadata.gz: 8b11570dce2060acddeda8aa444082ee77dad05e80a6416741993ce757c87e7693ba9574ef0015d991956dc2685feaa0708ccc0f808ed97dce87182f7ab51cab
7
+ data.tar.gz: 7e5f27704e9ed76eae4738652556fbb85053c57f0d7a40b95fa8055158ddce3189a35d660e4775be2b2c15af4fd43d9cd87f8d382d591cc1735884c43a7ad480
data/bin/badges2svg CHANGED
@@ -7,11 +7,16 @@ require 'badges2svg'
7
7
  opts = Trollop.options do
8
8
  version "badges2svg #{BadgesToSVG.version}"
9
9
  banner <<-EOS
10
- badges2svg is a tool to replace your PNG GitHub badges into SVG ones.
10
+ badges2svg is a tool to replace your PNG GitHub badges with resolution-independant SVG ones.
11
11
 
12
12
  Usage:
13
- badges2svg <file>
13
+ badges2svg [options] <file>
14
+
15
+ where [options] are:
14
16
  EOS
17
+
18
+ opt :https, 'use HTTPS in URLs', :default => true, :short => '-H'
19
+
15
20
  end
16
21
 
17
22
  if ARGV.empty?
@@ -19,8 +24,11 @@ if ARGV.empty?
19
24
  exit 1
20
25
  end
21
26
 
22
- content = File.read(ARGV[0])
27
+ if ARGV[0] == '-'
28
+ print BadgesToSVG.replace(STDIN.read, opts)
29
+ exit 0
30
+ end
23
31
 
24
32
  File.open(ARGV[0], 'w') do |f|
25
- f.write(BadgesToSVG.replace(content))
33
+ f.write(BadgesToSVG.replace(content, opts))
26
34
  end
data/lib/badges2svg.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  module BadgesToSVG
2
- class << self
3
2
 
4
- ROOT = 'https://img.shields.io'
3
+ @protocol = 'https'
4
+ @domain = 'img.shields.io'
5
+
6
+ class << self
5
7
 
6
8
  # see http://shields.io/
7
9
  RULES = [
@@ -82,7 +84,11 @@ module BadgesToSVG
82
84
  ]
83
85
 
84
86
  def version
85
- '0.1.0'
87
+ '0.1.1'
88
+ end
89
+
90
+ def root_url(opts={})
91
+ "#{opts[:protocol] || @protocol}://#{opts[:domain] || @domain}"
86
92
  end
87
93
 
88
94
  def compile_pattern(pat, *a)
@@ -90,11 +96,12 @@ module BadgesToSVG
90
96
  Regexp.new ("\\b#{pat.gsub(/%\{(\w+)\}/, "(?<\\1>.+?)")}\\b")
91
97
  end
92
98
 
93
- def replace ct
94
- content = ct.clone
99
+ def replace content, opts={}
100
+ root = root_url(opts)
95
101
  RULES.each do |r|
96
- content.gsub!(compile_pattern(r[:pattern]),
97
- ROOT + r[:string].gsub(/%\{(\w+)\}/, "\\\\k<\\1>"))
102
+ pat = compile_pattern(r[:pattern])
103
+ repl = root + r[:string].gsub(/%\{(\w+)\}/, "\\\\k<\\1>")
104
+ content.gsub!(pat, repl)
98
105
  end
99
106
 
100
107
  content
data/tests/tests.rb CHANGED
@@ -48,8 +48,35 @@ class BadgesToSVGTests < Test::Unit::TestCase
48
48
  end
49
49
 
50
50
  def test_compile_pattern_with_multiple_field_names
51
- assert_equal(/\b(?<a>.+?)\/(?<b>.+?)\b/,
52
- BadgesToSVG.compile_pattern("%{a}/%{b}"))
51
+ assert_equal(/\b(?<a>.+?)\/(?<b>.+?)\b/.to_s,
52
+ BadgesToSVG.compile_pattern("%{a}/%{b}").to_s)
53
+ end
54
+
55
+ # == BadgesToSVG#root_url == #
56
+
57
+ def test_root_url_default
58
+ assert_equal("https://img.shields.io", BadgesToSVG.root_url)
59
+ end
60
+
61
+ def test_root_url_custom_protocol
62
+ assert_equal("foobar://img.shields.io",
63
+ BadgesToSVG.root_url(:protocol => 'foobar'))
64
+ assert_equal("http://img.shields.io",
65
+ BadgesToSVG.root_url(:protocol => 'http'))
66
+ end
67
+
68
+ def test_root_url_custom_protocol_symbol
69
+ assert_equal("foobar://img.shields.io",
70
+ BadgesToSVG.root_url(:protocol => :foobar))
71
+ end
72
+
73
+ def test_root_url_custom_domain
74
+ assert_equal("https://bar", BadgesToSVG.root_url(:domain => 'bar'))
75
+ end
76
+
77
+ def test_root_url_custom_protocol_and_domain
78
+ s = "foo://bar"
79
+ assert_equal(s, BadgesToSVG.root_url(:protocol => 'foo', :domain => 'bar'))
53
80
  end
54
81
 
55
82
  # == BadgesToSVG#replace == #
@@ -239,6 +266,29 @@ class BadgesToSVGTests < Test::Unit::TestCase
239
266
  assert_equal(ct2, BadgesToSVG.replace(ct1))
240
267
  end
241
268
 
269
+ ## with options
270
+
271
+ ### custom protocol
272
+
273
+ def test_replace_with_custom_protocol
274
+ ct1 = '![](https://poser.pugx.org/foo/bar/d/total.png)'
275
+ ct2 = '![](foo://img.shields.io/packagist/dm/foo/bar.svg)'
276
+ assert_equal(ct2, BadgesToSVG.replace(ct1, :protocol => :foo))
277
+ end
278
+
279
+ def test_replace_with_custom_domain
280
+ ct1 = '![](https://poser.pugx.org/foo/bar/d/total.png)'
281
+ ct2 = '![](https://foobar.io/packagist/dm/foo/bar.svg)'
282
+ assert_equal(ct2, BadgesToSVG.replace(ct1, :domain => 'foobar.io'))
283
+ end
284
+
285
+ def test_replace_with_custom_protocol_domain
286
+ ct1 = '![](https://poser.pugx.org/foo/bar/d/total.png)'
287
+ ct2 = '![](http://foobar.io/packagist/dm/foo/bar.svg)'
288
+ assert_equal(ct2, BadgesToSVG.replace(ct1, :protocol => :http,
289
+ :domain => 'foobar.io'))
290
+ end
291
+
242
292
  end
243
293
 
244
294
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: badges2svg
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
  - Baptiste Fontaine
@@ -87,9 +87,9 @@ executables:
87
87
  extensions: []
88
88
  extra_rdoc_files: []
89
89
  files:
90
- - bin/badges2svg
91
90
  - lib/badges2svg.rb
92
91
  - tests/tests.rb
92
+ - bin/badges2svg
93
93
  homepage: https://github.com/bfontaine/badges2svg
94
94
  licenses:
95
95
  - MIT
@@ -110,7 +110,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
110
110
  version: '0'
111
111
  requirements: []
112
112
  rubyforge_project:
113
- rubygems_version: 2.2.1
113
+ rubygems_version: 2.0.3
114
114
  signing_key:
115
115
  specification_version: 4
116
116
  summary: Replace GitHub PNG badges into SVG ones