Add RDoc scraper and Ruby documentation

pull/15/head
Thibaut 11 years ago
parent f5eb547900
commit 3093104dc2

Binary file not shown.

Before

Width:  |  Height:  |  Size: 9.1 KiB

After

Width:  |  Height:  |  Size: 10 KiB

Binary file not shown.

Before

Width:  |  Height:  |  Size: 23 KiB

After

Width:  |  Height:  |  Size: 26 KiB

@ -138,6 +138,11 @@ credits = [
'1997-2013 The PHP Documentation Group',
'CC BY',
'http://creativecommons.org/licenses/by/3.0/'
], [
'Ruby',
'1993-2013 Yukihiro Matsumoto',
'Ruby',
'https://www.ruby-lang.org/en/about/license.txt'
], [
'Sass',
'2006-2013 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein',

@ -24,7 +24,10 @@ newsItem = (date, news) ->
result
app.news = [
[ 1382572800000, # October 24, 2013
[ 1384560000000, # November 16, 2013
""" New <a href="/ruby/">Ruby</a> documentation """
], [
1382572800000, # October 24, 2013
""" DevDocs is now <a href="https://github.com/Thibaut/devdocs">open source</a>. """
], [
1381276800000, # October 9, 2013

@ -0,0 +1,20 @@
#= require views/pages/base
class app.views.RdocPage extends app.views.BasePage
@events:
click: 'onClick'
afterRender: ->
@highlightCode @findAll('pre.ruby'), 'ruby'
@highlightCode @findAll('pre.c'), 'clike'
return
onClick: (event) ->
return unless event.target.classList.contains 'method-click-advice'
$.stopEvent(event)
source = $ '.method-source-code', event.target.parentNode.parentNode
isShown = source.style.display is 'block'
source.style.display = if isShown then 'none' else 'block'
event.target.textContent = if isShown then 'Show source' else 'Hide source'

@ -36,6 +36,7 @@
'pages/mdn',
'pages/node',
'pages/php',
'pages/rdoc',
'pages/rfc',
'pages/underscore',
'pages/yard';

@ -39,3 +39,4 @@
._icon-jquerymobile:before { background-position: 0 -5rem; }
._icon-lodash:before { background-position: -1rem -5rem; }
._icon-php:before { background-position: -2rem -5rem; }
._icon-ruby:before { background-position: -3rem -5rem; }

@ -0,0 +1,46 @@
._rdoc {
> .description, > .documentation-section { padding-left: 1rem; }
> .description > h2, .section-header { @extend %block-heading; }
> .description > h2, .section-header, .method-heading { margin-left: -1rem; }
.description > h1 { font-size: 1rem; }
.method-description > h2, h3, h4 { font-size: 1em; }
.method-heading {
font-weight: bold;
@extend %block-label, %label-blue;
+ .method-heading { margin-top: -.5em; }
}
> .meta {
@extend %note, %note-blue;
> dd { margin: 0; }
> dd + dt { margin-top: .5em; }
}
a.method-click-advice {
float: right;
font-size: .75rem;
color: $linkColor;
cursor: pointer;
@extend %user-select-none;
&:hover { text-decoration: underline; }
}
.method-description { position: relative; }
.method-source-code {
display: none;
position: absolute;
z-index: 1;
top: 0;
left: -1em;
right: 0;
background: rgba(white, .95);
box-shadow: 0 1em 1em 1em white;
> pre { margin: 0; }
}
}

@ -0,0 +1,49 @@
module Docs
class Rdoc
class CleanHtmlFilter < Filter
def call
root_page? ? root : other
doc
end
def root
at_css('.section-header').remove
# Remove skipped items
css('li > span').each do |node|
node.parent.remove
end
end
def other
css('hr').remove
# Remove paragraph/up links
css('h1 > span', 'h2 > span', 'h3 > span', 'h4 > span').remove
# Move id attributes to headings
css('.method-detail').each do |node|
next unless heading = node.at_css('.method-heading')
heading['id'] = node['id']
node.remove_attribute 'id'
end
# Convert "click to toggle source" into a link
css('.method-click-advice').each do |node|
node.name = 'a'
node.content = 'Show source'
end
# Add class to differentiate Ruby code from C code
css('.method-source-code > pre').each do |node|
node['class'] = node.at_css('.ruby-keyword') ? 'ruby' : 'c'
end
# Remove code highlighting
css('pre').each do |node|
node.content = node.content
end
end
end
end
end

@ -0,0 +1,26 @@
module Docs
class Rdoc
class ContainerFilter < Filter
def call
if root_page?
at_css '#classindex-section'
else
container = at_css '#documentation'
# Add <dl> mentioning parent class and included modules
meta = Nokogiri::XML::Node.new 'dl', doc
meta['class'] = 'meta'
if parent = at_css('#parent-class-section')
meta << %(<dt>Parent:</dt><dd class="meta-parent">#{parent.at_css('.link').inner_html}</dd>)
end
if includes = at_css('#includes-section')
meta << %(<dt>Included modules:</dt><dd class="meta-includes">#{includes.css('a').map(&:to_html).join(', ')}</dd>)
end
container.at_css('h1').after(meta)
container
end
end
end
end
end

@ -0,0 +1,38 @@
module Docs
class Rdoc
class EntriesFilter < Docs::EntriesFilter
def get_name
name = at_css('h1').content.strip
name.sub! 'class ', ''
name.sub! 'module ', ''
name
end
def get_type
type = name.dup
unless type.sub! %r{::.*\z}, ''
parent = at_css('.meta-parent').try(:content).to_s.strip
return 'Errors' if type.end_with?('Error') || parent.end_with?('Error') || parent.end_with?('Exception')
end
type
end
def additional_entries
return [] if root_page?
require 'cgi'
css('.method-detail').map do |node|
name = node['id'].dup
name.sub! %r{\A\w+?\-.}, ''
name.sub! %r{\A-(?!\d)}, ''
name.gsub! '-', '%'
name = CGI.unescape(name)
name.prepend self.name + (node['id'] =~ /\A\w+-c-/ ? '::' : '#')
[name, node['id']]
end
end
end
end
end

@ -0,0 +1,52 @@
module Docs
class Ruby
class EntriesFilter < Docs::Rdoc::EntriesFilter
REPLACE_TYPE = {
'ACL' => 'DRb',
'Addrinfo' => 'Socket',
'BigMath' => 'BigDecimal',
'CMath' => 'Math',
'ConditionVariable' => 'Mutex',
'DEBUGGER__' => 'Debug',
'Errno' => 'Errors',
'FileTest' => 'File',
'Jacobian' => 'BigDecimal',
'LUSolve' => 'BigDecimal',
'Newton' => 'BigDecimal',
'PP' => 'PrettyPrint',
'Profiler__' => 'Profiler',
'Psych' => 'YAML',
'Rinda' => 'DRb',
'SortedSet' => 'Set',
'TCPServer' => 'Socket',
'TempIO' => 'Tempfile',
'ThWait' => 'Thread',
'UNIXServer' => 'Socket' }
REPLACE_TYPE_STARTS_WITH = {
'Monitor' => 'Monitor',
'Mutex' => 'Mutex',
'Shell' => 'Shell',
'Sync' => 'Sync',
'Thread' => 'Thread' }
REPLACE_TYPE_ENDS_WITH = {
'Queue' => 'Queue',
'Socket' => 'Socket' }
def get_type
type = super
REPLACE_TYPE_STARTS_WITH.each_pair do |key, value|
return value if type.start_with?(key)
end
REPLACE_TYPE_ENDS_WITH.each_pair do |key, value|
return value if type.end_with?(key)
end
REPLACE_TYPE[type] || type
end
end
end
end

@ -0,0 +1,13 @@
module Docs
class Rdoc < FileScraper
self.abstract = true
self.type = 'rdoc'
self.root_path = 'index.html'
html_filters.replace 'container', 'rdoc/container'
html_filters.push 'rdoc/entries', 'rdoc/clean_html', 'title'
options[:title] = false
options[:skip] = %w(table_of_contents.html)
end
end

@ -0,0 +1,85 @@
module Docs
class Ruby < Rdoc
# Generated with:
# rdoc \
# --format=darkfish \
# --no-line-numbers \
# --op=rdoc \
# --visibility=public \
# *.c \
# lib/**/*.rb \
# lib/*.rb \
# ext/bigdecimal/*.c \
# ext/bigdecimal/lib/*.rb \
# ext/bigdecimal/lib/**/*.rb \
# ext/date/*.c \
# ext/date/lib/*.rb \
# ext/date/lib/**/*.rb \
# ext/digest/*.c \
# ext/digest/**/*.c \
# ext/digest/**/*.rb \
# ext/json/lib/**/*.rb \
# ext/pathname/*.c \
# ext/pathname/lib/*.rb \
# ext/psych/*.c \
# ext/psych/lib/*.rb \
# ext/psych/lib/**/*.rb \
# ext/readline/*.c \
# ext/ripper/*.c \
# ext/ripper/lib/*.rb \
# ext/ripper/lib/**/*.rb \
# ext/socket/*.c \
# ext/socket/lib/*.rb \
# ext/socket/lib/**/*.rb \
# ext/stringio/*.c \
# ext/zlib/*.c
self.version = '2.0.0'
self.dir = '/Users/Thibaut/DevDocs/Docs/RDoc/Ruby'
html_filters.replace 'rdoc/entries', 'ruby/entries'
options[:root_title] = 'Ruby Programming Language'
options[:skip] += %w(
fatal.html
unknown.html
Data.html
E2MM.html
English.html
Exception2MessageMapper.html
GServer.html
MakeMakefile.html
ParallelEach.html
Requirement.html
YAML/DBM.html)
options[:skip_patterns] = [
/\AComplex/,
/\AGem/,
/\AHttpServer/,
/\AIRB/,
/\AMiniTest/i,
/\ANQXML/,
/\AOpenSSL/,
/\APride/,
/\ARacc/,
/\ARake/,
/\ARbConfig/,
/\ARDoc/,
/\AREXML/,
/\ARSS/,
/\ATest/,
/\AWEBrick/,
/\AXML/,
/\AXMP/
]
options[:attribution] = <<-HTML
Ruby Core &copy; 1993&ndash;2013 Yukihiro Matsumoto<br>
Licensed under the Ruby License.<br>
Ruby Standard Library &copy; contributors<br>
Licensed under their own licenses.
HTML
end
end

Binary file not shown.

After

Width:  |  Height:  |  Size: 906 B

Binary file not shown.

After

Width:  |  Height:  |  Size: 2.5 KiB

@ -0,0 +1 @@
http://commons.wikimedia.org/wiki/File:Ruby_logo.svg
Loading…
Cancel
Save