History

Add Go documentation

Thibaut committed 12 years ago

Commit f657dfd1 parent 50f1ca914 files · +122 −-3Browse files

Unified · Split

14 files
  1. assets/images/icons.png +0 −0
  2. assets/images/icons@2x.png +0 −0
  3. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  4. assets/javascripts/templates/pages/news_tmpl.coffee +4 −1
  5. assets/javascripts/views/pages/go.coffee +6 −0
  6. assets/stylesheets/application.css.scss +1 −0
  7. assets/stylesheets/global/_icons.scss +1 −0
  8. assets/stylesheets/pages/_go.scss +7 −0
  9. lib/docs/filters/go/clean_html.rb +46 −0
  10. lib/docs/filters/go/entries.rb +33 −0
  11. lib/docs/scrapers/go.rb +22 −0
  12. public/icons/docs/go/16.png +0 −0
  13. public/icons/docs/go/16@2x.png +0 −0
  14. public/icons/docs/go/SOURCE +1 −0
assets/images/icons.png+0−0

Binary file not shown.

assets/images/icons@2x.png+0−0

Binary file not shown.

assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -115,6 +115,11 @@ credits = [ · 114 unmodified lines
115115 '2005-2014 Linus Torvalds and others',
116116 'GPLv2',
117117 'https://raw.github.com/git/git/master/COPYING'
118+ ], [
119+ 'Go',
120+ 'Google, Inc.',
121+ 'CC BY',
122+ 'http://creativecommons.org/licenses/by/3.0/'
118123 ], [
119124 'HTTP',
120125 '1999 The Internet Society',
assets/javascripts/templates/pages/news_tmpl.coffee+4−1
@@ -24,7 +24,10 @@ newsItem = (date, news) -> · 23 unmodified lines
2424 result
2525
2626 app.news = [
27− [ 1396137600000, # March 30, 2014
27+ [ 1396742400000, # April 6, 2014
28+ """ New <a href="/go/">Go</a> documentation """,
29+ ], [
30+ 1396137600000, # March 30, 2014
2831 """ New <a href="/cpp/">C++</a> documentation """,
2932 ], [
3033 1394928000000, # March 16, 2014
assets/javascripts/views/pages/go.coffee+6−0
@@ -0,0 +1,6 @@
1+#= require views/pages/base
2+
3+class app.views.GoPage extends app.views.BasePage
4+ afterRender: ->
5+ @highlightCode @findAll('pre'), 'go'
6+ return
assets/stylesheets/application.css.scss+1−0
@@ -33,6 +33,7 @@ · 32 unmodified lines
3333 'pages/coffeescript',
3434 'pages/d3',
3535 'pages/ember',
36+ 'pages/go',
3637 'pages/jquery',
3738 'pages/knockout',
3839 'pages/git',
assets/stylesheets/global/_icons.scss+1−0
@@ -52,3 +52,4 @@ · 51 unmodified lines
5252 %icon-path { background-position: -3rem -7rem; }
5353 ._icon-yii:before { background-position: -4rem -7rem; }
5454 ._icon-cpp:before { background-position: 0 -8rem; }
55+._icon-go:before { background-position: -1rem -8rem; }
assets/stylesheets/pages/_go.scss+7−0
@@ -0,0 +1,7 @@
1+._go {
2+ padding-left: 1rem;
3+
4+ h1, h2, #short-nav, table.dir { margin-left: -1rem; }
5+ h2 { @extend %block-heading; }
6+ h3 { @extend %block-label, %label-blue; }
7+}
lib/docs/filters/go/clean_html.rb+46−0
@@ -0,0 +1,46 @@
1+module Docs
2+ class Go
3+ class CleanHtmlFilter < Filter
4+ def call
5+ if root_page?
6+ at_css('h1').content = 'Go Programming Language'
7+
8+ # Remove empty columns
9+ css('tr:first-child + tr', 'th:first-child + th', 'td:first-child + td').remove
10+
11+ # Remove links to unscraped pages
12+ css('td + td:empty').each do |node|
13+ node.previous_element.content = node.previous_element.content
14+ end
15+ end
16+
17+ css('#plusone', '#nav', '.pkgGopher', '#footer', '.collapsed').remove
18+
19+ # Remove triangle character
20+ css('h2', '.exampleHeading').each do |node|
21+ node.content = node.content.sub("\u25BE", '')
22+ node.name = 'h2'
23+ end
24+
25+ # Turn <dl> into <ul>
26+ css('#short-nav', '#manual-nav').each do |node|
27+ node.children = node.css('dd').tap { |nodes| nodes.each { |dd| dd.name = 'li' } }
28+ node.name = 'ul'
29+ end
30+
31+ # Remove code highlighting
32+ css('pre').each do |node|
33+ node.content = node.content
34+ end
35+
36+ # Fix example markup
37+ css('.play').each do |node|
38+ node.children = node.at_css('.code').children
39+ node.name = 'pre'
40+ end
41+
42+ doc
43+ end
44+ end
45+ end
46+end
lib/docs/filters/go/entries.rb+33−0
@@ -0,0 +1,33 @@
1+module Docs
2+ class Go
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ name = at_css('h1').content
6+ name.sub! 'Package ', ''
7+ name
8+ end
9+
10+ def get_type
11+ subpath[/\A[^\/]+/]
12+ end
13+
14+ def additional_entries
15+ css('#manual-nav a').each_with_object [] do |node, entries|
16+ case node.content
17+ when /type\ (\w+)/
18+ name = $1
19+ when /func\ (?:\(.+\)\ )?(\w+)\(/
20+ name = "#{$1}()"
21+ name.prepend "#{$1}." if node['href'] =~ /#(\w+)\.#{$1}/
22+ end
23+
24+ entries << ["#{name} (#{self.name})", node['href'][1..-1]] if name
25+ end
26+ end
27+
28+ def include_default_entry?
29+ !at_css('h1 + table.dir')
30+ end
31+ end
32+ end
33+end
lib/docs/scrapers/go.rb+22−0
@@ -0,0 +1,22 @@
1+module Docs
2+ class Go < UrlScraper
3+ self.type = 'go'
4+ self.version = '1.2.1'
5+ self.base_url = 'http://golang.org/pkg/'
6+
7+ html_filters.push 'go/clean_html', 'go/entries'
8+
9+ options[:container] = '#page .container'
10+
11+ options[:attribution] = <<-HTML
12+ &copy; Google, Inc.<br>
13+ Licensed under the Creative Commons Attribution License 3.0.
14+ HTML
15+
16+ private
17+
18+ def parse(html) # Hook here because Nokogori removes whitespace from textareas
19+ super html.gsub %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>'
20+ end
21+ end
22+end
public/icons/docs/go/16.png+0−0

Binary file not shown.

public/icons/docs/go/16@2x.png+0−0

Binary file not shown.

public/icons/docs/go/SOURCE+1−0
@@ -0,0 +1 @@
1+http://golang.org/doc/gopher/