mirror of https://github.com/freeCodeCamp/devdocs
parent
5878551f5e
commit
36d6a109dc
Before Width: | Height: | Size: 11 KiB After Width: | Height: | Size: 11 KiB |
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 30 KiB |
@ -0,0 +1,6 @@
|
||||
#= require views/pages/base
|
||||
|
||||
class app.views.SphinxPage extends app.views.BasePage
|
||||
afterRender: ->
|
||||
@highlightCode @findAll('pre.python'), 'python'
|
||||
return
|
@ -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
|
||||
© 1990–2013 Python Software Foundation<br>
|
||||
Licensed under the PSF License.
|
||||
HTML
|
||||
end
|
||||
end
|
After Width: | Height: | Size: 547 B |
After Width: | Height: | Size: 1.3 KiB |
@ -0,0 +1 @@
|
||||
http://www.python.org/community/logos/
|
Loading…
Reference in new issue