Skip to content

Commit

Permalink
explain myself
Browse files Browse the repository at this point in the history
  • Loading branch information
gjtorikian committed Nov 23, 2020
1 parent 6636e5e commit 15bf0da
Showing 1 changed file with 3 additions and 5 deletions.
8 changes: 3 additions & 5 deletions lib/html-proofer/element.rb
Original file line number Diff line number Diff line change
Expand Up @@ -181,18 +181,16 @@ def file_path
path_dot_ext = path + @check.options[:extension] if @check.options[:assume_extension]

base = if absolute_path?(path) # path relative to root
if File.directory?(@check.src)
@check.options[:root_dir] || @check.src
else
@check.options[:root_dir] || File.dirname(@check.src)
end
# either overwrite with root_dir; or, if source is directory, use that; or, just get the current file's dirname
@check.options[:root_dir] || (File.directory?(@check.src) ? @check.src : File.dirname(@check.src))
elsif File.exist?(File.expand_path(path, @check.src)) || File.exist?(File.expand_path(path_dot_ext, @check.src)) # relative links, path is a file
File.dirname(@check.path)
elsif File.exist?(File.join(File.dirname(@check.path), path)) || File.exist?(File.join(File.dirname(@check.path), path_dot_ext)) # rubocop:disable Lint/DuplicateBranch; relative links in nested dir, path is a file
File.dirname(@check.path)
else # relative link, path is a directory
@check.path
end

file = File.join(base, path)

if @check.options[:assume_extension] && File.file?("#{file}#{@check.options[:extension]}")
Expand Down

0 comments on commit 15bf0da

Please sign in to comment.