Class: Docs::Sass::EntriesFilter

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

Constant Summary collapse

TYPES =
['CSS Extensions', 'SassScript', '@-Rules and Directives',
'Output Styles']
SKIP_NAMES =
['Interactive Shell', 'Data Types', 'Operations',
'Division and /', 'Keyword Arguments']
REPLACE_NAMES =
{
  '%foo'               => '%placeholder selector',
  '&'                  => '& parent selector',
  '$'                  => '$ variables',
  '`'                  => '#{} interpolation',
  'The !optional Flag' => '!optional'
}

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, #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


22
23
24
# File 'lib/docs/filters/sass/entries.rb', line 22

def additional_entries
  root_page? ? root_entries : function_entries
end

#function_entriesObject


67
68
69
70
71
72
73
74
75
76
77
# File 'lib/docs/filters/sass/entries.rb', line 67

def function_entries
  css('.method_details > .signature').inject [] do |entries, node|
    name = node.at_css('strong').content.strip

    unless name == entries.last.try(:first)
      entries << [name, node['id'], 'Functions']
    end

    entries
  end
end

#include_default_entry?Boolean

Returns:

  • (Boolean)

18
19
20
# File 'lib/docs/filters/sass/entries.rb', line 18

def include_default_entry?
  false
end

#root_entriesObject


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
58
59
60
61
62
63
64
65
# File 'lib/docs/filters/sass/entries.rb', line 26

def root_entries
  entries = []
  type = ''

  css('> [id]').each do |node|
    if node.name == 'h2'
      type = node.content.strip

      if type == 'Function Directives'
        entries << ['@function', node['id'], '@-Rules and Directives']
      end

      if type.include? 'Directives'
        type = '@-Rules and Directives'
      elsif type == 'Output Style'
        type = 'Output Styles'
      end

      next
    end

    next unless TYPES.include?(type)

    name = node.content.strip
    name.remove! %r{\A.+?: }

    next if SKIP_NAMES.include?(name)

    name = REPLACE_NAMES[name] if REPLACE_NAMES[name]
    name.gsub!(/ [A-Z]/) { |str| str.downcase! }

    if type == '@-Rules and Directives'
      next unless name =~ /\[email protected][\w\-]+\z/ || name == '!optional'
    end

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

  entries
end