History

Add Python 2 documentation

Thibaut committed 11 years ago

Commit 4849e681 parent 660cb1e4 files · +121 −1Browse files

Unified · Split

4 files
  1. assets/javascripts/templates/pages/news_tmpl.coffee +4 −1
  2. assets/stylesheets/global/_icons.scss +1 −0
  3. lib/docs/filters/python2/entries.rb +87 −0
  4. lib/docs/scrapers/python2.rb +29 −0
assets/javascripts/templates/pages/news_tmpl.coffee+4−1
@@ -33,7 +33,10 @@ newsItem = (date, news) -> · 32 unmodified lines
33 result33 result
34 34
35app.news = [35app.news = [
36 [ 1415491200000, # November 9, 201436 [ 1416096000000, # November 16, 2014
37 """ New <a href="/python2/">Python 2</a> documentation """
38 ], [
39 1415491200000, # November 9, 2014
37 """ New design40 """ New design
38 Feedback welcome on <a href="https://twitter.com/DevDocs" target="_blank">Twitter</a> and <a href="https://github.com/Thibaut/devdocs" target="_blank">GitHub</a>. """41 Feedback welcome on <a href="https://twitter.com/DevDocs" target="_blank">Twitter</a> and <a href="https://github.com/Thibaut/devdocs" target="_blank">GitHub</a>. """
39 ], [42 ], [
assets/stylesheets/global/_icons.scss+1−0
@@ -42,6 +42,7 @@ · 41 unmodified lines
42._icon-ruby:before { background-position: -3rem -5rem; }42._icon-ruby:before { background-position: -3rem -5rem; }
43._icon-rails:before { background-position: -4rem -5rem; }43._icon-rails:before { background-position: -4rem -5rem; }
44._icon-python:before { background-position: 0 -6rem; }44._icon-python:before { background-position: 0 -6rem; }
45._icon-python2:before { background-position: 0 -6rem; }
45._icon-git:before { background-position: -1rem -6rem; }46._icon-git:before { background-position: -1rem -6rem; }
46._icon-redis:before { background-position: -2rem -6rem; }47._icon-redis:before { background-position: -2rem -6rem; }
47._icon-postgresql:before { background-position: -3rem -6rem; }48._icon-postgresql:before { background-position: -3rem -6rem; }
lib/docs/filters/python2/entries.rb+87−0
@@ -0,0 +1,87 @@
1module Docs
2 class Python2
3 class EntriesFilter < Docs::EntriesFilter
4 REPLACE_TYPES = {
5 'compiler package' => 'Compiler',
6 'Cryptographic' => 'Cryptography',
7 'Custom Interpreters' => 'Interpreters',
8 'Data Compression & Archiving' => 'Data Compression',
9 'Generic Operating System' => 'Operating System',
10 'Graphical User Interfaces with Tk' => 'Tk',
11 'Internet Data Handling' => 'Internet Data',
12 'Internet Protocols & Support' => 'Internet',
13 'Interprocess Communication & Networking' => 'Networking',
14 'MacOSA' => 'Mac OS',
15 'Program Frameworks' => 'Frameworks',
16 'Structured Markup Processing Tools' => 'Structured Markup' }
17
18 def get_name
19 name = at_css('h1').content
20 name.remove! %r{\A[\d\.]+ } # remove list number
21 name.remove! "\u{00B6}" # remove pilcrow sign
22 name.remove! %r{ [\u{2013}\u{2014}].+\z} # remove text after em/en dash
23 name.remove! 'Built-in'
24 name.strip!
25 name
26 end
27
28 def get_type
29 return 'Logging' if slug.start_with? 'library/logging'
30
31 type = at_css('.related a[accesskey="U"]').content
32
33 if type == 'The Python Standard Library'
34 type = at_css('h1').content
35 elsif type.include?('I/O') || %w(select selectors).include?(name)
36 type = 'Input/ouput'
37 elsif type.start_with? '18'
38 type = 'Internet Data Handling'
39 elsif type.include? 'Mac'
40 type = 'Mac OS'
41 end
42
43 type.remove! %r{\A\d+\.\s+} # remove list number
44 type.remove! "\u{00b6}" # remove paragraph character
45 type.sub! ' and ', ' & '
46 [' Services', ' Modules', ' Specific', 'Python '].each { |str| type.remove!(str) }
47
48 REPLACE_TYPES[type] || type
49 end
50
51 def include_default_entry?
52 !at_css('.body > .section:only-child > .toctree-wrapper:last-child') && !type.in?(%w(Language Superseded SunOS))
53 end
54
55 def additional_entries
56 return [] if root_page? || !include_default_entry? || name == 'errno'
57 clean_id_attributes
58 entries = []
59
60 css('.class > dt[id]', '.exception > dt[id]', '.attribute > dt[id]').each do |node|
61 entries << [node['id'], node['id']]
62 end
63
64 css('.data > dt[id]').each do |node|
65 if node['id'].split('.').last.upcase! # skip constants
66 entries << [node['id'], node['id']]
67 end
68 end
69
70 css('.function > dt[id]', '.method > dt[id]', '.classmethod > dt[id]').each do |node|
71 entries << [node['id'] + '()', node['id']]
72 end
73
74 entries
75 end
76
77 def clean_id_attributes
78 css('.section > .target[id]').each do |node|
79 if dt = node.at_css('+ dl > dt')
80 dt['id'] ||= node['id'].remove(/\w+\-/)
81 end
82 node.remove
83 end
84 end
85 end
86 end
87end
lib/docs/scrapers/python2.rb+29−0
@@ -0,0 +1,29 @@
1module Docs
2 class Python2 < FileScraper
3 self.name = 'Python 2'
4 self.slug = 'python2'
5 self.version = '2.7.8'
6 self.type = 'sphinx'
7 self.dir = '/Users/Thibaut/DevDocs/Docs/Python2' # downloaded from docs.python.org/2.7/download.html
8 self.base_url = 'http://docs.python.org/2.7/'
9 self.root_path = 'library/index.html'
10
11 html_filters.push 'python2/entries', 'python/clean_html'
12
13 options[:only_patterns] = [/\Alibrary\//]
14
15 options[:skip] = %w(
16 library/2to3.html
17 library/formatter.html
18 library/index.html
19 library/intro.html
20 library/undoc.html
21 library/unittest.mock-examples.html
22 library/sunau.html)
23
24 options[:attribution] = <<-HTML
25 &copy; 1990&ndash;2014 Python Software Foundation<br>
26 Licensed under the PSF License.
27 HTML
28 end
29end