Skip to content
This repository has been archived by the owner on Feb 29, 2024. It is now read-only.

Commit

Permalink
Address RuboCop Style/StringLiterals warnings (#109)
Browse files Browse the repository at this point in the history
* RuboCop: Style/StringLiterals

* RuboCop: Style/StringLiterals

* RuboCop: Style/StringLiterals

* Remove inlined rubocop:disable comment
  • Loading branch information
jgarber623 authored Dec 13, 2023
1 parent dd04662 commit c24a658
Show file tree
Hide file tree
Showing 29 changed files with 225 additions and 233 deletions.
14 changes: 5 additions & 9 deletions .simplecov
Original file line number Diff line number Diff line change
@@ -1,19 +1,15 @@
# frozen_string_literal: true

require 'simplecov_json_formatter'
require 'simplecov-console'
formatters = SimpleCov::Formatter.from_env(ENV)

formatters = [
SimpleCov::Formatter::HTMLFormatter,
SimpleCov::Formatter::JSONFormatter
]

# rubocop:disable Style/IfUnlessModifier
if RSpec.configuration.files_to_run.length > 1
require "simplecov-console"

formatters << SimpleCov::Formatter::Console
end
# rubocop:enable Style/IfUnlessModifier

SimpleCov.start do
enable_coverage :branch

formatter SimpleCov::Formatter::MultiFormatter.new(formatters)
end
24 changes: 12 additions & 12 deletions Gemfile
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
# frozen_string_literal: true

source 'https://rubygems.org'
source "https://rubygems.org"

# Specify your gem's dependencies in svgeez.gemspec
# Specify your gem"s dependencies in svgeez.gemspec
gemspec

gem 'debug'
gem 'rake'
gem 'rspec'
gem 'rubocop'
gem 'rubocop-packaging'
gem 'rubocop-performance'
gem 'rubocop-rake'
gem 'rubocop-rspec'
gem 'simplecov'
gem 'simplecov-console'
gem "debug"
gem "rake"
gem "rspec"
gem "rubocop"
gem "rubocop-packaging"
gem "rubocop-performance"
gem "rubocop-rake"
gem "rubocop-rspec"
gem "simplecov"
gem "simplecov-console"
5 changes: 2 additions & 3 deletions Rakefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
# frozen_string_literal: true

require 'bundler/gem_tasks'

require 'rspec/core/rake_task'
require "bundler/gem_tasks"
require "rspec/core/rake_task"

RSpec::Core::RakeTask.new

Expand Down
8 changes: 4 additions & 4 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
#!/usr/bin/env ruby
# frozen_string_literal: true

require 'bundler/setup'
require 'svgeez'
require "bundler/setup"
require "svgeez"

# You can add fixtures and/or initialization code here to make experimenting
# with your gem easier. You can also use a different console, if you like.

# (If you use this, don't forget to add pry to your Gemfile!)
# require 'pry'
# require "pry"
# Pry.start

require 'irb'
require "irb"
IRB.start(__FILE__)
11 changes: 5 additions & 6 deletions exe/svgeez
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
#!/usr/bin/env ruby

# frozen_string_literal: true

$LOAD_PATH.unshift File.join(File.dirname(__FILE__), '..', 'lib')
$LOAD_PATH.unshift File.join(File.dirname(__FILE__), "..", "lib")

require 'mercenary'
require 'svgeez'
require "mercenary"
require "svgeez"

Mercenary.program(:svgeez) do |program|
program.version Svgeez::VERSION
program.description 'Generate an SVG sprite from a folder of SVG icons.'
program.syntax 'svgeez <subcommand> [options]'
program.description "Generate an SVG sprite from a folder of SVG icons."
program.syntax "svgeez <subcommand> [options]"

Svgeez::Command.subclasses.each do |command|
command.init_with_program(program)
Expand Down
32 changes: 16 additions & 16 deletions lib/svgeez.rb
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
# frozen_string_literal: true

require 'fileutils'
require 'logger'
require 'mkmf'
require 'securerandom'
require "fileutils"
require "logger"
require "mkmf"
require "securerandom"

require 'listen'
require 'mercenary'
require "listen"
require "mercenary"

require_relative 'svgeez/version'
require_relative "svgeez/version"

require_relative 'svgeez/command'
require_relative 'svgeez/commands/build'
require_relative 'svgeez/commands/watch'
require_relative "svgeez/command"
require_relative "svgeez/commands/build"
require_relative "svgeez/commands/watch"

require_relative 'svgeez/elements/svg_element'
require_relative 'svgeez/elements/symbol_element'
require_relative "svgeez/elements/svg_element"
require_relative "svgeez/elements/symbol_element"

require_relative 'svgeez/builder'
require_relative 'svgeez/destination'
require_relative 'svgeez/optimizer'
require_relative 'svgeez/source'
require_relative "svgeez/builder"
require_relative "svgeez/destination"
require_relative "svgeez/optimizer"
require_relative "svgeez/source"

module Svgeez
def self.logger
Expand Down
12 changes: 5 additions & 7 deletions lib/svgeez/builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,16 @@
module Svgeez
class Builder
SOURCE_IS_DESTINATION_MESSAGE = "Setting `source` and `destination` to the same path isn't allowed!"
SOURCE_DOES_NOT_EXIST = 'Provided `source` folder does not exist.'
NO_SVGS_IN_SOURCE_MESSAGE = 'No SVGs were found in `source` folder.'
SOURCE_DOES_NOT_EXIST = "Provided `source` folder does not exist."
NO_SVGS_IN_SOURCE_MESSAGE = "No SVGs were found in `source` folder."

attr_reader :source, :destination, :prefix

def initialize(options = {})
@source = Source.new(options)
@destination = Destination.new(options)
@svgo = options.fetch('svgo', false)
@prefix = options.fetch('prefix', @destination.file_id)
@svgo = options.fetch("svgo", false)
@prefix = options.fetch("prefix", @destination.file_id)

raise SOURCE_IS_DESTINATION_MESSAGE if source_is_destination?
raise SOURCE_DOES_NOT_EXIST unless source_exists?
Expand All @@ -21,7 +21,6 @@ def initialize(options = {})
exit
end

# rubocop:disable Metrics/AbcSize
def build
raise NO_SVGS_IN_SOURCE_MESSAGE if source_is_empty?

Expand All @@ -37,15 +36,14 @@ def build
rescue RuntimeError => e
logger.warn e.message
end
# rubocop:enable Metrics/AbcSize

private

def destination_file_contents
file_contents = Elements::SvgElement.new(source, destination, prefix).build
file_contents = Optimizer.new.optimize(file_contents) if @svgo

file_contents.insert(4, ' style="display: none;"')
file_contents.insert(4, %( style="display: none;"))
end

def destination_file_path
Expand Down
10 changes: 5 additions & 5 deletions lib/svgeez/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def inherited(base)
end

def init_with_program(program)
program.command(name.split('::').last.downcase.to_sym) do |command|
program.command(name.split("::").last.downcase.to_sym) do |command|
command.description command_description
command.syntax command_syntax

Expand All @@ -31,10 +31,10 @@ def add_actions(command)
end

def add_options(command)
command.option 'source', '-s', '--source [FOLDER]', 'Source folder (defaults to ./_svgeez)'
command.option 'destination', '-d', '--destination [OUTPUT]', 'Destination file or folder (defaults to ./svgeez.svg)'
command.option 'prefix', '-p', '--prefix [PREFIX]', 'Custom Prefix for icon id (defaults to destination filename)'
command.option 'svgo', '--with-svgo', 'Optimize source SVGs with SVGO before sprite generation (non-destructive)'
command.option "source", "-s", "--source [FOLDER]", "Source folder (defaults to ./_svgeez)"
command.option "destination", "-d", "--destination [OUTPUT]", "Destination file or folder (defaults to ./svgeez.svg)"
command.option "prefix", "-p", "--prefix [PREFIX]", "Custom Prefix for icon id (defaults to destination filename)"
command.option "svgo", "--with-svgo", "Optimize source SVGs with SVGO before sprite generation (non-destructive)"
end
end
end
Expand Down
4 changes: 2 additions & 2 deletions lib/svgeez/commands/build.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,11 @@ def command_action(options)
end

def command_description
'Builds an SVG sprite from a folder of SVG icons'
"Builds an SVG sprite from a folder of SVG icons"
end

def command_syntax
'build [options]'
"build [options]"
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions lib/svgeez/commands/watch.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ def process(options)
Listen.to(folder_path, only: /\.svg\z/) { builder.build }.start
sleep
rescue Interrupt
Svgeez.logger.info 'Quitting svgeez...'
Svgeez.logger.info "Quitting svgeez..."
end

private
Expand All @@ -24,11 +24,11 @@ def command_action(options)
end

def command_description
'Watches a folder of SVG icons for changes'
"Watches a folder of SVG icons for changes"
end

def command_syntax
'watch [options]'
"watch [options]"
end
end
end
Expand Down
10 changes: 5 additions & 5 deletions lib/svgeez/destination.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@

module Svgeez
class Destination
DEFAULT_DESTINATION_FILE_NAME = 'svgeez.svg'
DEFAULT_DESTINATION_FILE_NAME = "svgeez.svg"

def initialize(options = {})
@destination = File.expand_path(options.fetch('destination', "./#{DEFAULT_DESTINATION_FILE_NAME}"))
@destination = File.expand_path(options.fetch("destination", "./#{DEFAULT_DESTINATION_FILE_NAME}"))
end

def file_id
@file_id ||= File.basename(file_name, '.svg').tr(' ', '-')
@file_id ||= File.basename(file_name, ".svg").tr(" ", "-")
end

def file_name
@file_name ||=
if @destination.end_with?('.svg')
if @destination.end_with?(".svg")
File.split(@destination)[1]
else
DEFAULT_DESTINATION_FILE_NAME
Expand All @@ -27,7 +27,7 @@ def file_path

def folder_path
@folder_path ||=
if @destination.end_with?('.svg')
if @destination.end_with?(".svg")
File.split(@destination)[0]
else
@destination
Expand Down
6 changes: 3 additions & 3 deletions lib/svgeez/elements/symbol_element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ def initialize(file_path, file_id)

def build
File.read(@file_path).match(%r{^<svg\s*?(?<attributes>.*?)>(?<content>.*?)</svg>}m) do |matches|
%(<symbol #{element_attributes(matches[:attributes]).sort.join(' ')}>#{element_contents(matches[:content])}</symbol>)
%(<symbol #{element_attributes(matches[:attributes]).sort.join(" ")}>#{element_contents(matches[:content])}</symbol>)
end
end

Expand All @@ -19,8 +19,8 @@ def build
def element_attributes(attributes)
attrs = attributes.scan(/(?:viewBox|xmlns:.+?)=".*?"/m)
id_prefix = @file_id
id_suffix = File.basename(@file_path, '.svg').gsub(/['"\s]/, '-')
id_attribute = [id_prefix, id_suffix].reject(&:empty?).join('-')
id_suffix = File.basename(@file_path, ".svg").gsub(/['"\s]/, "-")
id_attribute = [id_prefix, id_suffix].reject(&:empty?).join("-")

attrs << %(id="#{id_attribute}")
end
Expand Down
6 changes: 3 additions & 3 deletions lib/svgeez/optimizer.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

module Svgeez
class Optimizer
SVGO_VERSION = '1.3.2'
SVGO_VERSION = "1.3.2"
SVGO_VERSION_MESSAGE = "svgeez relies on SVGO #{SVGO_VERSION}. Continuing with standard sprite generation..."
SVGO_NOT_INSTALLED = 'Unable to find `svgo` in your PATH. Continuing with standard sprite generation...'
SVGO_NOT_INSTALLED = "Unable to find `svgo` in your PATH. Continuing with standard sprite generation..."

def optimize(file_contents)
raise SVGO_NOT_INSTALLED unless installed?
Expand All @@ -18,7 +18,7 @@ def optimize(file_contents)
private

def installed?
@installed ||= find_executable0('svgo')
@installed ||= find_executable0("svgo")
end

def logger
Expand Down
6 changes: 3 additions & 3 deletions lib/svgeez/source.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,12 @@

module Svgeez
class Source
DEFAULT_INPUT_FOLDER_PATH = './_svgeez'
DEFAULT_INPUT_FOLDER_PATH = "./_svgeez"

attr_reader :folder_path

def initialize(options = {})
@folder_path = File.expand_path(options.fetch('source', DEFAULT_INPUT_FOLDER_PATH))
@folder_path = File.expand_path(options.fetch("source", DEFAULT_INPUT_FOLDER_PATH))
end

def file_paths
Expand All @@ -17,7 +17,7 @@ def file_paths
private

def file_paths_pattern
@file_paths_pattern ||= File.join(folder_path, '*.svg')
@file_paths_pattern ||= File.join(folder_path, "*.svg")
end
end
end
2 changes: 1 addition & 1 deletion lib/svgeez/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module Svgeez
VERSION = '4.1.0'
VERSION = "4.1.0"
end
Loading

0 comments on commit c24a658

Please sign in to comment.