Class: Docs::Ember::CleanHtmlFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/docs/filters/ember/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/ember/clean_html.rb', line 4

def call
  root_page? ? root : other
  doc
end

#otherObject


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/docs/filters/ember/clean_html.rb', line 31

def other
  css(*%w(hr .edit-page #api-options .toc-anchor .inherited .protected .private .deprecated)).remove

  # Remove tabs and "Index"
  css('.tabs').each do |node|
    panes = node.css '#methods', '#events', '#properties'
    panes.remove_attr 'style'
    node.before(panes).remove
  end

  css('.method', '.property', '.event').remove_attr('id')

  css('h3[data-id]').each do |node|
    # Put id attributes on headings
    node.name = 'h2'
    node['id'] = node['data-id']
    node.remove_attribute 'data-id'
    node.content = node.content

    # Move headings, span.args, etc. into a div.title
    div = Nokogiri::XML::Node.new 'div', doc
    div['class'] = 'title'
    node.before(div).parent = div
    div.add_child(div.next_element) while div.next_element.name == 'span'
  end

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

#rootObject


9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/docs/filters/ember/clean_html.rb', line 9

def root
  css('#back-to-top').remove

  # Remove "Projects" and "Tag" links
  css('.level-1:nth-child(1)', '.level-1:nth-child(2)').remove

  # Turn section links (e.g. Modules) into headings
  css('.level-1 > a').each do |node|
    node.name = 'h2'
    node.remove_attribute 'href'
  end

  # Remove root-level list
  css('.level-1').each do |node|
    node.before(node.elements).remove
  end

  css('ol').each do |node|
    node.name = 'ul'
  end
end