Add Python documentation

pull/17/merge
Thibaut 11 years ago
parent 5878551f5e
commit 36d6a109dc

Binary file not shown.

Before

Width:  |  Height:  |  Size: 11 KiB

After

Width:  |  Height:  |  Size: 11 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 28 KiB

After

Width:  |  Height:  |  Size: 30 KiB

@ -138,6 +138,11 @@ credits = [
'1997-2013 The PHP Documentation Group',
'CC BY',
'http://creativecommons.org/licenses/by/3.0/'
], [
'Python',
'1990-2013 Python Software Foundation<br>Python is a trademark of the Python Software Foundation.',
'PSFL',
'http://docs.python.org/3/license.html'
], [
'Ruby',
'1993-2013 Yukihiro Matsumoto',

@ -24,7 +24,10 @@ newsItem = (date, news) ->
result
app.news = [
[ 1384819200000, # November 19, 2013
[ 1385424000000, # November 26, 2013
""" New <a href="/python/">Python</a> documentation """
], [
1384819200000, # November 19, 2013
""" New <a href="/rails/">Ruby on Rails</a> documentation """
], [
1384560000000, # November 16, 2013
@ -35,7 +38,8 @@ app.news = [
], [
1381276800000, # October 9, 2013
""" DevDocs is now available as a <a href="https://chrome.google.com/webstore/detail/devdocs/mnfehgbmkapmjnhcnbodoamcioleeooe">Chrome web app</a>. """
], [ 1379808000000, # September 22, 2013
], [
1379808000000, # September 22, 2013
""" New <a href="/php/">PHP</a> documentation """
], [
1378425600000, # September 6, 2013

@ -0,0 +1,6 @@
#= require views/pages/base
class app.views.SphinxPage extends app.views.BasePage
afterRender: ->
@highlightCode @findAll('pre.python'), 'python'
return

@ -38,5 +38,6 @@
'pages/php',
'pages/rdoc',
'pages/rfc',
'pages/sphinx',
'pages/underscore',
'pages/yard';

@ -153,7 +153,6 @@
%lined-heading {
white-space: nowrap;
overflow: hidden;
overflow-wrap: normal;
word-wrap: normal;
&:after {

@ -4,7 +4,7 @@
width: 1rem;
height: 1rem;
background-image: image-url('icons.png');
background-size: 5rem 6rem;
background-size: 5rem 7rem;
}
@media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
@ -41,3 +41,4 @@
._icon-php:before { background-position: -2rem -5rem; }
._icon-ruby:before { background-position: -3rem -5rem; }
._icon-rails:before { background-position: -4rem -5rem; }
._icon-python:before { background-position: 0 -6rem; }

@ -0,0 +1,26 @@
._sphinx {
h2, h3 { @extend %block-heading; }
dl:not(.docutils) > dt { @extend %block-label, %label-blue; }
dt + dt { margin-top: -.5em; }
.note, .admonition, .versionadded, .versionchanged, .deprecated-removed { @extend %note; }
.deprecated-removed { @extend %note-red; }
.versionmodified { font-weight: bold; }
p > code, li > code { @extend %label; }
.admonition-title {
float: left;
margin: 0 .5em 0 0;
font-weight: bold;
&:after { content: ':'; }
}
.admonition > dl {
clear: left;
margin: 0;
}
ul.simple { margin: 1em 0; }
}

@ -0,0 +1,68 @@
module Docs
class Python
class CleanHtmlFilter < Filter
def call
@doc = at_css '.body > .section'
# Clean inline code elements
css('tt.literal').each do |node|
node.before(node.children).remove
end
css('tt', 'span.pre').each do |node|
node.name = 'code'
node.remove_attribute 'class'
end
root_page? ? root : other
doc
end
def root
at_css('h1').content = 'Python'
css('> p').remove
end
def other
css('.headerlink', 'hr').remove
# Clean headings
at_css('h1').tap do |node|
node.content = node.content.sub!(/\A[\d\.]+/) { |str| @levelRegexp = /\A#{str}/; '' }
end
css('h2', 'h3', 'h4').each do |node|
node.css('a').each do |link|
link.before(link.children).remove
end
node.child.content = node.child.content.sub @levelRegexp, ''
end
css('dt').each do |node|
node.content = node.content
end
# Remove blockquotes
css('blockquote').each do |node|
node.before(node.children).remove
end
# Remove code highlighting
css('.highlight-python3').each do |node|
pre = node.at_css('pre')
pre.content = pre.content
pre['class'] = 'python'
node.replace(pre)
end
# Remove <table> border attribute
css('table[border]').each do |node|
node.remove_attribute 'border'
end
end
end
end
end

@ -0,0 +1,82 @@
module Docs
class Python
class EntriesFilter < Docs::EntriesFilter
REPLACE_TYPES = {
'Cryptographic' => 'Cryptography',
'Custom Interpreters' => 'Interpreters',
'Data Compression & Archiving' => 'Data Compression',
'Generic Operating System' => 'Operating System',
'Graphical User Interfaces with Tk' => 'Tk',
'Internet Data Handling' => 'Internet Data',
'Internet Protocols & Support' => 'Internet',
'Interprocess Communication & Networking' => 'Networking',
'Program Frameworks' => 'Frameworks',
'Structured Markup Processing Tools' => 'Structured Markup' }
def get_name
name = at_css('h1').content
name.sub! %r{\A[\d\.]+ }, '' # remove list number
name.sub! %r{ \u{2014}.+\z}, '' # remove text after em dash
name
end
def get_type
return 'Logging' if slug.start_with? 'library/logging'
type = at_css('.related a[accesskey="U"]').content
if type == 'The Python Standard Library'
type = at_css('h1').content
elsif type.start_with? '19'
type = 'Internet Data Handling'
end
type.sub! %r{\A\d+\.\s+}, '' # remove list number
type.sub! "\u{00b6}", '' # remove paragraph character
type.sub! ' and ', ' & '
[' Services', ' Modules', ' Specific', 'Python '].each { |str| type.sub! str, '' }
REPLACE_TYPES[type] || type
end
def include_default_entry?
name !~ /[A-Z]/ && !skip? # skip non-module names
end
def additional_entries
return [] if root_page? || skip? || name == 'errno'
clean_id_attributes
entries = []
css('.class > dt[id]', '.exception > dt[id]', '.attribute > dt[id]').each do |node|
entries << [node['id'], node['id']]
end
css('.data > dt[id]').each do |node|
if node['id'].split('.').last.upcase! # skip constants
entries << [node['id'], node['id']]
end
end
css('.function > dt[id]', '.method > dt[id]', '.classmethod > dt[id]').each do |node|
entries << [node['id'] + '()', node['id']]
end
entries
end
def skip?
type == 'Language'
end
def clean_id_attributes
css('.section > .target[id]').each do |node|
if dt = node.at_css('+ dl > dt')
dt['id'] ||= node['id'].sub(/\w+\-/, '')
end
node.remove
end
end
end
end
end

@ -0,0 +1,27 @@
module Docs
class Python < FileScraper
self.version = '3.3.3'
self.type = 'sphinx'
self.dir = '/Users/Thibaut/DevDocs/Docs/Python' # downloaded from docs.python.org/3/download.html
self.base_url = 'http://docs.python.org/3/'
self.root_path = 'library/index.html'
html_filters.push 'python/entries', 'python/clean_html'
options[:only_patterns] = [/\Alibrary\//]
options[:skip] = %w(
library/2to3.html
library/formatter.html
library/index.html
library/intro.html
library/undoc.html
library/unittest.mock-examples.html
library/sunau.html)
options[:attribution] = <<-HTML
&copy; 1990&ndash;2013 Python Software Foundation<br>
Licensed under the PSF License.
HTML
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 547 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

@ -0,0 +1 @@
http://www.python.org/community/logos/
Loading…
Cancel
Save