History

Finish Pygame scraper

Thibaut Courouble committed 8 years ago

Commit 34fe8331 parent 6f4f34812 files · +26 −31Browse files

Unified · Split

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

Binary file not shown.

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

Binary file not shown.

assets/javascripts/news.json+3−0
@@ -1,5 +1,8 @@
11 [
22 [
3+ "2018-07-29",
4+ "New documentation: <a href=\"/pygame/\">Pygame</a>"
5+ ], [
36 "2018-07-08",
47 "New documentations: <a href=\"/leaflet/\">Leaflet</a>, <a href=\"/terraform/\">Terraform</a> and <a href=\"/koa/\">Koa</a>"
58 ], [
assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -545,6 +545,11 @@ credits = [ · 544 unmodified lines
545545 '1996-2018 The PostgreSQL Global Development Group<br>&copy; 1994 The Regents of the University of California',
546546 'PostgreSQL',
547547 'https://www.postgresql.org/about/licence/'
548+ ], [
549+ 'Pygame',
550+ 'Pygame Developpers',
551+ 'LGPLv2.1',
552+ 'https://raw.githubusercontent.com/pygame/pygame/master/LICENSE'
548553 ], [
549554 'Python',
550555 '2001-2018 Python Software Foundation<br>Python is a trademark of the Python Software Foundation.',
assets/stylesheets/global/_icons.scss+1−0
@@ -173,3 +173,4 @@ · 172 unmodified lines
173173 ._icon-babel:before { background-position: -2rem -3rem; @extend %doc-icon-2; }
174174 ._icon-leaflet:before { background-position: -3rem -3rem; @extend %doc-icon-2; }
175175 ._icon-terraform:before { background-position: -4rem -3rem; @extend %doc-icon-2; }
176+._icon-pygame:before { background-position: -5rem -3rem; @extend %doc-icon-2; }
lib/docs/filters/pygame/clean_html.rb+9−11
@@ -2,23 +2,21 @@ module Docs · 1 unmodified line
22 class Pygame
33 class CleanHtmlFilter < Filter
44 def call
5−
65 @doc = at_css '.body'
76
87 if root_page?
98 # remove unneeded stuff
109 at_css('.modindex-jumpbox').remove
11− css('[role="navigation"],.pcap, .cap, .footer').each do |node|
12− node.remove
13− end
10+ css('[role="navigation"],.pcap, .cap, .footer').remove
1411 # table -> list
1512 list = at_css('table')
1613 list.replace(list.children)
1714 list.name = 'ul'
1815 css('tr').each do |row|
1916 row.name = 'li'
20− row['class'] = ''
17+ row.remove_attribute('class')
2118 end
19+ at_css('h1').content = 'Pygame'
2220 return doc
2321 end
2422
@@ -26,11 +24,7 @@ module Docs · 1 unmodified line
2624 # .headerlink => ¶ after links
2725 # .toc => table of content
2826 # .tooltip-content => tooltips after links to functions
29− if toremove = css('table.toc.docutils, .headerlink, .tooltip-content')
30− toremove.each do |node|
31− node.remove
32− end
33− end
27+ css('table.toc.docutils, .headerlink, .tooltip-content').remove
3428
3529 # Remove wrapper .section
3630 section = at_css('.section')
@@ -43,7 +37,7 @@ module Docs · 6 unmodified lines
4337 pre = node.at_css('pre')
4438 node.replace(pre)
4539 # gets rid of the already existing syntax highlighting
46− pre.inner_html = pre.inner_text
40+ pre.content = pre.content
4741 pre['class'] = 'language-python'
4842 pre['data-language'] = "python"
4943 end
@@ -97,6 +91,10 @@ module Docs · 47 unmodified lines
9791 end
9892 end
9993
94+ css('> dl', '> dl > dd', 'h1 code').each do |node|
95+ node.before(node.children).remove
96+ end
97+
10098 doc
10199 end
102100 end
lib/docs/filters/pygame/entries.rb+11−17
@@ -2,33 +2,27 @@ module Docs · 1 unmodified line
22 class Pygame
33 class EntriesFilter < Docs::EntriesFilter
44 def get_name
5− return 'pygame'
5+ at_css('h1').content.remove('pygame.')
66 end
77
88 def get_type
99 at_css('h1').content
1010 end
1111
12− def include_default_entry?
13− return false
14− end
15−
1612 def additional_entries
17− return ['pygame'] if root_page?
13+ return [] if root_page?
14+
15+ css('h1, h2, h3').each_with_object [] do |node, entries|
16+ name = node['id'] || node['data-name']
1817
19− entries = []
20− css('h1,h2,h3').each do |node|
21− parentclass = node.parent['class']
22− name = node['id']
23− if not name
24− name = node['data-name']
25− elsif parentclass.include?('function') or parentclass.include?('method')
26− name += '()'
18+ if node.parent['class'].include?('function') or node.parent['class'].include?('method')
19+ name << '()'
2720 end
28− name = name.sub('pygame.', '')
29− entries << [name, node['id'], nil]
21+
22+ name.remove!('pygame.')
23+
24+ entries << [name, node['id']] unless name == self.name
3025 end
31− entries
3226 end
3327 end
3428 end
lib/docs/scrapers/pygame.rb+3−9
@@ -1,15 +1,8 @@
11 module Docs
22 class Pygame < UrlScraper
3−
43 self.type = 'simple'
5−
6− self.release = 'v1.9.4.dev0'
7−
8− self.initial_paths = ['py-modindex.html']
9− self.base_url = 'https://www.pygame.org/docs/'
4+ self.release = '1.9.4'
105 self.root_path = 'py-modindex.html'
11− self.initial_paths = []
12−
136 self.links = {
147 home: 'https://www.pygame.org/',
158 code: 'https://github.com/pygame/pygame'
@@ -20,7 +13,8 @@ module Docs · 4 unmodified lines
2013 options[:only_patterns] = [/ref\//]
2114
2215 options[:attribution] = <<-HTML
23− &copy; Pygame Developpers.
16+ &copy; Pygame Developpers.<br>
17+ Licensed under the GNU LGPL License version 2.1.
2418 HTML
2519 end
2620 end
public/icons/docs-2.pxm+0−0

Binary file not shown.

public/icons/docs-2@2x.pxm+0−0

Binary file not shown.

public/icons/docs/pygame/16.png+0−0

Binary file not shown.

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

Binary file not shown.