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
38 end38 end
39 end39 end
40 40
41 ADD_SUB_ENTRIES_KEYWORDS = %w(class module newtype)
42
41 def additional_entries43 def additional_entries
42 return [] if IGNORE_ENTRIES_PATHS.include?(subpath.split('/').last)44 return [] if IGNORE_ENTRIES_PATHS.include?(subpath.split('/').last)
43 45
44 css('#synopsis > ul > li').each_with_object [] do |node, entries|46 css('#synopsis > ul > li').each_with_object [] do |node, entries|
45 link = node.at_css('a')47 link = node.at_css('a')
46 next unless link['href'].start_with?('#')
47 name = node.content.strip48 name = node.content.strip
48 name.remove! %r{\A(?:module|data|newtype|class|type family m|type)\s+}49 name.remove! %r{\A(?:module|data|newtype|class|type family m|type)\s+}
49 name.sub! %r{\A\((.+?)\)}, '\1'50 name.sub! %r{\A\((.+?)\)}, '\1'
50 name.sub!(/ (?:\:\: (\w+))?.*\z/) { |_| $1 ? " (#{$1})" : '' }51 name.sub!(/ (?:\:\: (\w+))?.*\z/) { |_| $1 ? " (#{$1})" : '' }
51 next if name == self.name52
52 entries << [name, link['href'].remove('#')]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
53 end65 end
54 end66 end
55 67