svgeez 0.2.4 → 0.2.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.codeclimate.yml +9 -0
- data/Rakefile +1 -1
- data/bin/svgeez +1 -1
- data/lib/svgeez/commands/watch.rb +1 -1
- data/lib/svgeez/sprite_builder.rb +33 -37
- data/lib/svgeez/version.rb +1 -1
- data/lib/svgeez.rb +2 -2
- data/svgeez.gemspec +6 -4
- metadata +11 -11
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8d3afb52b2f6c2e729e45e0424973b27b55915af
|
4
|
+
data.tar.gz: 985940a3598cc19bcc6204e67874717154179f86
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6500f825534a6f87d21cb1eda1f0eebe7654c1ff5c313486a7686fb6d07ba1ab86d5a24abb60bef7ace4c35ad6a1ec78d29c0471afd0ec49b5f4052b9a42d4dc
|
7
|
+
data.tar.gz: 382fa4b98557b1343c087b32e11e9194f9f23bca8855f34ec2b4ab75cafd604945bb3ef464e6da51c8394fd73c6211285d2eeea3029ea5400b9779d5df743f05
|
data/.codeclimate.yml
CHANGED
data/Rakefile
CHANGED
data/bin/svgeez
CHANGED
@@ -17,7 +17,7 @@ module Svgeez
|
|
17
17
|
end
|
18
18
|
|
19
19
|
def process(options)
|
20
|
-
Svgeez.logger.info %
|
20
|
+
Svgeez.logger.info %(Watching `#{File.expand_path(options['source'])}` for changes... Press ctrl-c to stop.)
|
21
21
|
|
22
22
|
listener = Listen.to(options['source'], only: /\.svg$/) do
|
23
23
|
Svgeez::Commands::Build.process(options)
|
@@ -3,56 +3,56 @@ module Svgeez
|
|
3
3
|
def initialize(options)
|
4
4
|
@source = File.expand_path(options.fetch('source', './'))
|
5
5
|
@destination = File.expand_path(options.fetch('destination', './_svgeez/svgeez.svg'))
|
6
|
-
@
|
6
|
+
@svgo = options['svgo']
|
7
7
|
end
|
8
8
|
|
9
9
|
def build
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
Svgeez.logger.info %{Successfully generated sprite at `#{destination_file_path}`.}
|
28
|
-
else
|
29
|
-
Svgeez.logger.warn %{No SVGs were found in `#{@source}`.}
|
10
|
+
if source_is_destination?
|
11
|
+
Svgeez.logger.error %(Setting `source` and `destination` to the same path isn't allowed!)
|
12
|
+
elsif source_file_paths.any?
|
13
|
+
Svgeez.logger.info %(Generating sprite at `#{destination_file_path}` from #{source_file_paths.length} SVG#{'s' if source_file_paths.length > 1}...)
|
14
|
+
|
15
|
+
# Make destination folder
|
16
|
+
FileUtils.mkdir_p(destination_folder_path)
|
17
|
+
|
18
|
+
# Notify if SVGO requested but not found
|
19
|
+
if @svgo && !svgo_installed?
|
20
|
+
Svgeez.logger.warn %(Unable to find `svgo` in your PATH. Continuing with standard sprite generation...)
|
21
|
+
end
|
22
|
+
|
23
|
+
# Write the file
|
24
|
+
File.open(destination_file_path, 'w') do |f|
|
25
|
+
f.write build_destination_file_contents
|
30
26
|
end
|
27
|
+
|
28
|
+
Svgeez.logger.info %(Successfully generated sprite at `#{destination_file_path}`.)
|
31
29
|
else
|
32
|
-
Svgeez.logger.
|
30
|
+
Svgeez.logger.warn %(No SVGs were found in `#{@source}`.)
|
33
31
|
end
|
34
32
|
end
|
35
33
|
|
34
|
+
private
|
35
|
+
|
36
36
|
def build_destination_file_contents
|
37
|
-
destination_file_contents = '<svg>'
|
38
|
-
source_file_paths.each do |file_path|
|
39
|
-
IO.read(file_path).match(/^<svg.*?(?<viewbox>viewBox=".*?").*?>(?<content>.*?)<\/svg>/m) do |matches|
|
40
|
-
file_contents << %{<symbol id="#{destination_file_id}-#{File.basename(file_path, '.svg').gsub(/['"\s]/, '-')}" #{matches[:viewbox]}>#{matches[:content]}</symbol>}
|
41
|
-
end
|
42
|
-
end
|
37
|
+
destination_file_contents = '<svg>'
|
43
38
|
|
44
|
-
|
39
|
+
source_file_paths.each do |file_path|
|
40
|
+
IO.read(file_path).match(%r{^<svg.*?(?<viewbox>viewBox=".*?").*?>(?<content>.*?)</svg>}m) do |matches|
|
41
|
+
destination_file_contents << %(<symbol id="#{destination_file_id}-#{File.basename(file_path, '.svg').gsub(/['"\s]/, '-')}" #{matches[:viewbox]}>#{matches[:content]}</symbol>)
|
42
|
+
end
|
45
43
|
end
|
46
44
|
|
47
|
-
|
45
|
+
destination_file_contents << '</svg>'
|
46
|
+
|
47
|
+
if @svgo && svgo_installed?
|
48
48
|
destination_file_contents = `cat <<EOF | svgo --disable=cleanupIDs -i - -o -\n#{destination_file_contents}\nEOF`
|
49
49
|
end
|
50
50
|
|
51
|
-
destination_file_contents.insert(4, %
|
51
|
+
destination_file_contents.insert(4, %( id="#{destination_file_id}" style="display: none;" version="1.1"))
|
52
52
|
end
|
53
53
|
|
54
54
|
def destination_file_id
|
55
|
-
@destination_file_id ||= File.basename(destination_file_name, '.svg').
|
55
|
+
@destination_file_id ||= File.basename(destination_file_name, '.svg').tr(' ', '-')
|
56
56
|
end
|
57
57
|
|
58
58
|
def destination_file_name
|
@@ -80,15 +80,11 @@ module Svgeez
|
|
80
80
|
end
|
81
81
|
|
82
82
|
def source_is_destination?
|
83
|
-
|
83
|
+
/^#{@source}/ =~ destination_folder_path
|
84
84
|
end
|
85
85
|
|
86
86
|
def svgo_installed?
|
87
87
|
@svgo_installed ||= find_executable0('svgo')
|
88
88
|
end
|
89
|
-
|
90
|
-
def use_svgo?
|
91
|
-
@use_svgo ||= @with_svgo && svgo_installed?
|
92
|
-
end
|
93
89
|
end
|
94
90
|
end
|
data/lib/svgeez/version.rb
CHANGED
data/lib/svgeez.rb
CHANGED
data/svgeez.gemspec
CHANGED
@@ -4,13 +4,15 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
|
4
4
|
require 'svgeez/version'
|
5
5
|
|
6
6
|
Gem::Specification.new do |spec|
|
7
|
+
spec.required_ruby_version = '>= 2.2.5'
|
8
|
+
|
7
9
|
spec.name = 'svgeez'
|
8
10
|
spec.version = Svgeez::VERSION
|
9
11
|
spec.authors = ['Jason Garber']
|
10
12
|
spec.email = ['jason@sixtwothree.org']
|
11
13
|
|
12
|
-
spec.summary =
|
13
|
-
spec.description =
|
14
|
+
spec.summary = 'Automatically generate an SVG sprite from a folder of SVG icons.'
|
15
|
+
spec.description = spec.summary
|
14
16
|
spec.homepage = 'https://github.com/jgarber623/svgeez'
|
15
17
|
spec.license = 'MIT'
|
16
18
|
|
@@ -19,9 +21,9 @@ Gem::Specification.new do |spec|
|
|
19
21
|
spec.require_paths = ['lib']
|
20
22
|
|
21
23
|
spec.add_development_dependency 'bundler', '~> 1.10'
|
22
|
-
spec.add_development_dependency 'codeclimate-test-reporter'
|
24
|
+
spec.add_development_dependency 'codeclimate-test-reporter', '~> 0.6.0'
|
23
25
|
spec.add_development_dependency 'rake', '~> 10.0'
|
24
|
-
spec.add_development_dependency 'rspec'
|
26
|
+
spec.add_development_dependency 'rspec', '~> 3.5'
|
25
27
|
spec.add_development_dependency 'rubocop', '~> 0.42.0'
|
26
28
|
|
27
29
|
spec.add_runtime_dependency 'listen', '~> 3.0'
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: svgeez
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.2.
|
4
|
+
version: 0.2.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jason Garber
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-08-
|
11
|
+
date: 2016-08-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -28,16 +28,16 @@ dependencies:
|
|
28
28
|
name: codeclimate-test-reporter
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
|
-
- - "
|
31
|
+
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version:
|
33
|
+
version: 0.6.0
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
|
-
- - "
|
38
|
+
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version:
|
40
|
+
version: 0.6.0
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -56,16 +56,16 @@ dependencies:
|
|
56
56
|
name: rspec
|
57
57
|
requirement: !ruby/object:Gem::Requirement
|
58
58
|
requirements:
|
59
|
-
- - "
|
59
|
+
- - "~>"
|
60
60
|
- !ruby/object:Gem::Version
|
61
|
-
version: '
|
61
|
+
version: '3.5'
|
62
62
|
type: :development
|
63
63
|
prerelease: false
|
64
64
|
version_requirements: !ruby/object:Gem::Requirement
|
65
65
|
requirements:
|
66
|
-
- - "
|
66
|
+
- - "~>"
|
67
67
|
- !ruby/object:Gem::Version
|
68
|
-
version: '
|
68
|
+
version: '3.5'
|
69
69
|
- !ruby/object:Gem::Dependency
|
70
70
|
name: rubocop
|
71
71
|
requirement: !ruby/object:Gem::Requirement
|
@@ -149,7 +149,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
149
149
|
requirements:
|
150
150
|
- - ">="
|
151
151
|
- !ruby/object:Gem::Version
|
152
|
-
version:
|
152
|
+
version: 2.2.5
|
153
153
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
154
154
|
requirements:
|
155
155
|
- - ">="
|