mirror of https://github.com/freeCodeCamp/devdocs
commit
bf8c8fe53d
@ -1,89 +1,65 @@
|
||||
module Docs
|
||||
class Sass
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
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'
|
||||
}
|
||||
|
||||
def get_name
|
||||
'Functions'
|
||||
at_css('#main-content > h1').content
|
||||
end
|
||||
|
||||
def get_type
|
||||
'Functions'
|
||||
end
|
||||
|
||||
def additional_entries
|
||||
root_page? ? root_entries : function_entries
|
||||
case slug
|
||||
when /syntax/
|
||||
'Syntax'
|
||||
when /style/
|
||||
'Style rules'
|
||||
when /at/
|
||||
'At-Rules'
|
||||
when /values/
|
||||
'Values'
|
||||
when /operators/
|
||||
'Operators'
|
||||
when /cli/
|
||||
'Command line'
|
||||
when /modules/
|
||||
'Modules'
|
||||
else
|
||||
'Misc'
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
def root_entries
|
||||
def additional_entries
|
||||
entries = []
|
||||
type = ''
|
||||
|
||||
css('*').each do |node|
|
||||
if node.name == 'h2'
|
||||
type = node.content.strip
|
||||
type.remove! %r{\s#.*}
|
||||
node['id'] = type.parameterize
|
||||
|
||||
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
|
||||
elsif node.name == 'h3' || node.name == 'h4'
|
||||
next unless TYPES.include?(type)
|
||||
signatureElement = css('.signature')
|
||||
|
||||
name = node.content.strip
|
||||
name.remove! %r{\A.+?: }
|
||||
name.remove! %r{\s#.*}
|
||||
if signatureElement
|
||||
|
||||
node['id'] = name.parameterize
|
||||
signatureElement.each do |node|
|
||||
|
||||
next if SKIP_NAMES.include?(name)
|
||||
entry_name = node.content
|
||||
|
||||
name = REPLACE_NAMES[name] if REPLACE_NAMES[name]
|
||||
name.gsub!(/ [A-Z]/) { |str| str.downcase! }
|
||||
if entry_name.match(/\(/)
|
||||
entry_name = entry_name.scan(/.+\(/)[0].chop
|
||||
end
|
||||
|
||||
if type == '@-Rules and Directives'
|
||||
next unless name =~ /\A@[\w\-]+\z/ || name == '!optional'
|
||||
if entry_name.include?('$pi')
|
||||
entries << [entry_name, 'pi', 'Variable']
|
||||
elsif entry_name.include?('$e')
|
||||
entries << [entry_name, 'e', 'Variable']
|
||||
else
|
||||
entries << [entry_name, entry_name, 'Functions']
|
||||
end
|
||||
|
||||
entries << [name, node['id'], type]
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
entries
|
||||
end
|
||||
|
||||
def function_entries
|
||||
css('.method_details > .signature').inject [] do |entries, node|
|
||||
name = node.content.strip.remove(%r{\(.*})
|
||||
|
||||
unless name == entries.last.try(:first)
|
||||
entries << [name, node['id'], 'Functions']
|
||||
end
|
||||
|
||||
entries
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
||||
|
Loading…
Reference in new issue