Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-docs.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-02-01 17:32:25 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2019-02-01 17:32:25 +0300
commit95f460ca8f4e50dd537990b77c1c0f5fb37b4dc7 (patch)
treead2b460911d213564471efbc5e358a221d6f14fd /lib/checks
parentbcbf96ec41b3c09844cdb9a0f66351781d469611 (diff)
Make anchors validator a little more readable
Diffstat (limited to 'lib/checks')
-rw-r--r--lib/checks/anchors.rb29
1 files changed, 18 insertions, 11 deletions
diff --git a/lib/checks/anchors.rb b/lib/checks/anchors.rb
index 94d52c9c..f8f64de6 100644
--- a/lib/checks/anchors.rb
+++ b/lib/checks/anchors.rb
@@ -20,14 +20,20 @@ module Gitlab
File.exists?(@file)
end
- def path
+ def directory
File.dirname(@file)
end
+ def content
+ raise unless exists?
+
+ @content ||= File.read(@file)
+ end
+
def document
- raise ArgumentError unless exists?
+ raise if content.to_s.empty?
- @doc ||= Nokogiri::HTML(File.read(@file))
+ @doc ||= Nokogiri::HTML(content)
end
def links
@@ -58,10 +64,6 @@ module Gitlab
@page = page
end
- def path
- @href.to_s.partition('#').first
- end
-
def to_anchor?
@href.to_s.include?('#')
end
@@ -82,13 +84,17 @@ module Gitlab
@href.to_s.length > 0 && !@href.include?(':')
end
- def destination_path
+ def path
+ @href.to_s.partition('#').first
+ end
+
+ def absolute_path
raise unless internal?
if @href.start_with?('/')
Gitlab::Nanoc.output_dir + path
else
- ::File.expand_path(path, @page.path)
+ ::File.expand_path(path, @page.directory)
end
end
@@ -96,7 +102,7 @@ module Gitlab
if internal_anchor?
@page
else
- Gitlab::Page.build(destination_path)
+ Gitlab::Page.build(absolute_path)
end
end
@@ -133,12 +139,13 @@ Nanoc::Check.define(:internal_anchors) do
- source file `#{link.source_file}`
ERROR
elsif link.destination_anchor_not_found?
+ (require 'pry'; binding.pry) if link.anchor_name == '1-stop-server'
add_issue <<~ERROR
Broken anchor detected!
- anchor `##{link.anchor_name}`
- link `#{link.href}`
- source file `#{link.source_file}`
- - destination `#{link.destination_file}
+ - destination `#{link.destination_file}`
ERROR
end
end