History

Update and improve Go documentation (1.7.4)

Closes #538. Closes #540. Closes #541.

Thibaut Courouble committed 9 years ago

Commit cd8188b1 parent 06cf1184 files · +38 −12Browse files

Unified · Split

4 files
  1. assets/stylesheets/pages/_go.scss +5 −0
  2. lib/docs/filters/go/clean_html.rb +11 −4
  3. lib/docs/filters/go/entries.rb +20 −7
  4. lib/docs/scrapers/go.rb +2 −1
assets/stylesheets/pages/_go.scss+5−0
@@ -2,4 +2,9 @@ · 1 unmodified line
22 @extend %simple;
33
44 #short-nav, table.dir { margin-left: -1rem; }
5+
6+ a.source {
7+ float: right;
8+ font-size: .9em;
9+ }
510 }
lib/docs/filters/go/clean_html.rb+11−4
@@ -20,9 +20,16 @@ module Docs · 19 unmodified lines
2020 node.before(node.children).remove
2121 end
2222
23+ css('h2 a', 'h3 a').each do |node|
24+ if node['href'].include?('/src/')
25+ node.after %(<a href="#{node['href']}" class="source">Source</a>)
26+ node.before(node.children).remove
27+ end
28+ end
29+
2330 # Remove triangle character
2431 css('h2', '.exampleHeading').each do |node|
25− node.content = node.content.remove("\u25BE")
32+ node.inner_html = node.inner_html.remove("\u25BE")
2633 node.name = 'h4' unless node.name == 'h2'
2734 end
2835
@@ -44,9 +51,9 @@ module Docs · 15 unmodified lines
4451 node.content = node.content
4552 end
4653
47− css('td[style]', 'ul[style]').each do |node|
48− node.remove_attribute('style')
49− end
54+ css('td[style]', 'ul[style]').remove_attr('style')
55+ css('.toggleButton[title]').remove_attr('title')
56+ css('.toggleButton').remove_attr('class')
5057
5158 doc
5259 end
lib/docs/filters/go/entries.rb+20−7
@@ -2,23 +2,36 @@ module Docs · 1 unmodified line
22 class Go
33 class EntriesFilter < Docs::EntriesFilter
44 def get_name
5− name = at_css('h1').content
6− name.remove! 'Package '
7− name
5+ code = at_css('code')
6+ if code && name = code.content[/import "([\w\/]+)"/, 1]
7+ name
8+ else
9+ name = at_css('h1').content
10+ name.remove! 'Package '
11+ name
12+ end
813 end
914
1015 def get_type
11− subpath[/\A[^\/]+/]
16+ package = subpath[/\A[^\/]+/]
17+ if package.in?(%w(math net))
18+ name.split('/')[0..1].join('/')
19+ else
20+ package
21+ end
1222 end
1323
1424 def additional_entries
25+ return [] if root_page?
26+ package = self.name.split('/').last
1527 css('#manual-nav a').each_with_object [] do |node, entries|
1628 case node.content
1729 when /type\ (\w+)/
18− name = "#{$1} (#{self.name})"
30+ name = "#{package}.#{$1}"
1931 when /func\ (?:\(.+\)\ )?(\w+)\(/
20− name = "#{$1}() (#{self.name})"
32+ name = "#{$1}()"
2133 name.prepend "#{$1}." if node['href'] =~ /#(\w+)\.#{$1}/
34+ name.prepend "#{package}."
2235 when 'Constants'
2336 name = "#{self.name} constants"
2437 when 'Variables'
@@ -30,7 +43,7 @@ module Docs · 5 unmodified lines
3043 end
3144
3245 def include_default_entry?
33− !at_css('h1 + table.dir')
46+ !at_css('h1 + .pkg-dir')
3447 end
3548 end
3649 end
lib/docs/scrapers/go.rb+2−1
@@ -1,7 +1,7 @@
11 module Docs
22 class Go < UrlScraper
33 self.type = 'go'
4− self.release = '1.7.3'
4+ self.release = '1.7.4'
55 self.base_url = 'https://golang.org/pkg/'
66 self.links = {
77 home: 'https://golang.org/',
@@ -12,6 +12,7 @@ module Docs · 4 unmodified lines
1212
1313 options[:trailing_slash] = true
1414 options[:container] = '#page .container'
15+ options[:skip] = %w(runtime/msan/)
1516
1617 options[:attribution] = <<-HTML
1718 &copy; Google, Inc.<br>