mirror of
https://github.com/freeCodeCamp/devdocs
synced 2024-11-16 19:48:10 +01:00
Adds scala documentation
This commit is contained in:
parent
8e2a918df0
commit
2f9608662f
10 changed files with 318 additions and 0 deletions
|
@ -85,6 +85,7 @@
|
|||
'pages/rfc',
|
||||
'pages/rubydoc',
|
||||
'pages/rust',
|
||||
'pages/scala',
|
||||
'pages/sinon',
|
||||
'pages/socketio',
|
||||
'pages/sphinx',
|
||||
|
|
|
@ -85,6 +85,7 @@
|
|||
'pages/rfc',
|
||||
'pages/rubydoc',
|
||||
'pages/rust',
|
||||
'pages/scala',
|
||||
'pages/sinon',
|
||||
'pages/socketio',
|
||||
'pages/sphinx',
|
||||
|
|
4
assets/stylesheets/pages/_scala.scss
Normal file
4
assets/stylesheets/pages/_scala.scss
Normal file
|
@ -0,0 +1,4 @@
|
|||
._scala {
|
||||
@extend %simple;
|
||||
.deprecated { @extend %label-red; }
|
||||
}
|
99
lib/docs/filters/scala/clean_html.rb
Normal file
99
lib/docs/filters/scala/clean_html.rb
Normal file
|
@ -0,0 +1,99 @@
|
|||
module Docs
|
||||
class Scala
|
||||
class CleanHtmlFilter < Filter
|
||||
def call
|
||||
always
|
||||
|
||||
if slug == 'index'
|
||||
root
|
||||
else
|
||||
other
|
||||
end
|
||||
end
|
||||
|
||||
def always
|
||||
# remove deprecated sections
|
||||
css('.members').each do |members|
|
||||
header = members.at_css('h3')
|
||||
members.remove if header.text.downcase.include? 'deprecate'
|
||||
end
|
||||
# Some of this is just for 2.12
|
||||
# These are things that provide interactive features, which are not supported yet.
|
||||
css('#subpackage-spacer, #search, #mbrsel, .diagram-btn').remove
|
||||
css('#footer').remove
|
||||
css('.toggleContainer').remove
|
||||
|
||||
signature = at_css('#signature')
|
||||
signature.replace %Q|
|
||||
<h2 id="signature">#{signature.inner_html}</h2>
|
||||
|
|
||||
|
||||
css('div.members > h3').each do |node|
|
||||
change_tag! 'h2', node
|
||||
end
|
||||
|
||||
css('div.members > ol').each do |list|
|
||||
list.css('li').each do |li|
|
||||
h3 = doc.document.create_element 'h3'
|
||||
li.prepend_child h3
|
||||
li.css('.shortcomment').remove
|
||||
modifier = li.at_css('.modifier_kind')
|
||||
modifier.parent = h3 if modifier
|
||||
symbol = li.at_css('.symbol')
|
||||
symbol.parent = h3 if symbol
|
||||
li.swap li.children
|
||||
end
|
||||
list.swap list.children
|
||||
end
|
||||
|
||||
pres = css('.fullcomment pre, .fullcommenttop pre')
|
||||
pres.each do |pre|
|
||||
pre['data-language'] = 'scala'
|
||||
end
|
||||
pres.add_class 'language-scala'
|
||||
|
||||
|
||||
|
||||
doc
|
||||
|
||||
end
|
||||
|
||||
def root
|
||||
css('#filter').remove # these are filters to search through the types and packages
|
||||
css('#library').remove # these are icons at the top
|
||||
doc
|
||||
end
|
||||
|
||||
def other
|
||||
# these are sections of the documentation which do not seem useful
|
||||
%w(#inheritedMembers #groupedMembers .permalink .hiddenContent .material-icons).each do |selector|
|
||||
css(selector).remove
|
||||
end
|
||||
|
||||
# This is the kind of thing we have, class, object, trait
|
||||
kind = at_css('.modifier_kind .kind').content
|
||||
# this image replacement doesn't do anything on 2.12 docs
|
||||
img = at_css('img')
|
||||
img.replace %Q|<span class="img_kind">#{kind}</span>| unless img.nil?
|
||||
class_to_add = kind == 'object' ? 'value': 'type'
|
||||
|
||||
# for 2.10, 2.11, the kind class is associated to the body. we have to
|
||||
# add it somewhere, so we do that with the #definition.
|
||||
definition = css('#definition')
|
||||
definition.css('.big_circle').remove
|
||||
definition.add_class class_to_add
|
||||
|
||||
# this is something that is not shown on the site, such as deprecated members
|
||||
css('li[visbl=prt]').remove
|
||||
|
||||
doc
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def change_tag!(new_tag, node)
|
||||
node.replace %Q|<#{new_tag}>#{node.inner_html}</#{new_tag}>|
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
32
lib/docs/filters/scala/clean_html_210.rb
Normal file
32
lib/docs/filters/scala/clean_html_210.rb
Normal file
|
@ -0,0 +1,32 @@
|
|||
module Docs
|
||||
class Scala
|
||||
class CleanHtml210Filter < Filter
|
||||
def call
|
||||
definition = at_css('#definition')
|
||||
begin
|
||||
type = definition.at_css('.img_kind').text
|
||||
name = definition.at_css('h1').text.strip
|
||||
|
||||
package = definition.at_css('#owner').text rescue ''
|
||||
package = package + '.' unless name.empty? || name.start_with?('root')
|
||||
|
||||
other = definition.at_css('.morelinks').dup
|
||||
other_content = other ? "<h3>#{other.to_html}</h3>" : ''
|
||||
|
||||
definition.replace %Q|
|
||||
<h1><small>#{type} #{package}</small>#{name}</h1>
|
||||
#{other_content}
|
||||
|
|
||||
end if definition
|
||||
|
||||
doc
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def change_tag!(new_tag, node)
|
||||
node.replace %Q|<#{new_tag}>#{node.inner_html}</#{new_tag}>|
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
36
lib/docs/filters/scala/clean_html_212.rb
Normal file
36
lib/docs/filters/scala/clean_html_212.rb
Normal file
|
@ -0,0 +1,36 @@
|
|||
module Docs
|
||||
class Scala
|
||||
class CleanHtml212Filter < Filter
|
||||
def call
|
||||
css('.permalink').remove
|
||||
|
||||
definition = at_css('#definition')
|
||||
begin
|
||||
type_full_name = {c: 'class', t: 'trait', o: 'object', 'p': 'package'}
|
||||
type = type_full_name[definition.at_css('.big-circle').text.to_sym]
|
||||
name = definition.at_css('h1').text
|
||||
|
||||
package = definition.at_css('#owner').text rescue ''
|
||||
package = package + '.' unless name.empty? || package.empty?
|
||||
|
||||
other = definition.at_css('.morelinks').dup
|
||||
other_content = other ? "<h3>#{other.to_html}</h3>" : ''
|
||||
|
||||
definition.replace %Q|
|
||||
<h1><small>#{type} #{package}</small>#{name}</h1>
|
||||
#{other_content}
|
||||
|
|
||||
|
||||
end if definition
|
||||
|
||||
doc
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def change_tag!(new_tag, node)
|
||||
node.replace %Q|<#{new_tag}>#{node.inner_html}</#{new_tag}>|
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
65
lib/docs/filters/scala/entries.rb
Normal file
65
lib/docs/filters/scala/entries.rb
Normal file
|
@ -0,0 +1,65 @@
|
|||
module Docs
|
||||
class Scala
|
||||
class EntriesFilter < Docs::EntriesFilter
|
||||
def get_name
|
||||
# this first condition is mainly for scala 212 docs, which
|
||||
# have their package listing as index.html
|
||||
if is_package?
|
||||
symbol = at_css('#definition h1')
|
||||
symbol ? symbol.text.gsub(/\W+/, '') : "package"
|
||||
else
|
||||
slug.split('/').last
|
||||
end
|
||||
end
|
||||
|
||||
def get_type
|
||||
# if this entry is for a package, we group the package under the parent package
|
||||
if is_package?
|
||||
parent_package
|
||||
# otherwise, group it under the regular package name
|
||||
else
|
||||
package_name
|
||||
end
|
||||
end
|
||||
|
||||
def include_default_entry?
|
||||
true
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
# For the package name, we use the slug rather than parsing the package
|
||||
# name from the HTML because companion object classes may be broken out into
|
||||
# their own entries (by the source documentation). When that happens,
|
||||
# we want to group these classes (like `scala.reflect.api.Annotations.Annotation`)
|
||||
# under the package name, and not the fully-qualfied name which would
|
||||
# include the companion object.
|
||||
def package_name
|
||||
name = package_drop_last(slug_parts)
|
||||
name.empty? ? '_root_' : name
|
||||
end
|
||||
|
||||
def parent_package
|
||||
name = package_name
|
||||
parent = package_drop_last(package_name.split('.'))
|
||||
parent.empty? ? '_root_' : parent
|
||||
end
|
||||
|
||||
def package_drop_last(parts)
|
||||
parts[0...-1].join('.')
|
||||
end
|
||||
|
||||
def slug_parts
|
||||
slug.split('/')
|
||||
end
|
||||
|
||||
def owner
|
||||
at_css('#owner')
|
||||
end
|
||||
|
||||
def is_package?
|
||||
slug.ends_with?('index') || slug.ends_with?('package')
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
80
lib/docs/scrapers/scala.rb
Normal file
80
lib/docs/scrapers/scala.rb
Normal file
|
@ -0,0 +1,80 @@
|
|||
module Docs
|
||||
class Scala < FileScraper
|
||||
include FixInternalUrlsBehavior
|
||||
|
||||
self.name = 'scala'
|
||||
self.type = 'scala'
|
||||
self.links = {
|
||||
home: 'http://www.scala-lang.org/',
|
||||
code: 'https://github.com/scala/scala'
|
||||
}
|
||||
|
||||
version '2.12 Library' do
|
||||
self.release = '2.12.3'
|
||||
self.dir = '/Users/Thibaut/DevDocs/Docs/Scala212/api/scala-library' # https://downloads.lightbend.com/scala/2.12.3/scala-docs-2.12.3.zip
|
||||
self.base_url = 'http://www.scala-lang.org/api/2.12.3/'
|
||||
self.root_path = 'index.html'
|
||||
options[:attribution] = <<-HTML
|
||||
Scala programming documentation. Copyright (c) 2003-2017 <a
|
||||
href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
|
||||
href="http://www.lightbend.com" target="_blank">Lightbend</a>.
|
||||
HTML
|
||||
html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_212'
|
||||
end
|
||||
|
||||
version '2.12 Reflection' do
|
||||
self.release = '2.12.3'
|
||||
self.dir = '/Users/Thibaut/DevDocs/Docs/Scala212/api/scala-reflect' # https://downloads.lightbend.com/scala/2.12.3/scala-docs-2.12.3.zip
|
||||
self.base_url = 'http://www.scala-lang.org/api/2.12.3/scala-reflect/'
|
||||
self.root_path = 'index.html'
|
||||
options[:attribution] = <<-HTML
|
||||
Scala programming documentation. Copyright (c) 2003-2017 <a
|
||||
href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
|
||||
href="http://www.lightbend.com" target="_blank">Lightbend</a>.
|
||||
HTML
|
||||
html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_212'
|
||||
end
|
||||
|
||||
version '2.11 Library' do
|
||||
self.release = '2.11.8'
|
||||
self.dir = '/Users/Thibaut/DevDocs/Docs/Scala211/api/scala-library' # https://downloads.lightbend.com/scala/2.11.8/scala-docs-2.11.8.zip
|
||||
self.base_url = 'http://www.scala-lang.org/api/2.11.8/'
|
||||
self.root_path = 'package.html'
|
||||
options[:skip_patterns] = [/^index.html/, /index\/index-/]
|
||||
options[:attribution] = <<-HTML
|
||||
Scala programming documentation. Copyright (c) 2003-2016 <a
|
||||
href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
|
||||
href="http://www.lightbend.com" target="_blank">Lightbend</a>.
|
||||
HTML
|
||||
html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_210'
|
||||
end
|
||||
|
||||
version '2.11 Reflection' do
|
||||
self.release = '2.11.8'
|
||||
self.dir = '/Users/Thibaut/DevDocs/Docs/Scala211/api/scala-reflect' # https://downloads.lightbend.com/scala/2.11.8/scala-docs-2.11.8.zip
|
||||
self.base_url = 'http://www.scala-lang.org/api/2.11.8/scala-reflect/'
|
||||
self.root_path = 'package.html'
|
||||
options[:skip_patterns] = [/^index.html/, /index\/index-/]
|
||||
options[:attribution] = <<-HTML
|
||||
Scala programming documentation. Copyright (c) 2003-2016 <a
|
||||
href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
|
||||
href="http://www.lightbend.com" target="_blank">Lightbend</a>.
|
||||
HTML
|
||||
html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_210'
|
||||
end
|
||||
|
||||
version '2.10' do
|
||||
self.release = '2.10.6'
|
||||
self.dir = '/Users/Thibaut/DevDocs/Docs/Scala210' # https://downloads.lightbend.com/scala/2.10.6/scala-docs-2.10.6.zip
|
||||
self.base_url = 'http://www.scala-lang.org/api/2.10.6/'
|
||||
self.root_path = 'package.html'
|
||||
options[:skip_patterns] = [/^index.html/, /index\/index-/]
|
||||
options[:attribution] = <<-HTML
|
||||
Scala programming documentation. Copyright (c) 2003-2013 <a
|
||||
href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
|
||||
href="http://typesafe.com" target="_blank">Typesafe</a>.
|
||||
HTML
|
||||
html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_210'
|
||||
end
|
||||
end
|
||||
end
|
BIN
public/icons/docs/scala/16.png
Normal file
BIN
public/icons/docs/scala/16.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 944 B |
BIN
public/icons/docs/scala/16@2x.png
Normal file
BIN
public/icons/docs/scala/16@2x.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.8 KiB |
Loading…
Reference in a new issue