Kaynağa Gözat

Add Django documentation

Thibaut 11 yıl önce
ebeveyn
işleme
6bbf267b6e

BIN
assets/images/icons.png


BIN
assets/images/icons@2x.png


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

@@ -117,6 +117,11 @@ credits = [
     '2014 Michael Bostock',
     'BSD',
     'https://raw.github.com/mbostock/d3/master/LICENSE'
+  ], [
+    'Django',
+    'Django Software Foundation and individual contributors',
+    'BSD',
+    'https://raw.githubusercontent.com/django/django/master/LICENSE'
   ], [
     'Ember.js',
     '2014 Yehuda Katz, Tom Dale and Ember.js contributors',

+ 4 - 1
assets/javascripts/templates/pages/news_tmpl.coffee

@@ -32,7 +32,10 @@ newsItem = (date, news) ->
   result
 
 app.news = [
-  [ 1406419200000, # July 27, 2014
+  [ 1407110400000, # August 4, 2014
+    """ New <a href="/django/">Django</a> documentation """,
+  ], [
+    1406419200000, # July 27, 2014
     """ New <a href="/markdown/">Markdown</a> documentation """,
   ], [
     1404518400000, # July 5, 2014

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

@@ -3,4 +3,5 @@
 class app.views.SphinxPage extends app.views.BasePage
   afterRender: ->
     @highlightCode @findAll('pre.python'), 'python'
+    @highlightCode @findAll('pre.markup'), 'markup'
     return

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

@@ -63,3 +63,4 @@
 ._icon-sinon:before         { background-position: -4rem -9rem; }
 ._icon-cordova:before       { background-position: 0 -10rem; }
 ._icon-markdown:before      { background-position: -1rem -10rem; }
+._icon-django:before        { background-position: -2rem -10rem; }

+ 42 - 0
lib/docs/filters/django/clean_html.rb

@@ -0,0 +1,42 @@
+module Docs
+  class Django
+    class CleanHtmlFilter < Filter
+      def call
+        @doc = at_css('.yui-g')
+
+        css('.section', 'a > em').each do |node|
+          node.before(node.children).remove
+        end
+
+        css('tt', 'span.pre').each do |node|
+          node.name = 'code'
+          node.content = node.content
+          node.remove_attribute 'class'
+        end
+
+        css('.headerlink').each do |node|
+          id = node['href'][1..-1]
+          node.parent['id'] ||= id
+          doc.at_css("span##{id}").try(:remove)
+          node.remove
+        end
+
+        css('h1', 'h2', 'h3', 'dt').each do |node|
+          node.content = node.content
+        end
+
+        css('div[class^="highlight-"]').each do |node|
+          node.name = 'pre'
+          node['class'] = case node['class']
+            when 'highlight-python' then 'python'
+            when 'highlight-html+django' then 'markup'
+            else ''
+          end
+          node.content = node.at_css('pre').content
+        end
+
+        doc
+      end
+    end
+  end
+end

+ 46 - 0
lib/docs/filters/django/entries.rb

@@ -0,0 +1,46 @@
+module Docs
+  class Django
+    class EntriesFilter < Docs::EntriesFilter
+      def get_name
+        at_css('h1').content.remove("\u{00b6}")
+      end
+
+      def get_type
+        case subpath
+        when /\Atopics/
+          'Guides'
+        when /\Aintro/
+          'Guides: Intro'
+        when /\Ahowto/
+          'Guides: How-tos'
+        when /\Aref/
+          'API'
+        end
+      end
+
+      def additional_entries
+        entries = []
+
+        css('dl.function', 'dl.class', 'dl.method', 'dl.attribute').each do |node|
+          next unless id = node.at_css('dt')['id']
+          next unless name = id.dup.sub!('django.', '')
+
+          path = name.split('.')
+          type = "django.#{path.first}"
+          type << ".#{path.second}" if %w(contrib db).include?(path.first)
+
+          name.remove! 'contrib.'
+          name << '()' if node['class'].include?('method') || node['class'].include?('function')
+
+          entries << [name, id, type]
+        end
+
+        entries
+      end
+
+      def include_default_entry?
+        at_css('#sidebar a[href="index"]')
+      end
+    end
+  end
+end

+ 10 - 0
lib/docs/filters/django/fix_urls.rb

@@ -0,0 +1,10 @@
+module Docs
+  class Django
+    class FixUrlsFilter < Filter
+      def call
+        html.gsub! %r{#{Regexp.escape(Django.base_url)}([^"']+?)\.html}, "#{Django.base_url}\\1/"
+        html
+      end
+    end
+  end
+end

+ 36 - 0
lib/docs/scrapers/django.rb

@@ -0,0 +1,36 @@
+module Docs
+  class Django < FileScraper
+    self.name = 'Django'
+    self.type = 'sphinx'
+    self.version = '1.6.6'
+    self.dir = '/Users/Thibaut/DevDocs/Docs/Django'
+    self.base_url = 'https://docs.djangoproject.com/en/1.6/'
+    self.root_path = 'index.html'
+
+    html_filters.push 'django/entries', 'django/clean_html'
+    text_filters.push 'django/fix_urls'
+
+    options[:container] = '#bd'
+
+    options[:skip] = %w(
+      contents.html
+      genindex.html
+      py-modindex.html
+      glossary.html
+      search.html
+      intro/whatsnext.html)
+
+    options[:skip_patterns] = [
+      /\Afaq\//,
+      /\Ainternals\//,
+      /\Amisc\//,
+      /\Areleases\//,
+      /\A_/,
+      /flattened\-index\.html/]
+
+    options[:attribution] = <<-HTML
+      &copy; Django Software Foundation and individual contributors<br>
+      Licensed under the BSD License.
+    HTML
+  end
+end

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


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


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

@@ -0,0 +1 @@
+https://github.com/django/djangoproject.com/raw/master/static/favicon.ico