Class: Docs::Angular::CleanHtmlFilter

Inherits:
Filter
  • Object
show all
Defined in:
lib/docs/filters/angular/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
8
9
10
11
12
13
14
15
# File 'lib/docs/filters/angular/clean_html.rb', line 4

def call
  root_page? ? root : other

  # Remove ng-* attributes
  css('*').each do |node|
    node.attributes.each_key do |attribute|
      node.remove_attribute(attribute) if attribute.start_with? 'ng-'
    end
  end

  doc
end

#otherObject


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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
# File 'lib/docs/filters/angular/clean_html.rb', line 32

def other
  css('#example', '.example', '#description_source', '#description_demo', '[id$="example"]', 'hr').remove

  css('header').each do |node|
    node.before(node.children).remove
  end

  at_css('h1').add_child(css('.view-source', '.improve-docs'))

  # Remove root-level <div>
  while div = at_css('h1 + div')
    div.before(div.children)
    div.remove
  end

  css('.api-profile-header-structure > li').each do |node|
    node.inner_html = node.inner_html.remove('- ')
  end

  css('h1').each_with_index do |node, i|
    next if i == 0
    node.name = 'h2'
  end

  # Remove examples
  css('.runnable-example').each do |node|
    node.parent.remove
  end

  # Remove dead links (e.g. ngRepeat)
  css('a.type-hint').each do |node|
    node.name = 'code'
    node.remove_attribute 'href'
  end

  css('pre > code').each do |node|
    node.parent['class'] = node['class']
    node.before(node.children).remove
  end

  # Remove some <code> elements
  css('h1 > code', 'h2 > code', 'h3 > code', 'h4 > code', 'h6 > code').each do |node|
    node.before(node.content).remove
  end

  css('ul.methods', 'ul.properties', 'ul.events').add_class('defs').each do |node|
    node.css('> li > h3').each do |h3|
      next if h3.content.present?
      h3.content = h3.next_element.content
      h3.next_element.remove
    end
  end
end

#rootObject


17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/docs/filters/angular/clean_html.rb', line 17

def root
  css('.nav-index-group').each do |node|
    if heading = node.at_css('.nav-index-group-heading')
      heading.name = 'h2'
    end
    node.parent.before(node.children)
  end

  css('.nav-index-section').each do |node|
    node.content = node.content
  end

  css('.toc-close', '.naked-list').remove
end