Thibaut 12 роки тому
батько
коміт
36d6a109dc

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


+ 5 - 0
assets/javascripts/templates/pages/about_tmpl.coffee

@@ -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',

+ 6 - 2
assets/javascripts/templates/pages/news_tmpl.coffee

@@ -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

+ 6 - 0
assets/javascripts/views/pages/sphinx.coffee

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

+ 1 - 0
assets/stylesheets/application.css.scss

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

+ 0 - 1
assets/stylesheets/components/_content.scss

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

+ 2 - 1
assets/stylesheets/global/_icons.scss

@@ -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; }

+ 26 - 0
assets/stylesheets/pages/_sphinx.scss

@@ -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; }
+}

+ 68 - 0
lib/docs/filters/python/clean_html.rb

@@ -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

+ 82 - 0
lib/docs/filters/python/entries.rb

@@ -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

+ 27 - 0
lib/docs/scrapers/python.rb

@@ -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

BIN
public/icons/docs/python/16.png


BIN
public/icons/docs/python/16@2x.png


+ 1 - 0
public/icons/docs/python/SOURCE

@@ -0,0 +1 @@
+http://www.python.org/community/logos/