class Svgeez::Optimizer

Constants

SVGO_NOT_INSTALLED
SVGO_VERSION
SVGO_VERSION_MESSAGE

Public Instance Methods

optimize(file_contents) click to toggle source
# File lib/svgeez/optimizer.rb, line 7
def optimize(file_contents)
  raise SVGO_NOT_INSTALLED unless installed?
  raise SVGO_VERSION_MESSAGE unless supported?

  `cat <<EOF | svgo --disable=cleanupIDs --disable=removeHiddenElems --disable=removeViewBox -i - -o -\n#{file_contents}\nEOF`
rescue RuntimeError => exception
  logger.warn exception.message
end

Private Instance Methods

installed?() click to toggle source
# File lib/svgeez/optimizer.rb, line 18
def installed?
  @installed ||= find_executable0('svgo')
end
logger() click to toggle source
# File lib/svgeez/optimizer.rb, line 22
def logger
  @logger ||= Svgeez.logger
end
supported?() click to toggle source
# File lib/svgeez/optimizer.rb, line 26
def supported?
  @supported ||= `svgo -v`.strip == SVGO_VERSION
end