Skip to content

Commit 4390a91

Browse files
committed
Update and improve Rails documentation
1 parent 712c55c commit 4390a91

File tree

7 files changed

+88
-7
lines changed

7 files changed

+88
-7
lines changed

assets/stylesheets/pages/_rdoc.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,4 +43,9 @@
4343

4444
> pre { margin: 0; }
4545
}
46+
47+
// Rails guides
48+
.note { @extend %note; }
49+
.info { @extend %note, %note-blue; }
50+
.warning { @extend %note, %note-red; }
4651
}

assets/stylesheets/pages/_simple.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
._nim,
4242
._redux,
4343
._requirejs,
44+
._simple,
4445
._typescript,
4546
._vagrant,
4647
._vulkan,
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
module Docs
2+
class Rails
3+
class CleanHtmlGuidesFilter < Filter
4+
def call
5+
return doc unless slug.start_with?('guides')
6+
7+
at_css('#mainCol').prepend_child at_css('#feature .wrapper').children
8+
@doc = at_css('#mainCol')
9+
10+
container = Nokogiri::XML::Node.new 'div', doc
11+
container['class'] = '_simple'
12+
container.children = doc.children
13+
doc << container
14+
15+
css('h2, h3, h4, h5, h6').each do |node|
16+
node.name = node.name.sub(/\d/) { |i| i.to_i - 1 }
17+
end
18+
19+
doc.prepend_child at_css('h1')
20+
21+
css('#subCol', '.code_container').each do |node|
22+
node.before(node.children).remove
23+
end
24+
25+
css('pre').each do |node|
26+
language = node['class'][/brush: ?(\w+)/, 1]
27+
node['data-language'] = language unless language == 'plain'
28+
node.remove_attribute('class')
29+
node.content = node.content.strip
30+
end
31+
32+
doc
33+
end
34+
end
35+
end
36+
end

lib/docs/filters/rails/entries.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,19 @@ class EntriesFilter < Docs::Rdoc::EntriesFilter
3838
'Rails::Generators' => 'Rails/Generators',
3939
'Rails::Railtie' => 'Rails/Railtie' }
4040

41+
def get_name
42+
if slug.start_with?('guides')
43+
name = at_css('#feature h2').content.strip
44+
name.remove! %r{\s\(.+\)\z}
45+
return name
46+
end
47+
48+
super
49+
end
50+
4151
def get_type
52+
return 'Guides' if slug.start_with?('guides')
53+
4254
parent = at_css('.meta-parent').try(:content).to_s
4355

4456
if [name, parent].any? { |str| str.end_with?('Error') || str.end_with?('Exception') }
@@ -57,10 +69,14 @@ def get_type
5769
end
5870

5971
def include_default_entry?
72+
return true if slug.start_with?('guides')
73+
6074
super && !skip?
6175
end
6276

6377
def additional_entries
78+
return [] if slug.start_with?('guides')
79+
6480
skip? ? [] : super
6581
end
6682

lib/docs/filters/rdoc/clean_html.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Docs
22
class Rdoc
33
class CleanHtmlFilter < Filter
44
def call
5+
return doc if context[:skip_rdoc_filters?].try(:call, self)
6+
57
root_page? ? root : other
68
doc
79
end

lib/docs/filters/rdoc/container.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ module Docs
22
class Rdoc
33
class ContainerFilter < Filter
44
def call
5+
return doc if context[:skip_rdoc_filters?].try(:call, self)
6+
57
if root_page?
68
at_css 'main'
79
else

lib/docs/scrapers/rdoc/rails.rb

Lines changed: 26 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5,16 +5,25 @@ class Rails < Rdoc
55
self.name = 'Ruby on Rails'
66
self.slug = 'rails'
77
self.dir = '/Users/Thibaut/DevDocs/Docs/RDoc/Rails'
8+
self.initial_paths = %w(guides/index.html)
89
self.links = {
910
home: 'http://rubyonrails.org/',
1011
code: 'https://github.com/rails/rails'
1112
}
1213

1314
html_filters.replace 'rdoc/entries', 'rails/entries'
15+
html_filters.push 'rails/clean_html_guides'
16+
17+
options[:skip_rdoc_filters?] = ->(filter) { filter.slug.start_with?('guides/') }
1418

1519
options[:root_title] = 'Ruby on Rails'
1620

1721
options[:skip] += %w(
22+
guides/credits.html
23+
guides/ruby_on_rails_guides_guidelines.html
24+
guides/contributing_to_ruby_on_rails.html
25+
guides/development_dependencies_install.html
26+
guides/api_documentation_guidelines.html
1827
ActionController/Instrumentation.html
1928
ActionController/Rendering.html
2029
ActionDispatch/DebugExceptions.html
@@ -30,6 +39,7 @@ class Rails < Rdoc
3039
ActiveSupport/Notifications/Fanout.html)
3140

3241
options[:skip_patterns] += [
42+
/release_notes/,
3343
/\AActionController\/Testing/,
3444
/\AActionView\/LookupContext/,
3545
/\AActionView\/Resolver/,
@@ -43,21 +53,30 @@ class Rails < Rdoc
4353
/\ARails\/PluginBuilder/,
4454
/\ARails\/Generators\/Testing/]
4555

46-
options[:attribution] = <<-HTML
47-
&copy; 2004&ndash;2017 David Heinemeier Hansson<br>
48-
Licensed under the MIT License.
49-
HTML
56+
options[:attribution] = ->(filter) do
57+
if filter.slug.start_with?('guides')
58+
<<-HTML
59+
&copy; 2004&ndash;2017 David Heinemeier Hansson<br>
60+
Licensed under the Creative Commons Attribution-ShareAlike 4.0 International License.
61+
HTML
62+
else
63+
<<-HTML
64+
&copy; 2004&ndash;2017 David Heinemeier Hansson<br>
65+
Licensed under the MIT License.
66+
HTML
67+
end
68+
end
5069

5170
version '5.1' do
52-
self.release = '5.1.0'
71+
self.release = '5.1.4'
5372
end
5473

5574
version '5.0' do
56-
self.release = '5.0.2'
75+
self.release = '5.0.6'
5776
end
5877

5978
version '4.2' do
60-
self.release = '4.2.8'
79+
self.release = '4.2.10'
6180
end
6281

6382
version '4.1' do

0 commit comments

Comments
 (0)