Przeglądaj źródła

Add Go documentation

Thibaut 11 lat temu
rodzic
commit
f657dfddf6

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -115,6 +115,11 @@ credits = [
     '2005-2014 Linus Torvalds and others',
     'GPLv2',
     'https://raw.github.com/git/git/master/COPYING'
+  ], [
+    'Go',
+    'Google, Inc.',
+    'CC BY',
+    'http://creativecommons.org/licenses/by/3.0/'
   ], [
     'HTTP',
     '1999 The Internet Society',

+ 4 - 1
assets/javascripts/templates/pages/news_tmpl.coffee

@@ -24,7 +24,10 @@ newsItem = (date, news) ->
   result
 
 app.news = [
-  [ 1396137600000, # March 30, 2014
+  [ 1396742400000, # April 6, 2014
+    """ New <a href="/go/">Go</a> documentation """,
+  ], [
+    1396137600000, # March 30, 2014
     """ New <a href="/cpp/">C++</a> documentation """,
   ], [
     1394928000000, # March 16, 2014

+ 6 - 0
assets/javascripts/views/pages/go.coffee

@@ -0,0 +1,6 @@
+#= require views/pages/base
+
+class app.views.GoPage extends app.views.BasePage
+  afterRender: ->
+    @highlightCode @findAll('pre'), 'go'
+    return

+ 1 - 0
assets/stylesheets/application.css.scss

@@ -33,6 +33,7 @@
         'pages/coffeescript',
         'pages/d3',
         'pages/ember',
+        'pages/go',
         'pages/jquery',
         'pages/knockout',
         'pages/git',

+ 1 - 0
assets/stylesheets/global/_icons.scss

@@ -52,3 +52,4 @@
 %icon-path                  { background-position: -3rem -7rem; }
 ._icon-yii:before           { background-position: -4rem -7rem; }
 ._icon-cpp:before           { background-position: 0 -8rem; }
+._icon-go:before            { background-position: -1rem -8rem; }

+ 7 - 0
assets/stylesheets/pages/_go.scss

@@ -0,0 +1,7 @@
+._go {
+  padding-left: 1rem;
+
+  h1, h2, #short-nav, table.dir { margin-left: -1rem; }
+  h2 { @extend %block-heading; }
+  h3 { @extend %block-label, %label-blue; }
+}

+ 46 - 0
lib/docs/filters/go/clean_html.rb

@@ -0,0 +1,46 @@
+module Docs
+  class Go
+    class CleanHtmlFilter < Filter
+      def call
+        if root_page?
+          at_css('h1').content = 'Go Programming Language'
+
+          # Remove empty columns
+          css('tr:first-child + tr', 'th:first-child + th', 'td:first-child + td').remove
+
+          # Remove links to unscraped pages
+          css('td + td:empty').each do |node|
+            node.previous_element.content = node.previous_element.content
+          end
+        end
+
+        css('#plusone', '#nav', '.pkgGopher', '#footer', '.collapsed').remove
+
+        # Remove triangle character
+        css('h2', '.exampleHeading').each do |node|
+          node.content = node.content.sub("\u25BE", '')
+          node.name = 'h2'
+        end
+
+        # Turn <dl> into <ul>
+        css('#short-nav', '#manual-nav').each do |node|
+          node.children = node.css('dd').tap { |nodes| nodes.each { |dd| dd.name = 'li' } }
+          node.name = 'ul'
+        end
+
+        # Remove code highlighting
+        css('pre').each do |node|
+          node.content = node.content
+        end
+
+        # Fix example markup
+        css('.play').each do |node|
+          node.children = node.at_css('.code').children
+          node.name = 'pre'
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 33 - 0
lib/docs/filters/go/entries.rb

@@ -0,0 +1,33 @@
+module Docs
+  class Go
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        name = at_css('h1').content
+        name.sub! 'Package ', ''
+        name
+      end
+
+      def get_type
+        subpath[/\A[^\/]+/]
+      end
+
+      def additional_entries
+        css('#manual-nav a').each_with_object [] do |node, entries|
+          case node.content
+          when /type\ (\w+)/
+            name = $1
+          when /func\ (?:\(.+\)\ )?(\w+)\(/
+            name = "#{$1}()"
+            name.prepend "#{$1}." if node['href'] =~ /#(\w+)\.#{$1}/
+          end
+
+          entries << ["#{name} (#{self.name})", node['href'][1..-1]] if name
+        end
+      end
+
+      def include_default_entry?
+        !at_css('h1 + table.dir')
+      end
+    end
+  end
+end

+ 22 - 0
lib/docs/scrapers/go.rb

@@ -0,0 +1,22 @@
+module Docs
+  class Go < UrlScraper
+    self.type = 'go'
+    self.version = '1.2.1'
+    self.base_url = 'http://golang.org/pkg/'
+
+    html_filters.push 'go/clean_html', 'go/entries'
+
+    options[:container] = '#page .container'
+
+    options[:attribution] = <<-HTML
+      &copy; Google, Inc.<br>
+      Licensed under the Creative Commons Attribution License 3.0.
+    HTML
+
+    private
+
+    def parse(html) # Hook here because Nokogori removes whitespace from textareas
+      super html.gsub %r{<textarea\ class="code"[^>]*>([\W\w]+?)</textarea>}, '<pre class="code">\1</pre>'
+    end
+  end
+end

BIN
public/icons/docs/go/16.png


BIN
public/icons/docs/go/16@2x.png


+ 1 - 0
public/icons/docs/go/SOURCE

@@ -0,0 +1 @@
+http://golang.org/doc/gopher/