History

Update Pygame documentation (2.0.0)

Phil Scherer committed 5 years ago

Commit d6756ce1 parent 23a00046 files · +63 −100Browse files

Unified · Split

6 files
  1. assets/stylesheets/application.css.scss +1 −0
  2. assets/stylesheets/pages/_pygame.scss +12 −0
  3. lib/docs/filters/pygame/clean_html.rb +29 −83
  4. lib/docs/filters/pygame/entries.rb +7 −14
  5. lib/docs/filters/pygame/pre_clean_html.rb +11 −0
  6. lib/docs/scrapers/pygame.rb +3 −3
assets/stylesheets/application.css.scss+1−0
@@ -92,6 +92,7 @@ · 91 unmodified lines
9292 'pages/phpunit',
9393 'pages/postgres',
9494 'pages/pug',
95+ 'pages/pygame',
9596 'pages/python',
9697 'pages/qt',
9798 'pages/ramda',
assets/stylesheets/pages/_pygame.scss+12−0
@@ -0,0 +1,12 @@
1+._pygame {
2+ @extend %simple;
3+
4+ dl.class > dt { @extend %block-label, %label-orange; }
5+ dl.function > dt, dl.method > dt { @extend %block-label, %label-blue; }
6+ dl.attribute > dt, dl.exception > dt , dl.data > dt { @extend %block-label, %label-green; }
7+
8+ .line-block { @extend %note; }
9+ .line-block > .line:first-child { margin-bottom: 1em; }
10+ .line-block > .line:only-child { margin-bottom: 0em; }
11+ span.signature { font-family: monospace; }
12+}
lib/docs/filters/pygame/clean_html.rb+29−83
@@ -2,100 +2,46 @@ module Docs · 1 unmodified line
22 class Pygame
33 class CleanHtmlFilter < Filter
44 def call
5− @doc = at_css '.body'
6−
7− if root_page?
8− # remove unneeded stuff
9− at_css('.modindex-jumpbox').remove
10− css('[role="navigation"],.pcap, .cap, .footer').remove
11− # table -> list
12− list = at_css('table')
13− list.replace(list.children)
14− list.name = 'ul'
15− css('tr').each do |row|
16− row.name = 'li'
17− row.remove_attribute('class')
18− end
19− at_css('h1').content = 'Pygame'
20− return doc
21− end
5+ @doc = at_css('.body')
6+ root_page? ? root : other
7+ doc
8+ end
229
23− # remove unwanted stuff
24− # .headerlink => ¶ after links
25− # .toc => table of content
26− # .tooltip-content => tooltips after links to functions
27− css('table.toc.docutils, .headerlink, .tooltip-content').remove
10+ def root
11+ at_css('h1').content = 'Pygame'
2812
29− # Remove wrapper .section
30− section = at_css('.section')
31− definition = at_css('.definition')
32− definition['id'] = section['id']
33− section.replace(section.children)
13+ # remove unneeded stuff
14+ at_css('.modindex-jumpbox').remove
15+ css('[role="navigation"], .pcap, .cap, .footer').remove
16+ css('tr > td:first-child').remove
3417
35− # Format code for it be highlighted
36− css('.highlight-default.notranslate').each do |node|
37− pre = node.at_css('pre')
38− node.replace(pre)
39− # gets rid of the already existing syntax highlighting
40− pre.content = pre.content
41− pre['class'] = 'language-python'
42− pre['data-language'] = "python"
43− end
44−
45− # change descriptions of functions/attributes to blockquote
46− css('.line-block').each do |node|
47− node.name = 'blockquote'
18+ # Unitalicize package descriptions
19+ css('td > em').each do |node|
20+ node.parent.content = node.content
4821 end
22+ end
4923
50− # change functions
51− css('.definition').each do |d|
24+ def other
25+ css('> :not(.section), table.toc.docutils, .tooltip-content').remove
5226
53− # the header is the function/attribute name. It might look something like
54− # this:
55− # pygame.image.load()
56− # It'll end up being something like this:
57− # pygame.image.load(filename) -> Surface
58− # pygame.image.load(fileobj, namehint="") -> Surface
27+ # Remove code tag from function, class, method, module, etc.
28+ css('dl > dt').each do |node|
29+ node.content = node.content
30+ end
5931
60− header = d.at_css('dt.title')
61− if d['class'].include?('class') or d['class'].include?('module')
62− header.name = 'h1'
63− @section = header.content.strip
64− else
65− header.name = 'h3'
66− end
67− # save the original header
68− initial_header = header.content.strip
69− # save the real name for the entries
70− header['data-name'] = initial_header
71− # empty the header
72− if header.name == 'h3'
73− header.inner_html = ''
74− end
75− # to replace it with the signatures
76− next_el = header.next_element
77− signatures = next_el.css('.signature')
78− signatures.each do |sig|
79− sig.name = 'code'
80− if header.name == 'h3'
81− sig.parent = header
82− # the signature don't contain pygame.module. I think it's better
83− # to display them, as it avoids confusion with methods (have a
84− # look at the pygame.Rect page)
85− if initial_header.start_with?(@section)
86− sig.content = @section + '.' + sig.text
87− end
88− # separate the signatures on different lines.
89− header.add_child "<br>"
90− end
91− end
32+ css('> .section > dl > dt').each do |node|
33+ node.name = 'h1'
34+ node.parent.parent.before(node)
9235 end
9336
94− css('> dl', '> dl > dd', 'h1 code').each do |node|
95− node.before(node.children).remove
37+ # Format code for it be highlighted
38+ css('.highlight-default.notranslate').each do |node|
39+ node.name = 'pre'
40+ node.content = node.content.strip
41+ node['class'] = 'language-python'
42+ node['data-language'] = 'python'
9643 end
9744
98− doc
9945 end
10046 end
10147 end
lib/docs/filters/pygame/entries.rb+7−14
@@ -2,26 +2,19 @@ module Docs · 1 unmodified line
22 class Pygame
33 class EntriesFilter < Docs::EntriesFilter
44 def get_name
5− at_css('h1').content.remove('pygame.')
5+ at_css('.title').content.remove('pygame.').strip
66 end
77
88 def get_type
9− at_css('h1').content
9+ at_css('.title').content.strip
1010 end
1111
1212 def additional_entries
13− return [] if root_page?
14−
15− css('h1, h2, h3').each_with_object [] do |node, entries|
16− name = node['id'] || node['data-name']
17−
18− if node.parent['class'].include?('function') or node.parent['class'].include?('method')
19− name << '()'
20− end
21−
22− name.remove!('pygame.')
23−
24− entries << [name, node['id']] unless name == self.name
13+ css('dl.definition > dt.title').each_with_object [] do |node, entries|
14+ name = node['id'] || node.parent.parent['id']
15+ name.remove! 'pygame.'
16+ id = node['id']
17+ entries << [name, id] unless name == self.name
2518 end
2619 end
2720 end
lib/docs/filters/pygame/pre_clean_html.rb+11−0
@@ -0,0 +1,11 @@
1+module Docs
2+ class Pygame
3+ class PreCleanHtmlFilter < Filter
4+ def call
5+ # Remove ¶ character from tag w/ name & type
6+ css('.headerlink').remove
7+ doc
8+ end
9+ end
10+ end
11+end
lib/docs/scrapers/pygame.rb+3−3
@@ -1,7 +1,7 @@
11 module Docs
22 class Pygame < UrlScraper
3− self.type = 'simple'
4− self.release = '1.9.6'
3+ self.type = 'pygame'
4+ self.release = '2.0.0'
55 self.base_url = 'https://www.pygame.org/docs/'
66 self.root_path = 'py-modindex.html'
77 self.links = {
@@ -9,7 +9,7 @@ module Docs · 1 unmodified line
99 code: 'https://github.com/pygame/pygame'
1010 }
1111
12− html_filters.push 'pygame/clean_html', 'pygame/entries'
12+ html_filters.push 'pygame/pre_clean_html', 'pygame/entries', 'pygame/clean_html'
1313
1414 options[:only_patterns] = [/ref\//]
1515