Jonas Meinertz Hansen пре 9 година
родитељ
комит
547f4f54ed

+ 18 - 0
lib/docs/filters/numpy/clean_html.rb

@@ -0,0 +1,18 @@
+module Docs
+  class Numpy
+    class CleanHtmlFilter < Filter
+      def call
+        @doc = at_css('#spc-section-body')
+
+        css('.headerlink').remove  # remove permalinks
+
+        # Add class for correct syntax highlighting
+        css('pre').each do |pre|
+          pre['class'] = 'python'
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 50 - 0
lib/docs/filters/numpy/entries.rb

@@ -0,0 +1,50 @@
+module Docs
+  class Numpy
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        dt = at_css('dt')
+        if dt
+          name = dt.content
+          name.sub! /\(.*/, '()'
+          name.sub! /[\=\[].*/, ''
+          name.remove! 'class '
+          name.remove! 'classmethod '
+          name.remove! 'exception '
+        else
+          name = at_css('h1').content.strip
+        end
+        name.remove! '¶' # remove permalinks from title
+        name
+      end
+
+      def get_type
+        type = name.dup
+        nav_items = at_css('.nav.nav-pills.pull-left').children
+        if nav_items[7]
+          # Infer type from navigation item if possible...
+          type = nav_items[7].content
+        else
+          # ... or the page is probably an overview, so use its title.
+          type = at_css('h1').content
+          type.remove! '¶' # remove permalinks from type
+
+          # Handle some edge cases that arent proberly categorized in the docs
+          if type[0..16] == 'numpy.polynomial.'
+            type = 'Polynomials'
+          elsif type[0..11] == 'numpy.ufunc.'
+            type = 'Universal functions (ufunc)'
+          elsif type[0..12] == 'numpy.nditer.'
+            type = 'Indexing routines'
+          elsif type == 'numpy.core.defchararray.chararray.argsort'
+            type = 'String operations'
+          elsif type == 'numpy.memmap.shape'
+            type = 'Input and output'
+          elsif type == 'numpy.poly1d.variable'
+            type = 'Polynomials'
+          end
+        end
+        type
+      end
+    end
+  end
+end

+ 36 - 0
lib/docs/scrapers/numpy.rb

@@ -0,0 +1,36 @@
+module Docs
+  class Numpy < FileScraper
+    self.name = 'NumPy'
+    self.type = 'sphinx'
+    self.root_path = 'routines.html'
+    self.links = {
+      home: 'http://www.numpy.org/',
+      code: 'https://github.com/numpy/numpy'
+    }
+
+    html_filters.push 'numpy/entries', 'numpy/clean_html'
+
+    # .main contains more than the page's content alone, but we need something
+    # that includes the navigation bar as well in order to guess the type of
+    # most pages.
+    options[:container] = '.main'
+
+    # "generated" pages seem to be autogenerated from python docstrings.
+    # "routines" are mostly lists that help organize the generated pages.
+    # Everything else is manual-like and probably not desired in Devdocs.
+    options[:only_patterns] = [
+      /routines\.?.*\.html/,
+      /generated.*/]
+
+    options[:attribution] = <<-HTML
+      &copy; Copyright 2008-2015, The Scipy community.<br>
+      Licensed under a BSD-new License.
+    HTML
+
+    version '1.10' do
+      self.release = '1.10'
+      self.dir = '/vagrant/numpy-html/reference/'
+      # self.base_url = 'http://docs.scipy.org/doc/numpy/reference/'
+    end
+  end
+end

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


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


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

@@ -0,0 +1 @@
+https://www.scipy.org/_static/images/numpylogo_med.png