Class: Docs::Sinon::EntriesFilter

Inherits:
EntriesFilter show all
Defined in:
lib/docs/filters/sinon/entries.rb

Constant Summary

Constants inherited from Filter

Filter::SCHEME_RGX

Instance Method Summary collapse

Methods inherited from EntriesFilter

#build_entries, #build_entry, #call, #default_entry, #entries, #get_name, #get_type, #include_default_entry?, #name, #path, #type

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

#additional_entriesObject


4
5
6
7
8
9
10
11
12
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
# File 'lib/docs/filters/sinon/entries.rb', line 4

def additional_entries
  entries = []
  type = config = nil

  css('*').each do |node|
    if node.name == 'h2'
      config = false
      type = node.content.strip
      type.remove! 'Test '
      type.remove! 'Sinon.JS '
      type = type[0].upcase + type.from(1)

      id = type.parameterize
      node['id'] = id

      entries << [type, id, 'Sections']
    elsif node.name == 'h3' && node.content.include?('sinon.config')
      config = true
    elsif node.name == 'dl'
      node.css('dt > code').each do |code|
        name = code.content.strip
        name.sub! %r{\(.*\);?}, '()'
        name.sub! %r{\Aserver.(\w+)\s=.*\z}, 'server.\1'
        name.remove! '`'
        name.remove! %r{\A.+?\=\s+}
        name.remove! %r{\A\w+?\s}
        name.prepend 'sinon.config.' if config

        next if name =~ /\s/
        next if entries.any? { |entry| entry[0].casecmp(name) == 0 }

        id = name.parameterize
        code.parent['id'] = id

        entries << [name, id, type]
      end
    end
  end

  entries
end