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 00000000..51a7c4f6 Binary files /dev/null and b/public/icons/docs/numpy/16.png differ diff --git a/public/icons/docs/numpy/16@2x.png b/public/icons/docs/numpy/16@2x.png new file mode 100644 index 00000000..4e0e5f7d Binary files /dev/null and b/public/icons/docs/numpy/16@2x.png differ diff --git a/public/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