Class: Docs::TitleFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/docs/filters/core/title.rb

Constant Summary

Constants inherited from Filter

Filter::SCHEME_RGX

Instance Method Summary collapse

Methods inherited from Filter

#absolute_url_string?, #at_css, #at_xpath, #base_url, #css, #current_url, #fragment_url_string?, #initial_page?, #parse_html, #relative_url_string?, #root_page?, #root_path, #root_url, #slug, #subpath, #subpath_to, #xpath

Instance Method Details

#callObject


3
4
5
6
7
# File 'lib/docs/filters/core/title.rb', line 3

def call
  title = self.title
  doc.child.before node(title) if title
  doc
end

#default_titleObject


19
20
21
# File 'lib/docs/filters/core/title.rb', line 19

def default_title
  result[:entries].try(:first).try(:name)
end

#node(content) ⇒ Object


23
24
25
26
27
# File 'lib/docs/filters/core/title.rb', line 23

def node(content)
  node = Nokogiri::XML::Node.new 'h1', doc
  node.content = content
  node
end

#titleObject


9
10
11
12
13
14
15
16
17
# File 'lib/docs/filters/core/title.rb', line 9

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