Class: Docs::Html::EntriesFilter

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

Constant Summary collapse

HTML5 =
%w(content element video)
OBSOLETE =
%w(frame frameset hgroup noframes)
ADDITIONAL_ENTRIES =
{ 'Element/Heading_Elements' => (1..6).map { |n| ["h#{n}"] } }

Constants inherited from Filter

Filter::SCHEME_RGX

Instance Method Summary collapse

Methods inherited from EntriesFilter

#build_entries, #build_entry, #call, #default_entry, #entries, #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


33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
# File 'lib/docs/filters/html/entries.rb', line 33

def additional_entries
  return ADDITIONAL_ENTRIES[slug] if ADDITIONAL_ENTRIES.key?(slug)

  if slug == 'Attributes'
    css('.standard-table td:first-child').map do |node|
      name = node.content.strip
      id = node.parent['id'] = name.parameterize
      [name, id, 'Attributes']
    end
  elsif slug == 'Link_types'
    css('.standard-table td:first-child > code').map do |node|
      name = node.content.strip
      id = node.parent.parent['id'] = name.parameterize
      name.prepend 'rel: '
      [name, id, 'Attributes']
    end
  else
    []
  end
end

#get_nameObject


8
9
10
11
12
# File 'lib/docs/filters/html/entries.rb', line 8

def get_name
  name = super
  name.remove!('Element.').try(:downcase!)
  name
end

#get_typeObject


14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/docs/filters/html/entries.rb', line 14

def get_type
  slug = self.slug.remove('Element/')

  if at_css('.obsoleteHeader', '.deprecatedHeader', '.nonStandardHeader') || OBSOLETE.include?(slug)
    'Obsolete'
  else
    spec = css('.standard-table').last.try(:content)
    if (spec && html5_spec?(spec)) || HTML5.include?(slug)
      'HTML5'
    else
      'Standard'
    end
  end
end

#html5_spec?(spec) ⇒ Boolean

Returns:

  • (Boolean)

54
55
56
# File 'lib/docs/filters/html/entries.rb', line 54

def html5_spec?(spec)
  (spec =~ /HTML\s?5/ || spec.include?('WHATWG HTML Living Standard')) && spec !~ /HTML\s?4/
end

#include_default_entry?Boolean

Returns:

  • (Boolean)

29
30
31
# File 'lib/docs/filters/html/entries.rb', line 29

def include_default_entry?
  !%w(Attributes Link_types Element/Heading_Elements).include?(slug)
end