Class: Docs::Rdoc::CleanHtmlFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/docs/filters/rdoc/clean_html.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


4
5
6
7
# File 'lib/docs/filters/rdoc/clean_html.rb', line 4

def call
  root_page? ? root : other
  doc
end

#otherObject


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
# File 'lib/docs/filters/rdoc/clean_html.rb', line 18

def other
  css('hr').remove

  # Remove paragraph/up links
  css('h1 > span', 'h2 > span', 'h3 > span', 'h4 > span', 'h5 > span', 'h6 > span').remove

  # Move id attributes to headings
  css('.method-detail').each do |node|
    next unless heading = node.at_css('.method-heading')
    heading['id'] = node['id']
    node.remove_attribute 'id'
  end

  # Convert "click to toggle source" into a link
  css('.method-click-advice').each do |node|
    node.name = 'a'
    node.content = 'Show source'
  end

  # Add class to differentiate Ruby code from C code
  css('.method-source-code > pre').each do |node|
    node['class'] = node.at_css('.ruby-keyword') ? 'ruby' : 'c'
  end

  # Remove code highlighting
  css('pre').each do |node|
    node.content = node.content
  end
end

#rootObject


9
10
11
12
13
14
15
16
# File 'lib/docs/filters/rdoc/clean_html.rb', line 9

def root
  css('#methods + ul', 'h1', 'h2', 'li > ul').remove

  # Remove skipped items
  css('li > span').each do |node|
    node.parent.remove
  end
end