History

Merge pull request #1238 from davidcgl/davidc/fix-elixir-scraper

Fix Elixir documentation layout

Simon Legner committed 5 years ago

Commit 556bcd22 parents 6956b9c 3deac473 files · +32 −31Browse files

Showing the changes to lib (3 of 3 files). Show all

Unified · Split

3 files
  1. lib/docs/filters/elixir/clean_html.rb +22 −25
  2. lib/docs/filters/elixir/entries.rb +9 −5
  3. lib/docs/scrapers/elixir.rb +1 −1
lib/docs/filters/elixir/clean_html.rb+22−25
@@ -25,41 +25,38 @@ module Docs · 24 unmodified lines
25 end25 end
26 26
27 def api27 def api
28 css('footer', '.view-source', 'h1 .visible-xs').remove28 css('.hover-link', '.view-source', 'footer').remove
29 29
30 css('section section.docstring h2').each do |node|30 css('.summary').each do |node|
31 node.name = 'h4'31 node.name = 'dl'
32 end32 end
33 33
34 css('h1 .hover-link', '.detail-link').each do |node|34 css('.summary h2').each do |node|
35 node.parent['id'] = node['href'].remove('#')35 node.content = node.inner_text
36 node.remove36 node.parent.before(node)
37 end37 end
38 38
39 css('.details-list').each do |list|39 css('.summary-signature').each do |node|
40 type = list['id'].remove(/s\z/) if list['id']40 node.name = 'dt'
41 list.css('.detail-header').each do |node|
42 node.name = 'h3'
43 node['class'] += " #{type}" if type
44 end
45 end41 end
46 42
47 css('.summary h2').each { |node| node.parent.before(node) }43 css('.summary-synopsis').each do |node|
48 css('.summary').each { |node| node.name = 'dl' }44 node.name = 'dd'
49 css('.summary-signature').each { |node| node.name = 'dt' }
50 css('.summary-synopsis').each { |node| node.name = 'dd' }
51
52 css('section', 'div:not(.type-detail)', 'h2 a').each do |node|
53 node.before(node.children).remove
54 end45 end
55 46
56 css('.detail-header > pre').each do |node|47 css('section.detail').each do |detail|
57 node.parent.after(node)48 id = detail['id']
58 end49 detail.remove_attribute('id')
59 50
60 css('.signature').each do |node|51 detail.css('.detail-header').each do |node|
61 non_text_children = node.xpath('node()[not(self::text())]')52 node.name = 'h3'
62 non_text_children.to_a.reverse.each { |child| node.parent.add_next_sibling(child) }53 node['id'] = id
54 node.content = node.at_css('.signature').inner_text
55 end
56
57 detail.css('.docstring h2').each do |node|
58 node.name = 'h4'
59 end
63 end60 end
64 61
65 css('pre').each do |node|62 css('pre').each do |node|
lib/docs/filters/elixir/entries.rb+9−5
@@ -41,21 +41,25 @@ module Docs · 40 unmodified lines
41 end41 end
42 42
43 def additional_entries43 def additional_entries
44 return [] if type == 'Exceptions' || type == 'Guide'44 return [] if type == 'Exceptions' || type == 'Guide' || root_page?
45 45
46 css('.detail-header .signature').map do |node|46 css('.detail-header').map do |node|
47 id = node.parent['id']47 id = node['id']
48 name = node.content.strip48 name = node.content.strip
49
49 name.remove! %r{\(.*\)}50 name.remove! %r{\(.*\)}
50 name.remove! 'left '51 name.remove! 'left '
51 name.remove! ' right'52 name.remove! ' right'
52 name.sub! 'sigil_', '~'53 name.sub! 'sigil_', '~'
53 54
54 unless node.parent['class'].end_with?('macro') || self.name.start_with?('Kernel')55 if self.name && !self.name.start_with?('Kernel')
55 name.prepend "#{self.name}."56 name.prepend "#{self.name}."
56 end57 end
57 58
58 name << " (#{id.split('/').last})" if id =~ /\/\d+\z/59 if id =~ %r{/\d+\z}
60 arity = id.split('/').last
61 name << " (#{arity})"
62 end
59 63
60 [name, id]64 [name, id]
61 end65 end
lib/docs/scrapers/elixir.rb+1−1
@@ -34,7 +34,7 @@ module Docs · 33 unmodified lines
34 end34 end
35 35
36 version '1.9' do36 version '1.9' do
37 self.release = '1.9.1'37 self.release = '1.9.4'
38 self.base_urls = [38 self.base_urls = [
39 "https://hexdocs.pm/elixir/#{release}/",39 "https://hexdocs.pm/elixir/#{release}/",
40 "https://hexdocs.pm/eex/#{release}/",40 "https://hexdocs.pm/eex/#{release}/",