svgeez 2.0.1 → 3.0.0

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
  SHA256:
3
- metadata.gz: 3a34b3e2f43c0d78cd9f77457795fc021a5576acec7209a235d5d150990917da
4
- data.tar.gz: f26e9b0c2b70381cd939cda274240454b69fb575f004e853b9afc8e08c5dd237
3
+ metadata.gz: 51f2b828f3bd9b6247ac823ba7cf5c2f85175ea21245da946bdf272ef8bfb643
4
+ data.tar.gz: 97badde987dd8ed3e646a3cfa666c0ed43f637bb9393f6cd7347866bb89aafb0
5
5
  SHA512:
6
- metadata.gz: e059e288c8d7a92dbeb8a2f5c099004519c2cab971cfaf6d9f33f749aeda842b03cb60fce87f05c7f65370b42f24d611dfd63f73ab819a647e4bd58441f7fa4a
7
- data.tar.gz: 0fceee63b7a84300a7485a02e898909ba3e15540cecc445a095858a34da003489a24704e64ba6ab36beb9a3dff4c69a17cd83035b94a8c65943e5a6d7e976c0a
6
+ metadata.gz: eb5ab0a9a2ea91fcff2bf9c907769413ea4e180e5be9eea735a8d1f8113cd08645b63c082d151522e94a0c425fef3e64cd0e3494118797ec50db1c3f4fe98042
7
+ data.tar.gz: 8f486f1289987246c90733b15ec7913c62f7bd6a73b31efa765f4f6c1766836cd3cbe9ca3e8b8e1e72c4b20366b23faf753c109b3e0d7752d92aac8622910bb3
@@ -0,0 +1,16 @@
1
+ detectors:
2
+ DuplicateMethodCall:
3
+ max_calls: 2
4
+ IrresponsibleModule:
5
+ enabled: false
6
+ TooManyStatements:
7
+ exclude:
8
+ - Svgeez::Builder#build
9
+ - Svgeez::Builder#initialize
10
+ - Svgeez::Commands::Watch#process
11
+ UtilityFunction:
12
+ exclude:
13
+ - Svgeez::Elements::SymbolElement#element_contents
14
+
15
+ exclude_paths:
16
+ - vendor/
@@ -1,18 +1,21 @@
1
1
  require:
2
+ - rubocop-performance
2
3
  - rubocop-rspec
3
4
 
5
+ Layout/AlignHash:
6
+ Exclude:
7
+ - svgeez.gemspec
8
+
4
9
  Metrics/BlockLength:
5
10
  Exclude:
6
- - "spec/**/*"
11
+ - spec/**/*
12
+ - svgeez.gemspec
7
13
 
8
14
  Metrics/LineLength:
9
15
  Enabled: false
10
16
 
11
- RSpec/AnyInstance:
12
- Enabled: false
13
-
14
- RSpec/MessageSpies:
15
- EnforcedStyle: receive
17
+ Naming/RescuedExceptionsVariableName:
18
+ PreferredName: exception
16
19
 
17
20
  RSpec/MultipleExpectations:
18
21
  Max: 2
@@ -22,3 +25,6 @@ Style/Documentation:
22
25
 
23
26
  Style/FrozenStringLiteralComment:
24
27
  Enabled: false
28
+
29
+ Style/SymbolArray:
30
+ Enabled: false
@@ -1 +1 @@
1
- 2.4.5
1
+ 2.4.6
@@ -1,21 +1,19 @@
1
1
  language: ruby
2
2
  rvm:
3
- - 2.4.5
4
- - 2.5.3
5
- - 2.6.0
3
+ - 2.4.6
4
+ - 2.5.5
5
+ - 2.6.2
6
6
  cache:
7
7
  - bundler
8
8
  before_install:
9
- - gem install bundler -v '~> 1.17'
9
+ - gem update --system
10
+ - gem install bundler
10
11
  - nvm install node
11
12
  - npm install -g svgo
12
13
  before_script:
13
14
  - curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
14
15
  - chmod +x ./cc-test-reporter
15
16
  - ./cc-test-reporter before-build
16
- script:
17
- - bundle exec rubocop
18
- - bundle exec rake
19
17
  after_script:
20
18
  - ./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT
21
19
  notifications:
@@ -1,5 +1,17 @@
1
1
  # Changelog
2
2
 
3
+ ## 3.0.0 / 2019-08-02
4
+
5
+ ### Breaking Changes
6
+
7
+ - Bump required minimum SVGO version to 1.3.0 ([afa24c6](https://github.com/jgarber623/svgeez/commit/afa24c6)).
8
+
9
+ ### Additional Enhancements
10
+
11
+ - Refactor command classes ([02f420c](https://github.com/jgarber623/svgeez/commit/02f420c)).
12
+ - Refactor specs ([995f950](https://github.com/jgarber623/svgeez/commit/)).
13
+ - Update development dependencies.
14
+
3
15
  ## 2.0.1 / 2019-01-03
4
16
 
5
17
  - Expand supported Ruby versions to include 2.6 ([0facfd0](https://github.com/jgarber623/svgeez/commit/0facfd0)).
@@ -8,7 +20,7 @@
8
20
 
9
21
  - Refactor classes to use `attr_reader`s ([c62780f](https://github.com/jgarber623/svgeez/commit/c62780f))
10
22
  - Change required Ruby versions and liberalize dependency constraints ([35fcadb](https://github.com/jgarber623/svgeez/commit/35fcadb))
11
- - Change project Ruby version to 2.4.5 ([301d341](https://github.com/jgarber623/svgeez/commit/301d341))
23
+ - Change project Ruby version to 2.4.6 ([301d341](https://github.com/jgarber623/svgeez/commit/301d341))
12
24
  - Bump required SVGO version to 1.1.1 ([28741fc](https://github.com/jgarber623/svgeez/commit/28741fc))
13
25
 
14
26
  ## Previous Releases
@@ -8,9 +8,9 @@ There are a couple ways you can help improve svgeez:
8
8
 
9
9
  ## Getting Started
10
10
 
11
- svgeez is developed using Ruby 2.4.5 and is additionally tested against Ruby 2.5.3 and 2.6.0 using [Travis CI](https://travis-ci.org/jgarber623/svgeez).
11
+ svgeez is developed using Ruby 2.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.2 using [Travis CI](https://travis-ci.org/jgarber623/svgeez).
12
12
 
13
- Before making changes to svgeez, you'll want to install Ruby 2.4.5. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm). Once you've installed Ruby 2.4.5 using your method of choice, install the project's gems by running:
13
+ Before making changes to svgeez, you'll want to install Ruby 2.4.6. It's recommended that you use a Ruby version managment tool like [rbenv](https://github.com/rbenv/rbenv), [chruby](https://github.com/postmodern/chruby), or [rvm](https://github.com/rvm/rvm). Once you've installed Ruby 2.4.6 using your method of choice, install the project's gems by running:
14
14
 
15
15
  ```sh
16
16
  bundle install
data/README.md CHANGED
@@ -21,7 +21,7 @@ _For more on why SVG sprites are the bee's knees as far as icon systems go, give
21
21
 
22
22
  ## Getting Started
23
23
 
24
- Before installing and using svgeez, you'll want to have Ruby 2.4 (or newer) installed on your computer. There are plenty of ways to go about this, but my preference is [rbenv](https://github.com/sstephenson/rbenv). svgeez is developed using Ruby 2.4.5 and is additionally tested against Ruby 2.5.3 and 2.6.0 using [Travis CI](https://travis-ci.org/jgarber623/svgeez).
24
+ Before installing and using svgeez, you'll want to have Ruby 2.4 (or newer) installed on your computer. There are plenty of ways to go about this, but my preference is [rbenv](https://github.com/sstephenson/rbenv). svgeez is developed using Ruby 2.4.6 and is additionally tested against Ruby 2.5.5 and 2.6.2 using [Travis CI](https://travis-ci.org/jgarber623/svgeez).
25
25
 
26
26
  ## Installation
27
27
 
@@ -30,19 +30,19 @@ If you're using [Bundler](http://bundler.io), add svgeez to your project's Gemfi
30
30
  ```rb
31
31
  source 'https://rubygems.org'
32
32
 
33
- gem 'svgeez', '~> 2.0'
33
+ gem 'svgeez', '~> 3.0'
34
34
  ```
35
35
 
36
36
  …and hop over to your command prompt and run…
37
37
 
38
38
  ```sh
39
- $ bundle install
39
+ bundle install
40
40
  ```
41
41
 
42
42
  You may also install svgeez directly by issuing the following command:
43
43
 
44
44
  ```sh
45
- $ gem install svgeez
45
+ gem install svgeez
46
46
  ```
47
47
 
48
48
  ## Usage
@@ -56,18 +56,18 @@ You can manually generate an SVG sprite from a folder of SVGs with the `build` c
56
56
  A basic example:
57
57
 
58
58
  ```sh
59
- $ svgeez build --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg
59
+ svgeez build --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg
60
60
  ```
61
61
 
62
62
  The above example will combine all SVG files in `~/Sites/sixtwothree.org/images/icons` into a single SVG sprite file (`icons.svg`) in `~/Sites/sixtwothree.org/images`.
63
63
 
64
64
  #### Options and Defaults
65
65
 
66
- |Option|Description|
67
- |---|---|
68
- |`-s`<br>`--source`|Path to the folder of source SVGs (defaults to `./_svgeez`).|
69
- |`-d`<br>`--destination`|Path to the destination file or folder (defaults to `./svgeez.svg`)|
70
- |`--with-svgo`|Optimize SVG sprite file with [SVGO](https://github.com/svg/svgo)|
66
+ | Option | Description |
67
+ |:----------------------|:------------------------------------------------------------------|
68
+ | `-s`, `--source` | Path to folder of source SVGs (defaults to `./_svgeez`). |
69
+ | `-d`, `--destination` | Path to destination file or folder (defaults to `./svgeez.svg`) |
70
+ | `--with-svgo` | Optimize SVG sprite file with [SVGO](https://github.com/svg/svgo) |
71
71
 
72
72
  ### The `watch` command
73
73
 
@@ -76,7 +76,7 @@ The `watch` command takes the same arguments as the `build` command but uses the
76
76
  Tweaking the example from above:
77
77
 
78
78
  ```sh
79
- $ svgeez watch --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg
79
+ svgeez watch --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg
80
80
  ```
81
81
 
82
82
  svgeez will remaing running, watching for new, removed, or updated SVG files in the provided source folder. As SVG files are added, deleted, or modified in the source folder, svgeez will pump out updated SVG sprite files to the destination folder.
@@ -92,7 +92,7 @@ The first section of Jayden Seric's post, [How to optimize SVG](http://jaydenser
92
92
  If you have the excellent [SVGO](https://github.com/svg/svgo) utility installed on your system (and the `svgo` command is available in your `PATH`), you can use the `--with-svgo` option and optimize the generated sprite file.
93
93
 
94
94
  ```sh
95
- $ svgeez build --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg --with-svgo
95
+ svgeez build --source ~/Sites/sixtwothree.org/images/icons --destination ~/Sites/sixtwothree.org/images/icons.svg --with-svgo
96
96
  ```
97
97
 
98
98
  Depending on the number of individual SVG files in the source folder, using the `--with-svgo` option can add considerable time to SVG sprite generation.
data/Rakefile CHANGED
@@ -1,6 +1,18 @@
1
1
  require 'bundler/gem_tasks'
2
+
3
+ require 'reek/rake/task'
2
4
  require 'rspec/core/rake_task'
5
+ require 'rubocop/rake_task'
6
+
7
+ Reek::Rake::Task.new do |task|
8
+ task.fail_on_error = false
9
+ task.source_files = FileList['**/*.rb'].exclude('vendor/**/*.rb')
10
+ end
3
11
 
4
12
  RSpec::Core::RakeTask.new
5
13
 
6
- task default: :spec
14
+ RuboCop::RakeTask.new do |task|
15
+ task.fail_on_error = false
16
+ end
17
+
18
+ task default: [:rubocop, :reek, :spec]
@@ -1,22 +1,24 @@
1
1
  require 'fileutils'
2
- require 'listen'
3
2
  require 'logger'
4
- require 'mercenary'
5
3
  require 'mkmf'
6
4
  require 'securerandom'
7
5
 
6
+ require 'listen'
7
+ require 'mercenary'
8
+
8
9
  require 'svgeez/version'
9
10
 
10
11
  require 'svgeez/command'
11
12
  require 'svgeez/commands/build'
12
13
  require 'svgeez/commands/watch'
13
14
 
15
+ require 'svgeez/elements/svg_element'
16
+ require 'svgeez/elements/symbol_element'
17
+
14
18
  require 'svgeez/builder'
15
19
  require 'svgeez/destination'
16
20
  require 'svgeez/optimizer'
17
21
  require 'svgeez/source'
18
- require 'svgeez/svg_element'
19
- require 'svgeez/symbol_element'
20
22
 
21
23
  module Svgeez
22
24
  def self.logger
@@ -1,6 +1,7 @@
1
1
  module Svgeez
2
2
  class Builder
3
3
  SOURCE_IS_DESTINATION_MESSAGE = "Setting `source` and `destination` to the same path isn't allowed!".freeze
4
+ SOURCE_DOES_NOT_EXIST = 'Provided `source` folder does not exist.'.freeze
4
5
  NO_SVGS_IN_SOURCE_MESSAGE = 'No SVGs were found in `source` folder.'.freeze
5
6
 
6
7
  attr_reader :source, :destination
@@ -9,36 +10,59 @@ module Svgeez
9
10
  @source = Source.new(options)
10
11
  @destination = Destination.new(options)
11
12
  @svgo = options.fetch('svgo', false)
13
+
14
+ raise SOURCE_IS_DESTINATION_MESSAGE if source_is_destination?
15
+ raise SOURCE_DOES_NOT_EXIST unless source_exists?
16
+ rescue RuntimeError => exception
17
+ logger.error exception.message
18
+ exit
12
19
  end
13
20
 
14
21
  # rubocop:disable Metrics/AbcSize
15
22
  def build
16
- return Svgeez.logger.error(SOURCE_IS_DESTINATION_MESSAGE) if source_is_destination?
17
- return Svgeez.logger.warn(NO_SVGS_IN_SOURCE_MESSAGE) if source_is_empty?
23
+ raise NO_SVGS_IN_SOURCE_MESSAGE if source_is_empty?
18
24
 
19
- Svgeez.logger.info "Generating sprite at `#{destination.file_path}` from #{source.file_paths.length} SVG#{'s' if source.file_paths.length > 1}..."
25
+ logger.info "Generating sprite at `#{destination_file_path}` from #{source_files_count} SVG#{'s' if source_files_count > 1}..."
20
26
 
21
27
  # Make destination folder
22
28
  FileUtils.mkdir_p(destination.folder_path)
23
29
 
24
30
  # Write the file
25
- File.open(destination.file_path, 'w') do |f|
26
- f.write destination_file_contents
31
+ File.open(destination_file_path, 'w') do |file|
32
+ file.write destination_file_contents
27
33
  end
28
34
 
29
- Svgeez.logger.info "Successfully generated sprite at `#{destination.file_path}`."
35
+ logger.info "Successfully generated sprite at `#{destination_file_path}`."
36
+ rescue RuntimeError => exception
37
+ logger.warn exception.message
30
38
  end
31
39
  # rubocop:enable Metrics/AbcSize
32
40
 
33
41
  private
34
42
 
35
43
  def destination_file_contents
36
- file_contents = SvgElement.new(source, destination).build
44
+ file_contents = Elements::SvgElement.new(source, destination).build
37
45
  file_contents = Optimizer.new.optimize(file_contents) if @svgo
38
46
 
39
47
  file_contents.insert(4, ' style="display: none;"')
40
48
  end
41
49
 
50
+ def destination_file_path
51
+ @destination_file_path ||= destination.file_path
52
+ end
53
+
54
+ def logger
55
+ @logger ||= Svgeez.logger
56
+ end
57
+
58
+ def source_exists?
59
+ File.directory?(source.folder_path)
60
+ end
61
+
62
+ def source_files_count
63
+ source.file_paths.length
64
+ end
65
+
42
66
  def source_is_destination?
43
67
  /\A#{source.folder_path}/ =~ destination.folder_path
44
68
  end
@@ -1,18 +1,38 @@
1
1
  module Svgeez
2
2
  class Command
3
- def self.subclasses
4
- @subclasses ||= []
5
- end
3
+ class << self
4
+ def subclasses
5
+ @subclasses ||= []
6
+ end
6
7
 
7
- def self.inherited(base)
8
- subclasses << base
9
- super(base)
10
- end
8
+ def inherited(base)
9
+ subclasses << base
10
+ super(base)
11
+ end
12
+
13
+ def init_with_program(program)
14
+ program.command(name.split('::').last.downcase.to_sym) do |command|
15
+ command.description command_description
16
+ command.syntax command_syntax
17
+
18
+ add_actions(command)
19
+ add_options(command)
20
+ end
21
+ end
22
+
23
+ private
24
+
25
+ def add_actions(command)
26
+ command.action do |_, options|
27
+ command_action(options)
28
+ end
29
+ end
11
30
 
12
- def self.add_build_options(command)
13
- command.option 'source', '-s', '--source [FOLDER]', 'Source folder (defaults to ./_svgeez)'
14
- command.option 'destination', '-d', '--destination [OUTPUT]', 'Destination file or folder (defaults to ./svgeez.svg)'
15
- command.option 'svgo', '--with-svgo', 'Optimize source SVGs with SVGO before sprite generation (non-destructive)'
31
+ def add_options(command)
32
+ command.option 'source', '-s', '--source [FOLDER]', 'Source folder (defaults to ./_svgeez)'
33
+ command.option 'destination', '-d', '--destination [OUTPUT]', 'Destination file or folder (defaults to ./svgeez.svg)'
34
+ command.option 'svgo', '--with-svgo', 'Optimize source SVGs with SVGO before sprite generation (non-destructive)'
35
+ end
16
36
  end
17
37
  end
18
38
  end
@@ -1,21 +1,24 @@
1
1
  module Svgeez
2
2
  module Commands
3
3
  class Build < Command
4
- def self.init_with_program(program)
5
- program.command(:build) do |command|
6
- command.description 'Builds an SVG sprite from a folder of SVG icons'
7
- command.syntax 'build [options]'
4
+ class << self
5
+ def process(options)
6
+ Svgeez::Builder.new(options).build
7
+ end
8
8
 
9
- add_build_options(command)
9
+ private
10
10
 
11
- command.action do |_, options|
12
- Build.process(options)
13
- end
11
+ def command_action(options)
12
+ Build.process(options)
14
13
  end
15
- end
16
14
 
17
- def self.process(options)
18
- Svgeez::Builder.new(options).build
15
+ def command_description
16
+ 'Builds an SVG sprite from a folder of SVG icons'
17
+ end
18
+
19
+ def command_syntax
20
+ 'build [options]'
21
+ end
19
22
  end
20
23
  end
21
24
  end
@@ -1,33 +1,33 @@
1
1
  module Svgeez
2
2
  module Commands
3
3
  class Watch < Command
4
- def self.init_with_program(program)
5
- program.command(:watch) do |command|
6
- command.description 'Watches a folder of SVG icons for changes'
7
- command.syntax 'watch [options]'
4
+ class << self
5
+ def process(options)
6
+ builder = Svgeez::Builder.new(options)
7
+ folder_path = builder.source.folder_path
8
8
 
9
- add_build_options(command)
9
+ Svgeez.logger.info "Watching `#{folder_path}` for changes... Press ctrl-c to stop."
10
10
 
11
- command.action do |_, options|
12
- Build.process(options)
13
- Watch.process(options)
14
- end
11
+ Listen.to(folder_path, only: /\.svg\z/) { builder.build }.start
12
+ sleep
13
+ rescue Interrupt
14
+ Svgeez.logger.info 'Quitting svgeez...'
15
15
  end
16
- end
17
16
 
18
- def self.process(options)
19
- builder = Svgeez::Builder.new(options)
17
+ private
20
18
 
21
- listener = Listen.to(builder.source.folder_path, only: /\.svg\z/) do
22
- builder.build
19
+ def command_action(options)
20
+ Build.process(options)
21
+ Watch.process(options)
23
22
  end
24
23
 
25
- Svgeez.logger.info "Watching `#{builder.source.folder_path}` for changes... Press ctrl-c to stop."
24
+ def command_description
25
+ 'Watches a folder of SVG icons for changes'
26
+ end
26
27
 
27
- listener.start
28
- sleep
29
- rescue Interrupt
30
- Svgeez.logger.info 'Quitting svgeez...'
28
+ def command_syntax
29
+ 'watch [options]'
30
+ end
31
31
  end
32
32
  end
33
33
  end
@@ -0,0 +1,22 @@
1
+ module Svgeez
2
+ module Elements
3
+ class SvgElement
4
+ def initialize(source, destination)
5
+ @source = source
6
+ @destination = destination
7
+ end
8
+
9
+ def build
10
+ %(<svg id="#{@destination.file_id}" xmlns="http://www.w3.org/2000/svg">#{symbol_elements.join}</svg>)
11
+ end
12
+
13
+ private
14
+
15
+ def symbol_elements
16
+ @source.file_paths.map do |file_path|
17
+ SymbolElement.new(file_path, @destination.file_id).build
18
+ end
19
+ end
20
+ end
21
+ end
22
+ end
@@ -0,0 +1,35 @@
1
+ module Svgeez
2
+ module Elements
3
+ class SymbolElement
4
+ def initialize(file_path, file_id)
5
+ @file_path = file_path
6
+ @file_id = file_id
7
+ end
8
+
9
+ def build
10
+ IO.read(@file_path).match(%r{^<svg\s*?(?<attributes>.*?)>(?<content>.*?)</svg>}m) do |matches|
11
+ %(<symbol #{element_attributes(matches[:attributes]).sort.join(' ')}>#{element_contents(matches[:content])}</symbol>)
12
+ end
13
+ end
14
+
15
+ private
16
+
17
+ def element_attributes(attributes)
18
+ attrs = attributes.scan(/(?:viewBox|xmlns:.+?)=".*?"/m)
19
+
20
+ attrs << %(id="#{@file_id}-#{File.basename(@file_path, '.svg').gsub(/['"\s]/, '-')}")
21
+ end
22
+
23
+ def element_contents(content)
24
+ content.scan(/\sid="(.+?)"/).flatten.each do |value|
25
+ uuid = SecureRandom.uuid
26
+
27
+ content.gsub!(/\s(id|xlink:href)="(#?#{value})"/m, %( \\1="\\2-#{uuid}"))
28
+ content.gsub!(/\s(clip-path|fill|filter|marker-end|marker-mid|marker-start|mask|stroke)="url\((##{value})\)"/m, %( \\1="url(\\2-#{uuid})"))
29
+ end
30
+
31
+ content
32
+ end
33
+ end
34
+ end
35
+ end
@@ -1,14 +1,16 @@
1
1
  module Svgeez
2
2
  class Optimizer
3
- SVGO_MINIMUM_VERSION = '1.1.1'.freeze
3
+ SVGO_MINIMUM_VERSION = '1.3.0'.freeze
4
4
  SVGO_MINIMUM_VERSION_MESSAGE = "svgeez relies on SVGO #{SVGO_MINIMUM_VERSION} or newer. Continuing with standard sprite generation...".freeze
5
5
  SVGO_NOT_INSTALLED = 'Unable to find `svgo` in your PATH. Continuing with standard sprite generation...'.freeze
6
6
 
7
7
  def optimize(file_contents)
8
- return Svgeez.logger.warn(SVGO_NOT_INSTALLED) unless installed?
9
- return Svgeez.logger.warn(SVGO_MINIMUM_VERSION_MESSAGE) unless supported?
8
+ raise SVGO_NOT_INSTALLED unless installed?
9
+ raise SVGO_MINIMUM_VERSION_MESSAGE unless supported?
10
10
 
11
- `cat <<EOF | svgo --disable=cleanupIDs --disable=removeViewBox -i - -o -\n#{file_contents}\nEOF`
11
+ `cat <<EOF | svgo --disable=cleanupIDs --disable=removeHiddenElems --disable=removeViewBox -i - -o -\n#{file_contents}\nEOF`
12
+ rescue RuntimeError => exception
13
+ logger.warn exception.message
12
14
  end
13
15
 
14
16
  private
@@ -17,6 +19,10 @@ module Svgeez
17
19
  @installed ||= find_executable0('svgo')
18
20
  end
19
21
 
22
+ def logger
23
+ @logger ||= Svgeez.logger
24
+ end
25
+
20
26
  def supported?
21
27
  @supported ||= Gem::Version.new(`svgo -v`.strip) >= Gem::Version.new(SVGO_MINIMUM_VERSION)
22
28
  end
@@ -1,3 +1,3 @@
1
1
  module Svgeez
2
- VERSION = '2.0.1'.freeze
2
+ VERSION = '3.0.0'.freeze
3
3
  end
@@ -22,13 +22,19 @@ Gem::Specification.new do |spec|
22
22
  spec.executables = ['svgeez']
23
23
  spec.require_paths = ['lib']
24
24
 
25
- spec.add_development_dependency 'bundler', '~> 1.17'
25
+ spec.metadata = {
26
+ 'bug_tracker_uri' => "#{spec.homepage}/issues",
27
+ 'changelog_uri' => "#{spec.homepage}/blob/v#{spec.version}/CHANGELOG.md"
28
+ }
29
+
26
30
  spec.add_development_dependency 'rake', '~> 12.3'
31
+ spec.add_development_dependency 'reek', '~> 5.4'
27
32
  spec.add_development_dependency 'rspec', '~> 3.8'
28
- spec.add_development_dependency 'rubocop', '~> 0.62.0'
29
- spec.add_development_dependency 'rubocop-rspec', '~> 1.31'
30
- spec.add_development_dependency 'simplecov', '~> 0.16.1'
31
- spec.add_development_dependency 'simplecov-console', '~> 0.4.2'
33
+ spec.add_development_dependency 'rubocop', '~> 0.74.0'
34
+ spec.add_development_dependency 'rubocop-performance', '~> 1.4'
35
+ spec.add_development_dependency 'rubocop-rspec', '~> 1.34'
36
+ spec.add_development_dependency 'simplecov', '~> 0.17.0'
37
+ spec.add_development_dependency 'simplecov-console', '~> 0.5.0'
32
38
 
33
39
  spec.add_runtime_dependency 'listen', '~> 3.1'
34
40
  spec.add_runtime_dependency 'mercenary', '~> 0.3.6'
metadata CHANGED
@@ -1,43 +1,43 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: svgeez
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.1
4
+ version: 3.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Garber
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2019-01-03 00:00:00.000000000 Z
11
+ date: 2019-08-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
- name: bundler
14
+ name: rake
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
17
  - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.17'
19
+ version: '12.3'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
24
  - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.17'
26
+ version: '12.3'
27
27
  - !ruby/object:Gem::Dependency
28
- name: rake
28
+ name: reek
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
31
  - - "~>"
32
32
  - !ruby/object:Gem::Version
33
- version: '12.3'
33
+ version: '5.4'
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: '12.3'
40
+ version: '5.4'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
@@ -58,56 +58,70 @@ dependencies:
58
58
  requirements:
59
59
  - - "~>"
60
60
  - !ruby/object:Gem::Version
61
- version: 0.62.0
61
+ version: 0.74.0
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: 0.74.0
69
+ - !ruby/object:Gem::Dependency
70
+ name: rubocop-performance
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '1.4'
62
76
  type: :development
63
77
  prerelease: false
64
78
  version_requirements: !ruby/object:Gem::Requirement
65
79
  requirements:
66
80
  - - "~>"
67
81
  - !ruby/object:Gem::Version
68
- version: 0.62.0
82
+ version: '1.4'
69
83
  - !ruby/object:Gem::Dependency
70
84
  name: rubocop-rspec
71
85
  requirement: !ruby/object:Gem::Requirement
72
86
  requirements:
73
87
  - - "~>"
74
88
  - !ruby/object:Gem::Version
75
- version: '1.31'
89
+ version: '1.34'
76
90
  type: :development
77
91
  prerelease: false
78
92
  version_requirements: !ruby/object:Gem::Requirement
79
93
  requirements:
80
94
  - - "~>"
81
95
  - !ruby/object:Gem::Version
82
- version: '1.31'
96
+ version: '1.34'
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: simplecov
85
99
  requirement: !ruby/object:Gem::Requirement
86
100
  requirements:
87
101
  - - "~>"
88
102
  - !ruby/object:Gem::Version
89
- version: 0.16.1
103
+ version: 0.17.0
90
104
  type: :development
91
105
  prerelease: false
92
106
  version_requirements: !ruby/object:Gem::Requirement
93
107
  requirements:
94
108
  - - "~>"
95
109
  - !ruby/object:Gem::Version
96
- version: 0.16.1
110
+ version: 0.17.0
97
111
  - !ruby/object:Gem::Dependency
98
112
  name: simplecov-console
99
113
  requirement: !ruby/object:Gem::Requirement
100
114
  requirements:
101
115
  - - "~>"
102
116
  - !ruby/object:Gem::Version
103
- version: 0.4.2
117
+ version: 0.5.0
104
118
  type: :development
105
119
  prerelease: false
106
120
  version_requirements: !ruby/object:Gem::Requirement
107
121
  requirements:
108
122
  - - "~>"
109
123
  - !ruby/object:Gem::Version
110
- version: 0.4.2
124
+ version: 0.5.0
111
125
  - !ruby/object:Gem::Dependency
112
126
  name: listen
113
127
  requirement: !ruby/object:Gem::Requirement
@@ -146,6 +160,7 @@ extra_rdoc_files: []
146
160
  files:
147
161
  - ".editorconfig"
148
162
  - ".gitignore"
163
+ - ".reek.yml"
149
164
  - ".rspec"
150
165
  - ".rubocop"
151
166
  - ".rubocop.yml"
@@ -166,16 +181,18 @@ files:
166
181
  - lib/svgeez/commands/build.rb
167
182
  - lib/svgeez/commands/watch.rb
168
183
  - lib/svgeez/destination.rb
184
+ - lib/svgeez/elements/svg_element.rb
185
+ - lib/svgeez/elements/symbol_element.rb
169
186
  - lib/svgeez/optimizer.rb
170
187
  - lib/svgeez/source.rb
171
- - lib/svgeez/svg_element.rb
172
- - lib/svgeez/symbol_element.rb
173
188
  - lib/svgeez/version.rb
174
189
  - svgeez.gemspec
175
190
  homepage: https://github.com/jgarber623/svgeez
176
191
  licenses:
177
192
  - MIT
178
- metadata: {}
193
+ metadata:
194
+ bug_tracker_uri: https://github.com/jgarber623/svgeez/issues
195
+ changelog_uri: https://github.com/jgarber623/svgeez/blob/v3.0.0/CHANGELOG.md
179
196
  post_install_message:
180
197
  rdoc_options: []
181
198
  require_paths:
@@ -194,7 +211,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
194
211
  - !ruby/object:Gem::Version
195
212
  version: '0'
196
213
  requirements: []
197
- rubygems_version: 3.0.2
214
+ rubygems_version: 3.0.3
198
215
  signing_key:
199
216
  specification_version: 4
200
217
  summary: Automatically generate an SVG sprite from a folder of SVG icons.
@@ -1,20 +0,0 @@
1
- module Svgeez
2
- class SvgElement
3
- def initialize(source, destination)
4
- @source = source
5
- @destination = destination
6
- end
7
-
8
- def build
9
- %(<svg id="#{@destination.file_id}" xmlns="http://www.w3.org/2000/svg">#{symbol_elements.join}</svg>)
10
- end
11
-
12
- private
13
-
14
- def symbol_elements
15
- @source.file_paths.map do |file_path|
16
- SymbolElement.new(file_path, @destination.file_id).build
17
- end
18
- end
19
- end
20
- end
@@ -1,33 +0,0 @@
1
- module Svgeez
2
- class SymbolElement
3
- def initialize(file_path, file_id)
4
- @file_path = file_path
5
- @file_id = file_id
6
- end
7
-
8
- def build
9
- IO.read(@file_path).match(%r{^<svg\s*?(?<attributes>.*?)>(?<content>.*?)</svg>}m) do |matches|
10
- %(<symbol #{element_attributes(matches[:attributes]).sort.join(' ')}>#{element_contents(matches[:content])}</symbol>)
11
- end
12
- end
13
-
14
- private
15
-
16
- def element_attributes(attributes)
17
- attrs = attributes.scan(/(?:viewBox|xmlns:.+?)=".*?"/m)
18
-
19
- attrs << %(id="#{@file_id}-#{File.basename(@file_path, '.svg').gsub(/['"\s]/, '-')}")
20
- end
21
-
22
- def element_contents(content)
23
- content.scan(/\sid="(.+?)"/).flatten.each do |value|
24
- uuid = SecureRandom.uuid
25
-
26
- content.gsub!(/\s(id|xlink:href)="(#?#{value})"/m, %( \\1="\\2-#{uuid}"))
27
- content.gsub!(/\s(clip-path|fill|filter|marker-end|marker-mid|marker-start|mask|stroke)="url\((##{value})\)"/m, %( \\1="url(\\2-#{uuid})"))
28
- end
29
-
30
- content
31
- end
32
- end
33
- end