History

Add RDoc scraper and Ruby documentation

Thibaut committed 12 years ago

Commit 30931041 parent f5eb54717 files · +337 −-3Browse files

Unified · Split

17 files
  1. assets/images/icons.png +0 −0
  2. assets/images/icons@2x.png +0 −0
  3. assets/javascripts/templates/pages/about_tmpl.coffee +5 −0
  4. assets/javascripts/templates/pages/news_tmpl.coffee +4 −1
  5. assets/javascripts/views/pages/rdoc.coffee +20 −0
  6. assets/stylesheets/application.css.scss +1 −0
  7. assets/stylesheets/global/_icons.scss +1 −0
  8. assets/stylesheets/pages/_rdoc.scss +46 −0
  9. lib/docs/filters/rdoc/clean_html.rb +49 −0
  10. lib/docs/filters/rdoc/container.rb +26 −0
  11. lib/docs/filters/rdoc/entries.rb +38 −0
  12. lib/docs/filters/ruby/entries.rb +52 −0
  13. lib/docs/scrapers/rdoc/rdoc.rb +13 −0
  14. lib/docs/scrapers/rdoc/ruby.rb +85 −0
  15. public/icons/docs/ruby/16.png +0 −0
  16. public/icons/docs/ruby/16@2x.png +0 −0
  17. public/icons/docs/ruby/SOURCE +1 −0
assets/images/icons.png+0−0

Binary file not shown.

assets/images/icons@2x.png+0−0

Binary file not shown.

assets/javascripts/templates/pages/about_tmpl.coffee+5−0
@@ -138,6 +138,11 @@ credits = [ · 137 unmodified lines
138138 '1997-2013 The PHP Documentation Group',
139139 'CC BY',
140140 'http://creativecommons.org/licenses/by/3.0/'
141+ ], [
142+ 'Ruby',
143+ '1993-2013 Yukihiro Matsumoto',
144+ 'Ruby',
145+ 'https://www.ruby-lang.org/en/about/license.txt'
141146 ], [
142147 'Sass',
143148 '2006-2013 Hampton Catlin, Nathan Weizenbaum, and Chris Eppstein',
assets/javascripts/templates/pages/news_tmpl.coffee+4−1
@@ -24,7 +24,10 @@ newsItem = (date, news) -> · 23 unmodified lines
2424 result
2525
2626 app.news = [
27− [ 1382572800000, # October 24, 2013
27+ [ 1384560000000, # November 16, 2013
28+ """ New <a href="/ruby/">Ruby</a> documentation """
29+ ], [
30+ 1382572800000, # October 24, 2013
2831 """ DevDocs is now <a href="https://github.com/Thibaut/devdocs">open source</a>. """
2932 ], [
3033 1381276800000, # October 9, 2013
assets/javascripts/views/pages/rdoc.coffee+20−0
@@ -0,0 +1,20 @@
1+#= require views/pages/base
2+
3+class app.views.RdocPage extends app.views.BasePage
4+ @events:
5+ click: 'onClick'
6+
7+ afterRender: ->
8+ @highlightCode @findAll('pre.ruby'), 'ruby'
9+ @highlightCode @findAll('pre.c'), 'clike'
10+ return
11+
12+ onClick: (event) ->
13+ return unless event.target.classList.contains 'method-click-advice'
14+ $.stopEvent(event)
15+
16+ source = $ '.method-source-code', event.target.parentNode.parentNode
17+ isShown = source.style.display is 'block'
18+
19+ source.style.display = if isShown then 'none' else 'block'
20+ event.target.textContent = if isShown then 'Show source' else 'Hide source'
assets/stylesheets/application.css.scss+1−0
@@ -36,6 +36,7 @@ · 35 unmodified lines
3636 'pages/mdn',
3737 'pages/node',
3838 'pages/php',
39+ 'pages/rdoc',
3940 'pages/rfc',
4041 'pages/underscore',
4142 'pages/yard';
assets/stylesheets/global/_icons.scss+1−0
@@ -39,3 +39,4 @@ · 38 unmodified lines
3939 ._icon-jquerymobile:before { background-position: 0 -5rem; }
4040 ._icon-lodash:before { background-position: -1rem -5rem; }
4141 ._icon-php:before { background-position: -2rem -5rem; }
42+._icon-ruby:before { background-position: -3rem -5rem; }
assets/stylesheets/pages/_rdoc.scss+46−0
@@ -0,0 +1,46 @@
1+._rdoc {
2+ > .description, > .documentation-section { padding-left: 1rem; }
3+ > .description > h2, .section-header { @extend %block-heading; }
4+ > .description > h2, .section-header, .method-heading { margin-left: -1rem; }
5+ .description > h1 { font-size: 1rem; }
6+ .method-description > h2, h3, h4 { font-size: 1em; }
7+
8+ .method-heading {
9+ font-weight: bold;
10+ @extend %block-label, %label-blue;
11+
12+ + .method-heading { margin-top: -.5em; }
13+ }
14+
15+ > .meta {
16+ @extend %note, %note-blue;
17+
18+ > dd { margin: 0; }
19+ > dd + dt { margin-top: .5em; }
20+ }
21+
22+ a.method-click-advice {
23+ float: right;
24+ font-size: .75rem;
25+ color: $linkColor;
26+ cursor: pointer;
27+ @extend %user-select-none;
28+
29+ &:hover { text-decoration: underline; }
30+ }
31+
32+ .method-description { position: relative; }
33+
34+ .method-source-code {
35+ display: none;
36+ position: absolute;
37+ z-index: 1;
38+ top: 0;
39+ left: -1em;
40+ right: 0;
41+ background: rgba(white, .95);
42+ box-shadow: 0 1em 1em 1em white;
43+
44+ > pre { margin: 0; }
45+ }
46+}
lib/docs/filters/rdoc/clean_html.rb+49−0
@@ -0,0 +1,49 @@
1+module Docs
2+ class Rdoc
3+ class CleanHtmlFilter < Filter
4+ def call
5+ root_page? ? root : other
6+ doc
7+ end
8+
9+ def root
10+ at_css('.section-header').remove
11+
12+ # Remove skipped items
13+ css('li > span').each do |node|
14+ node.parent.remove
15+ end
16+ end
17+
18+ def other
19+ css('hr').remove
20+
21+ # Remove paragraph/up links
22+ css('h1 > span', 'h2 > span', 'h3 > span', 'h4 > span').remove
23+
24+ # Move id attributes to headings
25+ css('.method-detail').each do |node|
26+ next unless heading = node.at_css('.method-heading')
27+ heading['id'] = node['id']
28+ node.remove_attribute 'id'
29+ end
30+
31+ # Convert "click to toggle source" into a link
32+ css('.method-click-advice').each do |node|
33+ node.name = 'a'
34+ node.content = 'Show source'
35+ end
36+
37+ # Add class to differentiate Ruby code from C code
38+ css('.method-source-code > pre').each do |node|
39+ node['class'] = node.at_css('.ruby-keyword') ? 'ruby' : 'c'
40+ end
41+
42+ # Remove code highlighting
43+ css('pre').each do |node|
44+ node.content = node.content
45+ end
46+ end
47+ end
48+ end
49+end
lib/docs/filters/rdoc/container.rb+26−0
@@ -0,0 +1,26 @@
1+module Docs
2+ class Rdoc
3+ class ContainerFilter < Filter
4+ def call
5+ if root_page?
6+ at_css '#classindex-section'
7+ else
8+ container = at_css '#documentation'
9+
10+ # Add <dl> mentioning parent class and included modules
11+ meta = Nokogiri::XML::Node.new 'dl', doc
12+ meta['class'] = 'meta'
13+ if parent = at_css('#parent-class-section')
14+ meta << %(<dt>Parent:</dt><dd class="meta-parent">#{parent.at_css('.link').inner_html}</dd>)
15+ end
16+ if includes = at_css('#includes-section')
17+ meta << %(<dt>Included modules:</dt><dd class="meta-includes">#{includes.css('a').map(&:to_html).join(', ')}</dd>)
18+ end
19+ container.at_css('h1').after(meta)
20+
21+ container
22+ end
23+ end
24+ end
25+ end
26+end
lib/docs/filters/rdoc/entries.rb+38−0
@@ -0,0 +1,38 @@
1+module Docs
2+ class Rdoc
3+ class EntriesFilter < Docs::EntriesFilter
4+ def get_name
5+ name = at_css('h1').content.strip
6+ name.sub! 'class ', ''
7+ name.sub! 'module ', ''
8+ name
9+ end
10+
11+ def get_type
12+ type = name.dup
13+
14+ unless type.sub! %r{::.*\z}, ''
15+ parent = at_css('.meta-parent').try(:content).to_s.strip
16+ return 'Errors' if type.end_with?('Error') || parent.end_with?('Error') || parent.end_with?('Exception')
17+ end
18+
19+ type
20+ end
21+
22+ def additional_entries
23+ return [] if root_page?
24+ require 'cgi'
25+
26+ css('.method-detail').map do |node|
27+ name = node['id'].dup
28+ name.sub! %r{\A\w+?\-.}, ''
29+ name.sub! %r{\A-(?!\d)}, ''
30+ name.gsub! '-', '%'
31+ name = CGI.unescape(name)
32+ name.prepend self.name + (node['id'] =~ /\A\w+-c-/ ? '::' : '#')
33+ [name, node['id']]
34+ end
35+ end
36+ end
37+ end
38+end
lib/docs/filters/ruby/entries.rb+52−0
@@ -0,0 +1,52 @@
1+module Docs
2+ class Ruby
3+ class EntriesFilter < Docs::Rdoc::EntriesFilter
4+ REPLACE_TYPE = {
5+ 'ACL' => 'DRb',
6+ 'Addrinfo' => 'Socket',
7+ 'BigMath' => 'BigDecimal',
8+ 'CMath' => 'Math',
9+ 'ConditionVariable' => 'Mutex',
10+ 'DEBUGGER__' => 'Debug',
11+ 'Errno' => 'Errors',
12+ 'FileTest' => 'File',
13+ 'Jacobian' => 'BigDecimal',
14+ 'LUSolve' => 'BigDecimal',
15+ 'Newton' => 'BigDecimal',
16+ 'PP' => 'PrettyPrint',
17+ 'Profiler__' => 'Profiler',
18+ 'Psych' => 'YAML',
19+ 'Rinda' => 'DRb',
20+ 'SortedSet' => 'Set',
21+ 'TCPServer' => 'Socket',
22+ 'TempIO' => 'Tempfile',
23+ 'ThWait' => 'Thread',
24+ 'UNIXServer' => 'Socket' }
25+
26+ REPLACE_TYPE_STARTS_WITH = {
27+ 'Monitor' => 'Monitor',
28+ 'Mutex' => 'Mutex',
29+ 'Shell' => 'Shell',
30+ 'Sync' => 'Sync',
31+ 'Thread' => 'Thread' }
32+
33+ REPLACE_TYPE_ENDS_WITH = {
34+ 'Queue' => 'Queue',
35+ 'Socket' => 'Socket' }
36+
37+ def get_type
38+ type = super
39+
40+ REPLACE_TYPE_STARTS_WITH.each_pair do |key, value|
41+ return value if type.start_with?(key)
42+ end
43+
44+ REPLACE_TYPE_ENDS_WITH.each_pair do |key, value|
45+ return value if type.end_with?(key)
46+ end
47+
48+ REPLACE_TYPE[type] || type
49+ end
50+ end
51+ end
52+end
lib/docs/scrapers/rdoc/rdoc.rb+13−0
@@ -0,0 +1,13 @@
1+module Docs
2+ class Rdoc < FileScraper
3+ self.abstract = true
4+ self.type = 'rdoc'
5+ self.root_path = 'index.html'
6+
7+ html_filters.replace 'container', 'rdoc/container'
8+ html_filters.push 'rdoc/entries', 'rdoc/clean_html', 'title'
9+
10+ options[:title] = false
11+ options[:skip] = %w(table_of_contents.html)
12+ end
13+end
lib/docs/scrapers/rdoc/ruby.rb+85−0
@@ -0,0 +1,85 @@
1+module Docs
2+ class Ruby < Rdoc
3+ # Generated with:
4+ # rdoc \
5+ # --format=darkfish \
6+ # --no-line-numbers \
7+ # --op=rdoc \
8+ # --visibility=public \
9+ # *.c \
10+ # lib/**/*.rb \
11+ # lib/*.rb \
12+ # ext/bigdecimal/*.c \
13+ # ext/bigdecimal/lib/*.rb \
14+ # ext/bigdecimal/lib/**/*.rb \
15+ # ext/date/*.c \
16+ # ext/date/lib/*.rb \
17+ # ext/date/lib/**/*.rb \
18+ # ext/digest/*.c \
19+ # ext/digest/**/*.c \
20+ # ext/digest/**/*.rb \
21+ # ext/json/lib/**/*.rb \
22+ # ext/pathname/*.c \
23+ # ext/pathname/lib/*.rb \
24+ # ext/psych/*.c \
25+ # ext/psych/lib/*.rb \
26+ # ext/psych/lib/**/*.rb \
27+ # ext/readline/*.c \
28+ # ext/ripper/*.c \
29+ # ext/ripper/lib/*.rb \
30+ # ext/ripper/lib/**/*.rb \
31+ # ext/socket/*.c \
32+ # ext/socket/lib/*.rb \
33+ # ext/socket/lib/**/*.rb \
34+ # ext/stringio/*.c \
35+ # ext/zlib/*.c
36+
37+ self.version = '2.0.0'
38+ self.dir = '/Users/Thibaut/DevDocs/Docs/RDoc/Ruby'
39+
40+ html_filters.replace 'rdoc/entries', 'ruby/entries'
41+
42+ options[:root_title] = 'Ruby Programming Language'
43+
44+ options[:skip] += %w(
45+ fatal.html
46+ unknown.html
47+ Data.html
48+ E2MM.html
49+ English.html
50+ Exception2MessageMapper.html
51+ GServer.html
52+ MakeMakefile.html
53+ ParallelEach.html
54+ Requirement.html
55+ YAML/DBM.html)
56+
57+ options[:skip_patterns] = [
58+ /\AComplex/,
59+ /\AGem/,
60+ /\AHttpServer/,
61+ /\AIRB/,
62+ /\AMiniTest/i,
63+ /\ANQXML/,
64+ /\AOpenSSL/,
65+ /\APride/,
66+ /\ARacc/,
67+ /\ARake/,
68+ /\ARbConfig/,
69+ /\ARDoc/,
70+ /\AREXML/,
71+ /\ARSS/,
72+ /\ATest/,
73+ /\AWEBrick/,
74+ /\AXML/,
75+ /\AXMP/
76+ ]
77+
78+ options[:attribution] = <<-HTML
79+ Ruby Core &copy; 1993&ndash;2013 Yukihiro Matsumoto<br>
80+ Licensed under the Ruby License.<br>
81+ Ruby Standard Library &copy; contributors<br>
82+ Licensed under their own licenses.
83+ HTML
84+ end
85+end
public/icons/docs/ruby/16.png+0−0

Binary file not shown.

public/icons/docs/ruby/16@2x.png+0−0

Binary file not shown.

public/icons/docs/ruby/SOURCE+1−0
@@ -0,0 +1 @@
1+http://commons.wikimedia.org/wiki/File:Ruby_logo.svg