mirror of https://github.com/freeCodeCamp/devdocs
parent
83e8f5e8d3
commit
4d853c57f9
Before Width: | Height: | Size: 28 KiB After Width: | Height: | Size: 28 KiB |
Before Width: | Height: | Size: 75 KiB After Width: | Height: | Size: 76 KiB |
@ -0,0 +1,6 @@
|
||||
#= require views/pages/base
|
||||
|
||||
class app.views.RustPage extends app.views.BasePage
|
||||
afterRender: ->
|
||||
@highlightCode @findAll('pre.rust'), 'rust'
|
||||
return
|
@ -0,0 +1,10 @@
|
||||
._rust {
|
||||
@extend %simple;
|
||||
|
||||
h4 { @extend %block-label; }
|
||||
.docblock { margin-left: 1em; }
|
||||
|
||||
div.stability { margin-bottom: 1em; }
|
||||
em.stab, span.stab { @extend %label; }
|
||||
em.stab.unstable, span.stab.unstable { @extend %label-orange; }
|
||||
}
|
@ -0,0 +1,63 @@
|
||||
module Docs
|
||||
class Rust
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
if slug.start_with?('book')
|
||||
book
|
||||
elsif slug.start_with?('reference')
|
||||
reference
|
||||
else
|
||||
api
|
||||
end
|
||||
|
||||
css('.rusttest', 'hr').remove
|
||||
|
||||
css('.docblock > h1').each { |node| node.name = 'h4' }
|
||||
css('h2.section-header').each { |node| node.name = 'h3' }
|
||||
css('h1.section-header').each { |node| node.name = 'h2' }
|
||||
|
||||
css('> .impl-items', '> .docblock').each do |node|
|
||||
node.before(node.children).remove
|
||||
end
|
||||
|
||||
css('h1 > a', 'h2 > a', 'h3 > a', 'h4 > a', 'h5 > a').each do |node|
|
||||
node.before(node.children).remove
|
||||
end
|
||||
|
||||
css('pre > code').each do |node|
|
||||
node.parent['class'] = node['class']
|
||||
node.before(node.children).remove
|
||||
end
|
||||
|
||||
css('pre').each do |node|
|
||||
node.content = node.content
|
||||
end
|
||||
|
||||
doc
|
||||
end
|
||||
|
||||
def book
|
||||
@doc = at_css('#page')
|
||||
end
|
||||
|
||||
def reference
|
||||
css('#versioninfo').remove
|
||||
end
|
||||
|
||||
def api
|
||||
@doc = at_css('#main')
|
||||
|
||||
css('.toggle-wrapper').remove
|
||||
|
||||
css('h1.fqn').each do |node|
|
||||
node.content = node.at_css('.in-band').content
|
||||
end
|
||||
|
||||
css('.stability .stab').each do |node|
|
||||
node.name = 'span'
|
||||
node.content = node.content
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,56 @@
|
||||
module Docs
|
||||
class Rust
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
def get_name
|
||||
if slug.start_with?('book')
|
||||
at_css("#toc a[href='#{File.basename(slug)}']").content
|
||||
elsif slug.start_with?('reference')
|
||||
'Reference'
|
||||
else
|
||||
name = at_css('h1.fqn .in-band').content.remove(/\A.+\s/)
|
||||
mod = slug.split('/').first
|
||||
name.prepend("#{mod}::") unless name.start_with?(mod)
|
||||
name
|
||||
end
|
||||
end
|
||||
|
||||
PRIMITIVE_SLUG = /\A(\w+)\/(primitive)\./
|
||||
|
||||
def get_type
|
||||
if slug.start_with?('book')
|
||||
'Guide'
|
||||
elsif slug.start_with?('reference')
|
||||
'Reference'
|
||||
else
|
||||
path = name.split('::')
|
||||
heading = at_css('h1.fqn .in-band').content.strip
|
||||
if path.length > 2 || (path.length == 2 && (heading.start_with?('Module') || heading.start_with?('Primitive')))
|
||||
path[0..1].join('::')
|
||||
else
|
||||
path[0]
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def additional_entries
|
||||
if slug.start_with?('book')
|
||||
[]
|
||||
elsif slug.start_with?('reference')
|
||||
css('#TOC > ul > li > a', '#TOC > ul > li > ul > li > a').map do |node|
|
||||
name = node.content
|
||||
name.sub! %r{(\d)\ }, '\1. '
|
||||
name.sub! '10.0.', '10.'
|
||||
id = node['href'].remove('#')
|
||||
[name, id]
|
||||
end
|
||||
else
|
||||
css('#methods + * + div > .method', '#required-methods + div > .method', '#provided-methods + div > .method').map do |node|
|
||||
name = node.at_css('.fnname').content
|
||||
name.prepend "#{self.name}::"
|
||||
[name, node['id']]
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
@ -0,0 +1,48 @@
|
||||
module Docs
|
||||
class Rust < UrlScraper
|
||||
self.type = 'rust'
|
||||
self.version = '1.0.0'
|
||||
self.base_url = 'http://doc.rust-lang.org/'
|
||||
self.root_path = 'book/index.html'
|
||||
self.initial_paths = %w(
|
||||
reference.html
|
||||
collections/index.html
|
||||
std/index.html
|
||||
unicode/index.html)
|
||||
self.links = {
|
||||
home: 'http://www.rust-lang.org/',
|
||||
code: 'https://github.com/rust-lang/rust'
|
||||
}
|
||||
|
||||
html_filters.push 'rust/entries', 'rust/clean_html'
|
||||
|
||||
options[:only_patterns] = [
|
||||
/\Abook\//,
|
||||
/\Acollections\//,
|
||||
/\Astd\//,
|
||||
/\Aunicode\// ]
|
||||
|
||||
options[:skip] = %w(book/README.html)
|
||||
options[:skip_patterns] = [/(?<!\.html)\z/]
|
||||
|
||||
options[:fix_urls] = ->(url) do
|
||||
url.sub! %r{(#{Rust.base_url}.+/)\z}, '\1index.html'
|
||||
url.sub! '/unicode/u_str', '/unicode/str/'
|
||||
url
|
||||
end
|
||||
|
||||
options[:attribution] = <<-HTML
|
||||
© 2011-2015 The Rust Project Developers<br>
|
||||
Licensed under the Apache License, Version 2.0 or the MIT license, at your option.
|
||||
HTML
|
||||
|
||||
private
|
||||
|
||||
REDIRECT_RGX = /http-equiv="refresh"/i
|
||||
NOT_FOUND_RGX = /<title>Not Found<\/title>/
|
||||
|
||||
def process_response?(response)
|
||||
!(response.body =~ REDIRECT_RGX || response.body =~ NOT_FOUND_RGX || response.body.blank?)
|
||||
end
|
||||
end
|
||||
end
|
After Width: | Height: | Size: 333 B |
After Width: | Height: | Size: 617 B |
@ -0,0 +1 @@
|
||||
https://github.com/rust-lang/rust-www/tree/8347e870e3b09824ef9137fa9146ef7d21fec3d6/logos
|
Loading…
Reference in new issue