From 547f4f54edb03290a81457c3a3ebcd6e48c69cda Mon Sep 17 00:00:00 2001 From: Jonas Meinertz Hansen Date: Mon, 18 Apr 2016 00:26:21 +0200 Subject: [PATCH] Add NumPy documentation --- lib/docs/filters/numpy/clean_html.rb | 18 ++++++++++ lib/docs/filters/numpy/entries.rb | 50 +++++++++++++++++++++++++++ lib/docs/scrapers/numpy.rb | 36 +++++++++++++++++++ public/icons/docs/numpy/16.png | Bin 0 -> 1632 bytes public/icons/docs/numpy/16@2x.png | Bin 0 -> 3672 bytes public/icons/docs/numpy/SOURCE | 1 + 6 files changed, 105 insertions(+) create mode 100644 lib/docs/filters/numpy/clean_html.rb create mode 100644 lib/docs/filters/numpy/entries.rb create mode 100644 lib/docs/scrapers/numpy.rb create mode 100644 public/icons/docs/numpy/16.png create mode 100644 public/icons/docs/numpy/16@2x.png create mode 100644 public/icons/docs/numpy/SOURCE diff --git a/lib/docs/filters/numpy/clean_html.rb b/lib/docs/filters/numpy/clean_html.rb new file mode 100644 index 00000000..b36f9568 --- /dev/null +++ b/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 diff --git a/lib/docs/filters/numpy/entries.rb b/lib/docs/filters/numpy/entries.rb new file mode 100644 index 00000000..aeb54e05 --- /dev/null +++ b/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 diff --git a/lib/docs/scrapers/numpy.rb b/lib/docs/scrapers/numpy.rb new file mode 100644 index 00000000..d732d883 --- /dev/null +++ b/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 + © Copyright 2008-2015, The Scipy community.
+ 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 diff --git a/public/icons/docs/numpy/16.png b/public/icons/docs/numpy/16.png new file mode 100644 index 0000000000000000000000000000000000000000..51a7c4f6f8452162fa512e044e3016a1afbcb531 GIT binary patch literal 1632 zcmV-m2A}zfP)004&y004{^008_l004#4004Qw008hY002EO001E}O0Tse0006a zX+uL$Nkc;*P;zf(X>4Tx065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/icons/docs/numpy/SOURCE b/public/icons/docs/numpy/SOURCE new file mode 100644 index 00000000..62755b70 --- /dev/null +++ b/public/icons/docs/numpy/SOURCE @@ -0,0 +1 @@ +https://www.scipy.org/_static/images/numpylogo_med.png