Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update Rails (from FileScraper to UrlScraper) #1580

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion assets/javascripts/templates/pages/about_tmpl.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -738,7 +738,7 @@ credits = [
'https://www.ruby-lang.org/en/about/license.txt'
], [
'Ruby on Rails',
'2004-2020 David Heinemeier Hansson<br>Rails, Ruby on Rails, and the Rails logo are trademarks of David Heinemeier Hansson.',
'2004-2021 David Heinemeier Hansson<br>Rails, Ruby on Rails, and the Rails logo are trademarks of David Heinemeier Hansson.',
'MIT',
'https://raw.githubusercontent.com/rails/rails/master/activerecord/MIT-LICENSE'
], [
Expand Down
1 change: 1 addition & 0 deletions assets/stylesheets/application.css.scss
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@
'pages/pygame',
'pages/python',
'pages/qt',
'pages/rails',
'pages/ramda',
'pages/rdoc',
'pages/react_native',
Expand Down
9 changes: 9 additions & 0 deletions assets/stylesheets/pages/_rails.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
._rails {
.title.method-title {
@extend %block-label, %label-blue;
}

h2 {
@extend %block-heading;
}
}
1 change: 0 additions & 1 deletion docs/file-scrapers.md
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,6 @@ done

### Nokogiri
### Ruby / Minitest
### Ruby on Rails
### Ruby
Download the tarball of Ruby from https://www.ruby-lang.org/en/downloads/, extract it, run
`./configure && make html` in your terminal (while your are in the ruby directory) and move
Expand Down
67 changes: 67 additions & 0 deletions lib/docs/filters/rails/clean_html.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
module Docs
class Rails
class CleanHtmlFilter < Filter
def call

if current_url.to_s.match?('guides')
css('img, textarea, button, .anchorlink').remove

at_css('#mainCol').prepend_child at_css('#feature .wrapper').children
@doc = at_css('#mainCol')

container = Nokogiri::XML::Node.new 'div', doc
container['class'] = '_rails'
container.children = doc.children
doc << container

css('h2, h3, h4, h5, h6').each do |node|
node.name = node.name.sub(/\d/) { |i| i.to_i - 1 }
end

doc.prepend_child at_css('h1')

if version == '6.1' || version == '6.0'
css('pre').each do |node|
code = node.at_css('code')
language = code['class'][/highlight ?(\w+)/, 1]
node['data-language'] = language unless language == 'plain'
code.remove_attribute('class')
node.content = node.content.strip
end
end

else
title = at_css('h2')
title.name = 'h1'

@doc = at_css('#content')
@doc.prepend_child(title)

css('table td').each do |node|
node.remove if node.content.empty?
end

css('.permalink').remove

css('.sectiontitle').each do |node|
node.name = 'h2'
end

css('pre').each do |node|
node['data-language'] = 'ruby'
end

# move 'source on github' to the end of the source code
css('.sourcecode').each do |node|
github_url = node.at_css('.github_url')
github_url.content = "Source on Github"
node.at_css('.source-link').content = 'Source:'
node.at_css('.dyn-source').after(github_url)
end
end

doc
end
end
end
end
37 changes: 0 additions & 37 deletions lib/docs/filters/rails/clean_html_guides.rb

This file was deleted.

94 changes: 25 additions & 69 deletions lib/docs/filters/rails/entries.rb
Original file line number Diff line number Diff line change
@@ -1,88 +1,44 @@
module Docs
class Rails
class EntriesFilter < Docs::Rdoc::EntriesFilter
TYPE_BY_NAME_MATCHES = {
/Assertions|::Test|Fixture/ => 'Testing',
/\AActiveRecord.+mysql/i => 'ActiveRecord/MySQL',
/\AActiveRecord.+postgresql/i => 'ActiveRecord/PostgreSQL',
/\AActiveRecord.+sqlite/i => 'ActiveRecord/SQLite',
/\AActiveRecord.+Assoc/ => 'ActiveRecord/Associations',
/\AActiveRecord.+Attribute/ => 'ActiveRecord/Attributes',
/\AActiveRecord.+ConnectionAdapters/ => 'ActiveRecord/Connection',
/\AActiveSupport.+(Subscriber|Notifications)/ => 'ActiveSupport/Instrumentation' }

TYPE_BY_NAME_STARTS_WITH = {
'ActionController::Parameters' => 'ActionController/Parameters',
'ActionDispatch::Integration' => 'Testing',
'ActionDispatch::Request' => 'ActionDispatch/Request',
'ActionDispatch::Response' => 'ActionDispatch/Response',
'ActionDispatch::Routing' => 'ActionDispatch/Routing',
'ActionView::Helpers' => 'ActionView/Helpers',
'ActiveModel::Errors' => 'ActiveModel/Validation',
'ActiveModel::Valid' => 'ActiveModel/Validation',
'ActiveRecord::Batches' => 'ActiveRecord/Query',
'ActiveRecord::Calculations' => 'ActiveRecord/Query',
'ActiveRecord::Connection' => 'ActiveRecord/Connection',
'ActiveRecord::FinderMethods' => 'ActiveRecord/Query',
'ActiveRecord::Migra' => 'ActiveRecord/Migration',
'ActiveRecord::Query' => 'ActiveRecord/Query',
'ActiveRecord::Relation' => 'ActiveRecord/Relation',
'ActiveRecord::Result' => 'ActiveRecord/Connection',
'ActiveRecord::Scoping' => 'ActiveRecord/Query',
'ActiveRecord::SpawnMethods' => 'ActiveRecord/Query',
'ActiveSupport::Cach' => 'ActiveSupport/Caching',
'ActiveSupport::Inflector' => 'ActiveSupport/Inflector',
'ActiveSupport::Time' => 'ActiveSupport/TimeZones',
'Rails::Application' => 'Rails/Application',
'Rails::Engine' => 'Rails/Engine',
'Rails::Generators' => 'Rails/Generators',
'Rails::Railtie' => 'Rails/Railtie' }

class EntriesFilter < Docs::EntriesFilter# Docs::Rdoc::EntriesFilter
def get_name
if slug.start_with?('guides')
name = at_css('#feature h2').content.strip
name.remove! %r{\s\(.+\)\z}
return name
if current_url.to_s.match?('guides')
at_css('h2').content
else
name = at_css('h2').to_html.scan(/<\/span>.*?</)[0]

if name.nil?
name = at_css('h2').content
else
name.sub!("<\/span>", '')
name.sub!('<', '')
end

name.strip
end

super
end

def get_type
return 'Guides' if slug.start_with?('guides')

parent = at_css('.meta-parent').try(:content).to_s

if [name, parent].any? { |str| str.end_with?('Error') || str.end_with?('Exception') }
return 'Errors'
end

TYPE_BY_NAME_MATCHES.each_pair do |key, value|
return value if name =~ key
end
return 'Guides' if current_url.to_s.match?('guides')
return 'Ruby files' if name =~ /.rb/

TYPE_BY_NAME_STARTS_WITH.each_pair do |key, value|
return value if name.start_with?(key)
end
name.split('::')[0]

super
end

def include_default_entry?
return true if slug.start_with?('guides')
def additional_entries
return [] if current_url.to_s.match?('guides')

super && !skip?
end
entries = []

def additional_entries
return [] if slug.start_with?('guides')
css('.title.method-title').each do |node|
entry_name = node.at_css('b').content
entries << [name+"##{entry_name}", node['id']]
end

skip? ? [] : super
entries
end

def skip?
@skip ||= !css('p').any? { |node| node.content.present? }
end
end
end
end
Loading