-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Expand file tree
/
Copy pathtitle.rb
More file actions
31 lines (27 loc) · 648 Bytes
/
title.rb
File metadata and controls
31 lines (27 loc) · 648 Bytes
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
# frozen_string_literal: true
module Docs
class TitleFilter < Filter
def call
title = self.title
doc.child.before node(title) if title
doc
end
def title
if !context[:root_title].nil? && root_page?
context[:root_title]
elsif !context[:title].nil?
context[:title].is_a?(Proc) ? context[:title].call(self) : context[:title]
else
default_title
end
end
def default_title
result[:entries].try(:first).try(:name)
end
def node(content)
node = Nokogiri::XML::Node.new 'h1', doc.document
node.content = content
node
end
end
end