Class: Docs::Laravel::CleanHtmlFilter

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

#apiObject


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

def api
  @doc = doc.at_css('#page-content')

  css('.location').remove

  # Replace .header with <h1>
  css('.page-header > h1').each do |node|
    node.content = 'Laravel' if root_page?
    node.parent.before(node).remove
  end

  css('.container-fluid').each do |node|
    node.name = 'table'
    node.css('.row').each { |n| n.name = 'tr' }
    node.css('div[class^="col"]').each { |n| n.name = 'td' }
  end

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

  # Remove <abbr>
  css('a > abbr').each do |node|
    node.parent['title'] = node['title']
    node.before(node.children).remove
  end

  # Clean up headings
  css('h1 > a', '.content', 'h3 > code', 'h3 strong', 'abbr').each do |node|
    node.before(node.children).remove
  end

  # Remove empty <td>
  css('td').each do |node|
    node.remove if node.content =~ /\A\s+\z/
  end
end

#callObject


4
5
6
7
8
9
10
11
12
# File 'lib/docs/filters/laravel/clean_html.rb', line 4

def call
  if subpath.start_with?('/api')
    api
  else
    other
  end

  doc
end

#otherObject


52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/docs/filters/laravel/clean_html.rb', line 52

def other
  @doc = at_css('article')

  # Clean up headings
  css('h2 > a').each do |node|
    node.before(node.children).remove
  end

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