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
92 'pages/phpunit',92 'pages/phpunit',
93 'pages/postgres',93 'pages/postgres',
94 'pages/pug',94 'pages/pug',
95 'pages/pygame',
95 'pages/python',96 'pages/python',
96 'pages/qt',97 'pages/qt',
97 'pages/ramda',98 '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
2 class Pygame2 class Pygame
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 @doc = at_css '.body'5 @doc = at_css('.body')
6 6 root_page? ? root : other
7 if root_page?7 doc
8 # remove unneeded stuff8 end
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
22 9
23 # remove unwanted stuff10 def root
24 # .headerlink => ¶ after links11 at_css('h1').content = 'Pygame'
25 # .toc => table of content
26 # .tooltip-content => tooltips after links to functions
27 css('table.toc.docutils, .headerlink, .tooltip-content').remove
28 12
29 # Remove wrapper .section13 # remove unneeded stuff
30 section = at_css('.section')14 at_css('.modindex-jumpbox').remove
31 definition = at_css('.definition')15 css('[role="navigation"], .pcap, .cap, .footer').remove
32 definition['id'] = section['id']16 css('tr > td:first-child').remove
33 section.replace(section.children)
34 17
35 # Format code for it be highlighted18 # Unitalicize package descriptions
36 css('.highlight-default.notranslate').each do |node|19 css('td > em').each do |node|
37 pre = node.at_css('pre')20 node.parent.content = node.content
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'
48 end21 end
22 end
49 23
50 # change functions24 def other
51 css('.definition').each do |d|25 css('> :not(.section), table.toc.docutils, .tooltip-content').remove
52 26
53 # the header is the function/attribute name. It might look something like27 # Remove code tag from function, class, method, module, etc.
54 # this:28 css('dl > dt').each do |node|
55 # pygame.image.load()29 node.content = node.content
56 # It'll end up being something like this:30 end
57 # pygame.image.load(filename) -> Surface
58 # pygame.image.load(fileobj, namehint="") -> Surface
59 31
60 header = d.at_css('dt.title')32 css('> .section > dl > dt').each do |node|
61 if d['class'].include?('class') or d['class'].include?('module')33 node.name = 'h1'
62 header.name = 'h1'34 node.parent.parent.before(node)
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
92 end35 end
93 36
94 css('> dl', '> dl > dd', 'h1 code').each do |node|37 # Format code for it be highlighted
95 node.before(node.children).remove38 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'
96 end43 end
97 44
98 doc
99 end45 end
100 end46 end
101 end47 end
lib/docs/filters/pygame/entries.rb+7−14
@@ -2,26 +2,19 @@ module Docs · 1 unmodified line
2 class Pygame2 class Pygame
3 class EntriesFilter < Docs::EntriesFilter3 class EntriesFilter < Docs::EntriesFilter
4 def get_name4 def get_name
5 at_css('h1').content.remove('pygame.')5 at_css('.title').content.remove('pygame.').strip
6 end6 end
7 7
8 def get_type8 def get_type
9 at_css('h1').content9 at_css('.title').content.strip
10 end10 end
11 11
12 def additional_entries12 def additional_entries
13 return [] if root_page?13 css('dl.definition > dt.title').each_with_object [] do |node, entries|
14 14 name = node['id'] || node.parent.parent['id']
15 css('h1, h2, h3').each_with_object [] do |node, entries|15 name.remove! 'pygame.'
16 name = node['id'] || node['data-name']16 id = node['id']
17 17 entries << [name, id] unless name == self.name
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
25 end18 end
26 end19 end
27 end20 end
lib/docs/filters/pygame/pre_clean_html.rb+11−0
@@ -0,0 +1,11 @@
1module 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
11end
lib/docs/scrapers/pygame.rb+3−3
@@ -1,7 +1,7 @@
1module Docs1module Docs
2 class Pygame < UrlScraper2 class Pygame < UrlScraper
3 self.type = 'simple'3 self.type = 'pygame'
4 self.release = '1.9.6'4 self.release = '2.0.0'
5 self.base_url = 'https://www.pygame.org/docs/'5 self.base_url = 'https://www.pygame.org/docs/'
6 self.root_path = 'py-modindex.html'6 self.root_path = 'py-modindex.html'
7 self.links = {7 self.links = {
@@ -9,7 +9,7 @@ module Docs · 1 unmodified line
9 code: 'https://github.com/pygame/pygame'9 code: 'https://github.com/pygame/pygame'
10 }10 }
11 11
12 html_filters.push 'pygame/clean_html', 'pygame/entries'12 html_filters.push 'pygame/pre_clean_html', 'pygame/entries', 'pygame/clean_html'
13 13
14 options[:only_patterns] = [/ref\//]14 options[:only_patterns] = [/ref\//]
15 15