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
115 '2005-2014 Linus Torvalds and others',115 '2005-2014 Linus Torvalds and others',
116 'GPLv2',116 'GPLv2',
117 'https://raw.github.com/git/git/master/COPYING'117 '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/'
118 ], [123 ], [
119 'HTTP',124 'HTTP',
120 '1999 The Internet Society',125 '1999 The Internet Society',
assets/javascripts/templates/pages/news_tmpl.coffee+4−1
@@ -24,7 +24,10 @@ newsItem = (date, news) -> · 23 unmodified lines
24 result24 result
25 25
26app.news = [26app.news = [
27 [ 1396137600000, # March 30, 201427 [ 1396742400000, # April 6, 2014
28 """ New <a href="/go/">Go</a> documentation """,
29 ], [
30 1396137600000, # March 30, 2014
28 """ New <a href="/cpp/">C++</a> documentation """,31 """ New <a href="/cpp/">C++</a> documentation """,
29 ], [32 ], [
30 1394928000000, # March 16, 201433 1394928000000, # March 16, 2014
assets/javascripts/views/pages/go.coffee+6−0
@@ -0,0 +1,6 @@
1#= require views/pages/base
2
3class 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
33 'pages/coffeescript',33 'pages/coffeescript',
34 'pages/d3',34 'pages/d3',
35 'pages/ember',35 'pages/ember',
36 'pages/go',
36 'pages/jquery',37 'pages/jquery',
37 'pages/knockout',38 'pages/knockout',
38 'pages/git',39 'pages/git',
assets/stylesheets/global/_icons.scss+1−0
@@ -52,3 +52,4 @@ · 51 unmodified lines
52%icon-path { background-position: -3rem -7rem; }52%icon-path { background-position: -3rem -7rem; }
53._icon-yii:before { background-position: -4rem -7rem; }53._icon-yii:before { background-position: -4rem -7rem; }
54._icon-cpp:before { background-position: 0 -8rem; }54._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 @@
1module 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
46end
lib/docs/filters/go/entries.rb+33−0
@@ -0,0 +1,33 @@
1module 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
33end
lib/docs/scrapers/go.rb+22−0
@@ -0,0 +1,22 @@
1module 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
22end
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 @@
1http://golang.org/doc/gopher/