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