Update Pygame documentation (2.0.0)

pull/1413/head
Phil Scherer 4 years ago
parent 23a0004f7b
commit d6756ce24f

@ -92,6 +92,7 @@
'pages/phpunit', 'pages/phpunit',
'pages/postgres', 'pages/postgres',
'pages/pug', 'pages/pug',
'pages/pygame',
'pages/python', 'pages/python',
'pages/qt', 'pages/qt',
'pages/ramda', 'pages/ramda',

@ -0,0 +1,12 @@
._pygame {
@extend %simple;
dl.class > dt { @extend %block-label, %label-orange; }
dl.function > dt, dl.method > dt { @extend %block-label, %label-blue; }
dl.attribute > dt, dl.exception > dt , dl.data > dt { @extend %block-label, %label-green; }
.line-block { @extend %note; }
.line-block > .line:first-child { margin-bottom: 1em; }
.line-block > .line:only-child { margin-bottom: 0em; }
span.signature { font-family: monospace; }
}

@ -2,100 +2,46 @@ module Docs
class Pygame class Pygame
class CleanHtmlFilter < Filter class CleanHtmlFilter < Filter
def call def call
@doc = at_css '.body' @doc = at_css('.body')
root_page? ? root : other
doc
end
def root
at_css('h1').content = 'Pygame'
if root_page?
# remove unneeded stuff # remove unneeded stuff
at_css('.modindex-jumpbox').remove at_css('.modindex-jumpbox').remove
css('[role="navigation"], .pcap, .cap, .footer').remove css('[role="navigation"], .pcap, .cap, .footer').remove
# table -> list css('tr > td:first-child').remove
list = at_css('table')
list.replace(list.children)
list.name = 'ul'
css('tr').each do |row|
row.name = 'li'
row.remove_attribute('class')
end
at_css('h1').content = 'Pygame'
return doc
end
# remove unwanted stuff
# .headerlink => ¶ after links
# .toc => table of content
# .tooltip-content => tooltips after links to functions
css('table.toc.docutils, .headerlink, .tooltip-content').remove
# Remove wrapper .section
section = at_css('.section')
definition = at_css('.definition')
definition['id'] = section['id']
section.replace(section.children)
# Format code for it be highlighted # Unitalicize package descriptions
css('.highlight-default.notranslate').each do |node| css('td > em').each do |node|
pre = node.at_css('pre') node.parent.content = node.content
node.replace(pre)
# gets rid of the already existing syntax highlighting
pre.content = pre.content
pre['class'] = 'language-python'
pre['data-language'] = "python"
end end
# change descriptions of functions/attributes to blockquote
css('.line-block').each do |node|
node.name = 'blockquote'
end end
# change functions def other
css('.definition').each do |d| css('> :not(.section), table.toc.docutils, .tooltip-content').remove
# the header is the function/attribute name. It might look something like
# this:
# pygame.image.load()
# It'll end up being something like this:
# pygame.image.load(filename) -> Surface
# pygame.image.load(fileobj, namehint="") -> Surface
header = d.at_css('dt.title') # Remove code tag from function, class, method, module, etc.
if d['class'].include?('class') or d['class'].include?('module') css('dl > dt').each do |node|
header.name = 'h1' node.content = node.content
@section = header.content.strip
else
header.name = 'h3'
end
# save the original header
initial_header = header.content.strip
# save the real name for the entries
header['data-name'] = initial_header
# empty the header
if header.name == 'h3'
header.inner_html = ''
end
# to replace it with the signatures
next_el = header.next_element
signatures = next_el.css('.signature')
signatures.each do |sig|
sig.name = 'code'
if header.name == 'h3'
sig.parent = header
# the signature don't contain pygame.module. I think it's better
# to display them, as it avoids confusion with methods (have a
# look at the pygame.Rect page)
if initial_header.start_with?(@section)
sig.content = @section + '.' + sig.text
end
# separate the signatures on different lines.
header.add_child "<br>"
end
end end
css('> .section > dl > dt').each do |node|
node.name = 'h1'
node.parent.parent.before(node)
end end
css('> dl', '> dl > dd', 'h1 code').each do |node| # Format code for it be highlighted
node.before(node.children).remove css('.highlight-default.notranslate').each do |node|
node.name = 'pre'
node.content = node.content.strip
node['class'] = 'language-python'
node['data-language'] = 'python'
end end
doc
end end
end end
end end

@ -2,26 +2,19 @@ module Docs
class Pygame class Pygame
class EntriesFilter < Docs::EntriesFilter class EntriesFilter < Docs::EntriesFilter
def get_name def get_name
at_css('h1').content.remove('pygame.') at_css('.title').content.remove('pygame.').strip
end end
def get_type def get_type
at_css('h1').content at_css('.title').content.strip
end end
def additional_entries def additional_entries
return [] if root_page? css('dl.definition > dt.title').each_with_object [] do |node, entries|
name = node['id'] || node.parent.parent['id']
css('h1, h2, h3').each_with_object [] do |node, entries| name.remove! 'pygame.'
name = node['id'] || node['data-name'] id = node['id']
entries << [name, id] unless name == self.name
if node.parent['class'].include?('function') or node.parent['class'].include?('method')
name << '()'
end
name.remove!('pygame.')
entries << [name, node['id']] unless name == self.name
end end
end end
end end

@ -0,0 +1,11 @@
module Docs
class Pygame
class PreCleanHtmlFilter < Filter
def call
# Remove ¶ character from tag w/ name & type
css('.headerlink').remove
doc
end
end
end
end

@ -1,7 +1,7 @@
module Docs module Docs
class Pygame < UrlScraper class Pygame < UrlScraper
self.type = 'simple' self.type = 'pygame'
self.release = '1.9.6' self.release = '2.0.0'
self.base_url = 'https://www.pygame.org/docs/' self.base_url = 'https://www.pygame.org/docs/'
self.root_path = 'py-modindex.html' self.root_path = 'py-modindex.html'
self.links = { self.links = {
@ -9,7 +9,7 @@ module Docs
code: 'https://github.com/pygame/pygame' code: 'https://github.com/pygame/pygame'
} }
html_filters.push 'pygame/clean_html', 'pygame/entries' html_filters.push 'pygame/pre_clean_html', 'pygame/entries', 'pygame/clean_html'
options[:only_patterns] = [/ref\//] options[:only_patterns] = [/ref\//]

Loading…
Cancel
Save