Class: Docs::Phpunit::CleanHtmlFilter

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

def call
  root_page? ? root : other
  doc
end

#otherObject


13
14
15
16
17
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
47
48
49
50
51
52
53
54
55
56
57
# File 'lib/docs/filters/phpunit/clean_html.rb', line 13

def other
  @doc = doc.at_css('div.appendix, div.chapter')

  css('.example-break', '.table-break').remove

  css('a[id]').each do |node|
    next unless node.content.blank?
    node.parent['id'] = node['id']
    node.remove
  end

  css('.titlepage').each do |node|
    title = node.at_css('h1, .title')
    title.content = title.content.remove(/(Chapter|Appendix)\s+\w+\.\s+/)
    node.before(title).remove
  end

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

  css('[style], [border], [valign]').each do |node|
    node.remove_attribute('style')
    node.remove_attribute('border')
    node.remove_attribute('valign')
  end

  css('.warning h3', '.alert h3').each do |node|
    node.remove if node.content == 'Note'
  end

  css('p > code.literal:first-child:last-child').each do |node|
    next if node.previous_sibling && node.previous_sibling.content.present?
    next if node.next_sibling && node.next_sibling.content.present?
    node.parent.name = 'pre'
    node.parent['class'] = 'programlisting'
    node.parent.content = node.content
  end

  css('pre', '.term').each do |node|
    node.content = node.content
  end

  doc
end

#rootObject


9
10
11
# File 'lib/docs/filters/phpunit/clean_html.rb', line 9

def root
  doc.inner_html = ' '
end