History

Improve Haskell scraper

Thibaut committed 11 years ago

Commit e096acc1 parent ef7dbbe1 file · +15 −3Browse files

Unified · Split

lib/docs/filters/haskell/entries.rb+15−3
@@ -38,18 +38,30 @@ module Docs · 37 unmodified lines
3838 end
3939 end
4040
41+ ADD_SUB_ENTRIES_KEYWORDS = %w(class module newtype)
42+
4143 def additional_entries
4244 return [] if IGNORE_ENTRIES_PATHS.include?(subpath.split('/').last)
4345
4446 css('#synopsis > ul > li').each_with_object [] do |node, entries|
4547 link = node.at_css('a')
46− next unless link['href'].start_with?('#')
4748 name = node.content.strip
4849 name.remove! %r{\A(?:module|data|newtype|class|type family m|type)\s+}
4950 name.sub! %r{\A\((.+?)\)}, '\1'
5051 name.sub!(/ (?:\:\: (\w+))?.*\z/) { |_| $1 ? " (#{$1})" : '' }
51− next if name == self.name
52− entries << [name, link['href'].remove('#')]
52+
53+ if ADD_SUB_ENTRIES_KEYWORDS.include?(node.at_css('.keyword').try(:content))
54+ node.css('.subs > li').each do |sub_node|
55+ sub_link = sub_node.at_css('a')
56+ next unless sub_link['href'].start_with?('#')
57+ sub_name = sub_node.content.strip
58+ sub_name.remove! %r{\s.*}
59+ sub_name.prepend "#{name} "
60+ entries << [sub_name, sub_link['href'].remove('#')]
61+ end
62+ end
63+
64+ entries << [name, link['href'].remove('#')] if link['href'].start_with?('#') && name != self.name
5365 end
5466 end
5567