History

Finish Matplotlib scraper

Thibaut Courouble committed 10 years ago

Commit 8d038301 parent 8f8815012 files · +102 −17Browse files

Unified · Split

12 files
  1. assets/images/docs.png +0 −0
  2. assets/images/docs@2x.png +0 −0
  3. assets/javascripts/news.json +2 −2
  4. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  5. assets/stylesheets/global/_icons.scss +1 −0
  6. assets/stylesheets/pages/_sphinx.scss +6 −3
  7. lib/docs/filters/matplotlib/clean_html.rb +56 −1
  8. lib/docs/filters/matplotlib/entries.rb +27 −9
  9. lib/docs/scrapers/matplotlib.rb +8 −6
  10. public/icons/docs/matplotlib/16.png +0 −0
  11. public/icons/docs/matplotlib/16@2x.png +0 −0
  12. public/icons/docs/matplotlib/SOURCE +1 −0
assets/images/docs.png+0−0

Binary file not shown.

assets/images/docs@2x.png+0−0

Binary file not shown.

assets/javascripts/news.json+2−2
@@ -1,7 +1,7 @@
11 [
22 [
3− "2016-07-02",
4− "New documentation: <a href=\"/cmake/\">CMake</a>"
3+ "2016-07-03",
4+ "New documentations: <a href=\"/cmake/\">CMake</a> and <a href=\"/matplotlib/\">Matplotlib</a>"
55 ], [
66 "2016-06-19",
77 "New documentation: <a href=\"/love/\">L&Ouml;VE</a>"
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -295,6 +295,11 @@ credits = [ · 294 unmodified lines
295295 '2004 John Gruber',
296296 'BSD',
297297 'https://daringfireball.net/projects/markdown/license'
298+ ], [
299+ 'Matplotlib',
300+ '2012-2016 Matplotlib Development Team. All rights reserved.',
301+ 'Custom',
302+ 'https://raw.githubusercontent.com/matplotlib/matplotlib/master/LICENSE/LICENSE'
298303 ], [
299304 'Meteor',
300305 '2011-2016 Meteor Development Group',
assets/stylesheets/global/_icons.scss+1−0
@@ -132,6 +132,7 @@ · 131 unmodified lines
132132 ._icon-q:before { background-position: -5rem -8rem; }
133133 ._icon-react_native:before { background-position: 0 -9rem; }
134134 ._icon-phalcon:before { background-position: -1rem -9rem; }
135+._icon-matplotlib:before { background-position: -2rem -9rem; }
135136 ._icon-cmake:before { background-position: -3rem -9rem; }
136137 ._icon-elixir:before { background-position: -4rem -9rem; @extend %darkIconFix !optional; }
137138 ._icon-vagrant:before { background-position: -5rem -9rem; }
assets/stylesheets/pages/_sphinx.scss+6−3
@@ -1,6 +1,8 @@
11 %sphinx {
22 h2, h3 { @extend %block-heading; }
3− dl:not(.docutils) > dt { @extend %block-label, %label-blue; }
3+ h4 { font-size: 1em; }
4+ > dl:not(.docutils) > dt { @extend %block-label, %label-blue; }
5+ dl > dl > dt { @extend %block-label; }
46 dt + dt { margin-top: -.5em; }
57
68 .note, .admonition, .versionadded, .versionchanged, .deprecated-removed { @extend %note; }
@@ -8,7 +10,7 @@ · 1 unmodified line
810 .warning, .deprecated-removed { @extend %note-red; }
911 .versionmodified { font-weight: bold; }
1012
11− p > code, li > code { @extend %label; }
13+ p > code, li > code, dd > code { @extend %label; }
1214
1315 .admonition-title {
1416 float: left;
@@ -22,10 +24,11 @@ · 7 unmodified lines
2224 clear: left;
2325 margin: 0;
2426 }
27+ .admonition-title + dl { padding-top: .5em; }
2528
2629 ul.simple { margin: 1em 0; }
2730
28− h2 > a, h3 > a, dt > a { float: right; }
31+ h2 > a, h3 > a, dt[id] > a.external { float: right; }
2932 }
3033
3134 ._sphinx {
lib/docs/filters/matplotlib/clean_html.rb+56−1
@@ -2,9 +2,64 @@ module Docs · 1 unmodified line
22 class Matplotlib
33 class CleanHtmlFilter < Filter
44 def call
5− css('.headerlink').each do |node|
5+ css('.headerlink', 'hr').remove
6+
7+ css('.toc-backref', '.toctree-wrapper', '.contents', 'span.pre', 'pre a > code').each do |node|
8+ node.before(node.children).remove
9+ end
10+
11+ css('div[class*="highlight-"]').each do |node|
12+ pre = node.at_css('pre')
13+ pre.content = pre.content
14+ pre['data-language'] = node['class'][/highlight\-(\w+)/, 1]
15+ node.replace(pre)
16+ end
17+
18+ css('span[id]:empty').each do |node|
19+ node.next_element['id'] = node['id']
620 node.remove
721 end
22+
23+ css('.section').each do |node|
24+ if node['id']
25+ if node.first_element_child['id']
26+ node.element_children[1]['id'] = node['id']
27+ else
28+ node.first_element_child['id'] = node['id']
29+ end
30+ end
31+
32+ node.before(node.children).remove
33+ end
34+
35+ css('h2 > a > code').each do |node|
36+ node.parent.before(node.content).remove
37+ end
38+
39+ css('dt[id]').each do |node|
40+ node.inner_html = "<code>#{node.content.strip}</code>"
41+ end
42+
43+ css('li > p:first-child:last-child').each do |node|
44+ node.before(node.children).remove
45+ end
46+
47+ css('table[border]').each do |node|
48+ node.remove_attribute 'border'
49+ end
50+
51+ css('code[class]').each do |node|
52+ node.remove_attribute 'class'
53+ end
54+
55+ css('h1').each do |node|
56+ node.content = node.content
57+ end
58+
59+ css('p.rubric').each do |node|
60+ node.name = 'h4'
61+ end
62+
863 doc
964 end
1065 end
lib/docs/filters/matplotlib/entries.rb+27−9
@@ -1,29 +1,47 @@
11 module Docs
22 class Matplotlib
33 class EntriesFilter < Docs::EntriesFilter
4+ NAME_BY_SLUG = {
5+ 'matplotlib_configuration_api' => 'matplotlib',
6+ 'tri_api' => 'tri'
7+ }
8+
9+ TYPE_BY_SLUG = {
10+ 'pyplot_summary' => 'pyplot'
11+ }
12+
413 def get_name
14+ return NAME_BY_SLUG[slug] if NAME_BY_SLUG.key?(slug)
515 name = at_css('h1').content.strip
616 name.remove! "\u{00b6}"
17+ name.remove! 'matplotlib.'
18+ name.remove! %r{ \(.*\)}
19+ name.downcase!
720 name
821 end
922
1023 def get_type
11− name = at_css('h1').content.strip
12− name.remove! "\u{00b6}"
13− name
24+ return TYPE_BY_SLUG[slug] if TYPE_BY_SLUG.key?(slug)
25+ name.split('.').first
1426 end
1527
1628 def additional_entries
1729 entries = []
18− ents = css('dt .descname')
1930
20− if ents
21− ents.each do |node|
22− name = node.content.sub(/\(.*\)/, '()')
23− id = node.parent['id']
24− entries << [name, id, get_name]
31+ css('.class > dt[id]', '.exception > dt[id]', '.attribute > dt[id]').each do |node|
32+ entries << [node['id'].remove('matplotlib.'), node['id']]
33+ end
34+
35+ css('.data > dt[id]').each do |node|
36+ if node['id'].split('.').last.upcase! # skip constants
37+ entries << [node['id'].remove('matplotlib.'), node['id']]
2538 end
2639 end
40+
41+ css('.function > dt[id]', '.method > dt[id]', '.classmethod > dt[id]').each do |node|
42+ entries << [node['id'].remove('matplotlib.') + '()', node['id']]
43+ end
44+
2745 entries
2846 end
2947 end
lib/docs/scrapers/matplotlib.rb+8−6
@@ -1,9 +1,8 @@
11 module Docs
2− class Matplotlib < FileScraper
2+ class Matplotlib < UrlScraper
33 self.name = 'Matplotlib'
44 self.type = 'sphinx'
55 self.root_path = 'index.html'
6− self.release = "1.5.1"
76 self.links = {
87 home: 'http://matplotlib.org/',
98 code: 'https://github.com/matplotlib/matplotlib'
@@ -12,13 +11,16 @@ module Docs · 2 unmodified lines
1211 html_filters.push 'matplotlib/entries', 'matplotlib/clean_html'
1312
1413 options[:container] = '.body'
14+ options[:skip] = %w(api_changes.html)
1515
1616 options[:attribution] = <<-HTML
17− &copy; Matplotlib Development Team <br>
18− Licensed under the BSD License.
17+ &copy; 2012&ndash;2016 Matplotlib Development Team. All rights reserved.<br>
18+ Licensed under the Matplotlib License Agreement.
1919 HTML
2020
21− self.dir = '~/workspace/tmp/matplotlib/matplotlib.github.com-master/1.5.1/api/'
22− # self.base_url = 'http://matplotlib.org/api/'
21+ version '1.5' do
22+ self.release = '1.5.1'
23+ self.base_url = 'http://matplotlib.org/1.5.1/api/'
24+ end
2325 end
2426 end
public/icons/docs/matplotlib/16.png+0−0

Binary file not shown.

public/icons/docs/matplotlib/16@2x.png+0−0

Binary file not shown.

public/icons/docs/matplotlib/SOURCE+1−0
@@ -0,0 +1 @@
1+https://upload.wikimedia.org/wikipedia/commons/thumb/8/84/Matplotlib_icon.svg/1024px-Matplotlib_icon.svg.png