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

SVGO location #21

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 30 additions & 2 deletions lib/svgeez/sprite_builder.rb
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def build_destination_file_contents
destination_file_contents = "<svg>#{collect_source_files_contents.join}</svg>"

if svgo_use? && svgo_installed?
destination_file_contents = `cat <<EOF | svgo --disable=cleanupIDs -i - -o -\n#{destination_file_contents}\nEOF`
destination_file_contents = `cat <<EOF | #{svgo_executable} --disable=cleanupIDs -i - -o -\n#{destination_file_contents}\nEOF`
end

destination_file_contents.insert(4, %( id="#{destination_file_id}" style="display: none;" version="1.1"))
Expand Down Expand Up @@ -94,7 +94,35 @@ def svgo_use?
end

def svgo_installed?
@svgo_installed ||= find_executable0('svgo')
@svgo_installed ||= svgo_executable
end

def svgo_executable
@svgo_executable ||= find_svgo_executable
end

def find_svgo_executable
specified_executable || local_svgo_executable || global_svgo_executable
end

def specified_executable
svgo_path = specified_svgo_path
find_executable0('svgo', svgo_path) if svgo_path
end

def specified_svgo_path
return unless @options['svgo']
path = File.expand_path(@options['svgo'])
return unless File.directory?(path)
path
end

def local_svgo_executable
find_executable0('svgo', File.expand_path('./node_modules/svgo/bin', Dir.pwd))
end

def global_svgo_executable
find_executable0('svgo')
end
end
end
2 changes: 1 addition & 1 deletion lib/svgeez/version.rb
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module Svgeez
VERSION = '1.0.0'.freeze
VERSION = '1.0.1'.freeze
end