blob: 8bd5e9b9830c09a3a4ded235d0ebab58f2b80afa (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
|
module Gitlab
module Docs
class Page
attr_reader :file
attr_accessor :hrefs, :ids
def initialize(file)
@file = file
@hrefs = []
@ids = []
return unless exists?
Nokogiri::HTML::SAX::Parser
.new(Gitlab::Docs::Document.new(self))
.parse(File.read(file))
end
def exists?
File.exists?(@file)
end
def directory
File.dirname(@file)
end
def links
@links ||= @hrefs.map do |link|
Gitlab::Docs::Link.new(link, self)
end
end
def has_anchor?(name)
@ids.include?(name)
end
def self.build(path)
if path.end_with?('.html')
new(path)
else
new(File.join(path, 'index.html'))
end
end
end
end
end
|