History

Add Python documentation

Thibaut committed 12 years ago

Commit 36d6a101 parent 587855115 files · +220 −0Browse files

Unified · Split

15 files
  1. assets/images/icons.png +0 −0
  2. assets/images/icons@2x.png +0 −0
  3. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  4. assets/javascripts/templates/pages/news_tmpl.coffee +6 −2
  5. assets/javascripts/views/pages/sphinx.coffee +6 −0
  6. assets/stylesheets/application.css.scss +1 −0
  7. assets/stylesheets/components/_content.scss +0 −1
  8. assets/stylesheets/global/_icons.scss +2 −1
  9. assets/stylesheets/pages/_sphinx.scss +26 −0
  10. lib/docs/filters/python/clean_html.rb +68 −0
  11. lib/docs/filters/python/entries.rb +82 −0
  12. lib/docs/scrapers/python.rb +27 −0
  13. public/icons/docs/python/16.png +0 −0
  14. public/icons/docs/python/16@2x.png +0 −0
  15. public/icons/docs/python/SOURCE +1 −0
assets/images/icons.png+0−0

Binary file not shown.

assets/images/icons@2x.png+0−0

Binary file not shown.

assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -138,6 +138,11 @@ credits = [ · 137 unmodified lines
138138 '1997-2013 The PHP Documentation Group',
139139 'CC BY',
140140 'http://creativecommons.org/licenses/by/3.0/'
141+ ], [
142+ 'Python',
143+ '1990-2013 Python Software Foundation<br>Python is a trademark of the Python Software Foundation.',
144+ 'PSFL',
145+ 'http://docs.python.org/3/license.html'
141146 ], [
142147 'Ruby',
143148 '1993-2013 Yukihiro Matsumoto',
assets/javascripts/templates/pages/news_tmpl.coffee+6−2
@@ -24,7 +24,10 @@ newsItem = (date, news) -> · 23 unmodified lines
2424 result
2525
2626 app.news = [
27− [ 1384819200000, # November 19, 2013
27+ [ 1385424000000, # November 26, 2013
28+ """ New <a href="/python/">Python</a> documentation """
29+ ], [
30+ 1384819200000, # November 19, 2013
2831 """ New <a href="/rails/">Ruby on Rails</a> documentation """
2932 ], [
3033 1384560000000, # November 16, 2013
@@ -35,7 +38,8 @@ app.news = [ · 4 unmodified lines
3538 ], [
3639 1381276800000, # October 9, 2013
3740 """ DevDocs is now available as a <a href="https://chrome.google.com/webstore/detail/devdocs/mnfehgbmkapmjnhcnbodoamcioleeooe">Chrome web app</a>. """
38− ], [ 1379808000000, # September 22, 2013
41+ ], [
42+ 1379808000000, # September 22, 2013
3943 """ New <a href="/php/">PHP</a> documentation """
4044 ], [
4145 1378425600000, # September 6, 2013
assets/javascripts/views/pages/sphinx.coffee+6−0
@@ -0,0 +1,6 @@
1+#= require views/pages/base
2+
3+class app.views.SphinxPage extends app.views.BasePage
4+ afterRender: ->
5+ @highlightCode @findAll('pre.python'), 'python'
6+ return
assets/stylesheets/application.css.scss+1−0
@@ -38,5 +38,6 @@ · 37 unmodified lines
3838 'pages/php',
3939 'pages/rdoc',
4040 'pages/rfc',
41+ 'pages/sphinx',
4142 'pages/underscore',
4243 'pages/yard';
assets/stylesheets/components/_content.scss+0−1
@@ -153,7 +153,6 @@ · 152 unmodified lines
153153 %lined-heading {
154154 white-space: nowrap;
155155 overflow: hidden;
156− overflow-wrap: normal;
157156 word-wrap: normal;
158157
159158 &:after {
assets/stylesheets/global/_icons.scss+2−1
@@ -4,7 +4,7 @@ · 3 unmodified lines
44 width: 1rem;
55 height: 1rem;
66 background-image: image-url('icons.png');
7− background-size: 5rem 6rem;
7+ background-size: 5rem 7rem;
88 }
99
1010 @media (-webkit-min-device-pixel-ratio: 1.5), (min-resolution: 144dpi) {
@@ -41,3 +41,4 @@ · 30 unmodified lines
4141 ._icon-php:before { background-position: -2rem -5rem; }
4242 ._icon-ruby:before { background-position: -3rem -5rem; }
4343 ._icon-rails:before { background-position: -4rem -5rem; }
44+._icon-python:before { background-position: 0 -6rem; }
assets/stylesheets/pages/_sphinx.scss+26−0
@@ -0,0 +1,26 @@
1+._sphinx {
2+ h2, h3 { @extend %block-heading; }
3+ dl:not(.docutils) > dt { @extend %block-label, %label-blue; }
4+ dt + dt { margin-top: -.5em; }
5+
6+ .note, .admonition, .versionadded, .versionchanged, .deprecated-removed { @extend %note; }
7+ .deprecated-removed { @extend %note-red; }
8+ .versionmodified { font-weight: bold; }
9+
10+ p > code, li > code { @extend %label; }
11+
12+ .admonition-title {
13+ float: left;
14+ margin: 0 .5em 0 0;
15+ font-weight: bold;
16+
17+ &:after { content: ':'; }
18+ }
19+
20+ .admonition > dl {
21+ clear: left;
22+ margin: 0;
23+ }
24+
25+ ul.simple { margin: 1em 0; }
26+}
lib/docs/filters/python/clean_html.rb+68−0
@@ -0,0 +1,68 @@
1+module Docs
2+ class Python
3+ class CleanHtmlFilter < Filter
4+ def call
5+ @doc = at_css '.body > .section'
6+
7+ # Clean inline code elements
8+
9+ css('tt.literal').each do |node|
10+ node.before(node.children).remove
11+ end
12+
13+ css('tt', 'span.pre').each do |node|
14+ node.name = 'code'
15+ node.remove_attribute 'class'
16+ end
17+
18+ root_page? ? root : other
19+
20+ doc
21+ end
22+
23+ def root
24+ at_css('h1').content = 'Python'
25+ css('> p').remove
26+ end
27+
28+ def other
29+ css('.headerlink', 'hr').remove
30+
31+ # Clean headings
32+
33+ at_css('h1').tap do |node|
34+ node.content = node.content.sub!(/\A[\d\.]+/) { |str| @levelRegexp = /\A#{str}/; '' }
35+ end
36+
37+ css('h2', 'h3', 'h4').each do |node|
38+ node.css('a').each do |link|
39+ link.before(link.children).remove
40+ end
41+ node.child.content = node.child.content.sub @levelRegexp, ''
42+ end
43+
44+ css('dt').each do |node|
45+ node.content = node.content
46+ end
47+
48+ # Remove blockquotes
49+ css('blockquote').each do |node|
50+ node.before(node.children).remove
51+ end
52+
53+ # Remove code highlighting
54+ css('.highlight-python3').each do |node|
55+ pre = node.at_css('pre')
56+ pre.content = pre.content
57+ pre['class'] = 'python'
58+ node.replace(pre)
59+ end
60+
61+ # Remove <table> border attribute
62+ css('table[border]').each do |node|
63+ node.remove_attribute 'border'
64+ end
65+ end
66+ end
67+ end
68+end
lib/docs/filters/python/entries.rb+82−0
@@ -0,0 +1,82 @@
1+module Docs
2+ class Python
3+ class EntriesFilter < Docs::EntriesFilter
4+ REPLACE_TYPES = {
5+ 'Cryptographic' => 'Cryptography',
6+ 'Custom Interpreters' => 'Interpreters',
7+ 'Data Compression & Archiving' => 'Data Compression',
8+ 'Generic Operating System' => 'Operating System',
9+ 'Graphical User Interfaces with Tk' => 'Tk',
10+ 'Internet Data Handling' => 'Internet Data',
11+ 'Internet Protocols & Support' => 'Internet',
12+ 'Interprocess Communication & Networking' => 'Networking',
13+ 'Program Frameworks' => 'Frameworks',
14+ 'Structured Markup Processing Tools' => 'Structured Markup' }
15+
16+ def get_name
17+ name = at_css('h1').content
18+ name.sub! %r{\A[\d\.]+ }, '' # remove list number
19+ name.sub! %r{ \u{2014}.+\z}, '' # remove text after em dash
20+ name
21+ end
22+
23+ def get_type
24+ return 'Logging' if slug.start_with? 'library/logging'
25+
26+ type = at_css('.related a[accesskey="U"]').content
27+
28+ if type == 'The Python Standard Library'
29+ type = at_css('h1').content
30+ elsif type.start_with? '19'
31+ type = 'Internet Data Handling'
32+ end
33+
34+ type.sub! %r{\A\d+\.\s+}, '' # remove list number
35+ type.sub! "\u{00b6}", '' # remove paragraph character
36+ type.sub! ' and ', ' & '
37+ [' Services', ' Modules', ' Specific', 'Python '].each { |str| type.sub! str, '' }
38+
39+ REPLACE_TYPES[type] || type
40+ end
41+
42+ def include_default_entry?
43+ name !~ /[A-Z]/ && !skip? # skip non-module names
44+ end
45+
46+ def additional_entries
47+ return [] if root_page? || skip? || name == 'errno'
48+ clean_id_attributes
49+ entries = []
50+
51+ css('.class > dt[id]', '.exception > dt[id]', '.attribute > dt[id]').each do |node|
52+ entries << [node['id'], node['id']]
53+ end
54+
55+ css('.data > dt[id]').each do |node|
56+ if node['id'].split('.').last.upcase! # skip constants
57+ entries << [node['id'], node['id']]
58+ end
59+ end
60+
61+ css('.function > dt[id]', '.method > dt[id]', '.classmethod > dt[id]').each do |node|
62+ entries << [node['id'] + '()', node['id']]
63+ end
64+
65+ entries
66+ end
67+
68+ def skip?
69+ type == 'Language'
70+ end
71+
72+ def clean_id_attributes
73+ css('.section > .target[id]').each do |node|
74+ if dt = node.at_css('+ dl > dt')
75+ dt['id'] ||= node['id'].sub(/\w+\-/, '')
76+ end
77+ node.remove
78+ end
79+ end
80+ end
81+ end
82+end
lib/docs/scrapers/python.rb+27−0
@@ -0,0 +1,27 @@
1+module Docs
2+ class Python < FileScraper
3+ self.version = '3.3.3'
4+ self.type = 'sphinx'
5+ self.dir = '/Users/Thibaut/DevDocs/Docs/Python' # downloaded from docs.python.org/3/download.html
6+ self.base_url = 'http://docs.python.org/3/'
7+ self.root_path = 'library/index.html'
8+
9+ html_filters.push 'python/entries', 'python/clean_html'
10+
11+ options[:only_patterns] = [/\Alibrary\//]
12+
13+ options[:skip] = %w(
14+ library/2to3.html
15+ library/formatter.html
16+ library/index.html
17+ library/intro.html
18+ library/undoc.html
19+ library/unittest.mock-examples.html
20+ library/sunau.html)
21+
22+ options[:attribution] = <<-HTML
23+ &copy; 1990&ndash;2013 Python Software Foundation<br>
24+ Licensed under the PSF License.
25+ HTML
26+ end
27+end
public/icons/docs/python/16.png+0−0

Binary file not shown.

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

Binary file not shown.

public/icons/docs/python/SOURCE+1−0
@@ -0,0 +1 @@
1+http://www.python.org/community/logos/