diff --git a/assets/stylesheets/application-dark.css.scss b/assets/stylesheets/application-dark.css.scss index d480f720..3c407b58 100644 --- a/assets/stylesheets/application-dark.css.scss +++ b/assets/stylesheets/application-dark.css.scss @@ -85,6 +85,7 @@ 'pages/rfc', 'pages/rubydoc', 'pages/rust', + 'pages/scala', 'pages/sinon', 'pages/socketio', 'pages/sphinx', diff --git a/assets/stylesheets/application.css.scss b/assets/stylesheets/application.css.scss index 4fdc2a14..0b5a71ee 100644 --- a/assets/stylesheets/application.css.scss +++ b/assets/stylesheets/application.css.scss @@ -85,6 +85,7 @@ 'pages/rfc', 'pages/rubydoc', 'pages/rust', + 'pages/scala', 'pages/sinon', 'pages/socketio', 'pages/sphinx', diff --git a/assets/stylesheets/pages/_scala.scss b/assets/stylesheets/pages/_scala.scss new file mode 100644 index 00000000..b2beb118 --- /dev/null +++ b/assets/stylesheets/pages/_scala.scss @@ -0,0 +1,4 @@ +._scala { + @extend %simple; + .deprecated { @extend %label-red; } +} diff --git a/lib/docs/filters/scala/clean_html.rb b/lib/docs/filters/scala/clean_html.rb new file mode 100644 index 00000000..95097c80 --- /dev/null +++ b/lib/docs/filters/scala/clean_html.rb @@ -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| +

#{signature.inner_html}

+ | + + 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|#{kind}| 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}| + end + end + end +end diff --git a/lib/docs/filters/scala/clean_html_210.rb b/lib/docs/filters/scala/clean_html_210.rb new file mode 100644 index 00000000..3160f103 --- /dev/null +++ b/lib/docs/filters/scala/clean_html_210.rb @@ -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 ? "

#{other.to_html}

" : '' + + definition.replace %Q| +

#{type} #{package}#{name}

+ #{other_content} + | + end if definition + + doc + end + + private + + def change_tag!(new_tag, node) + node.replace %Q|<#{new_tag}>#{node.inner_html}| + end + end + end +end diff --git a/lib/docs/filters/scala/clean_html_212.rb b/lib/docs/filters/scala/clean_html_212.rb new file mode 100644 index 00000000..7b4b1fe2 --- /dev/null +++ b/lib/docs/filters/scala/clean_html_212.rb @@ -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 ? "

#{other.to_html}

" : '' + + definition.replace %Q| +

#{type} #{package}#{name}

+ #{other_content} + | + + end if definition + + doc + end + + private + + def change_tag!(new_tag, node) + node.replace %Q|<#{new_tag}>#{node.inner_html}| + end + end + end +end diff --git a/lib/docs/filters/scala/entries.rb b/lib/docs/filters/scala/entries.rb new file mode 100644 index 00000000..d328764c --- /dev/null +++ b/lib/docs/filters/scala/entries.rb @@ -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 diff --git a/lib/docs/scrapers/scala.rb b/lib/docs/scrapers/scala.rb new file mode 100644 index 00000000..6b6d6bb2 --- /dev/null +++ b/lib/docs/scrapers/scala.rb @@ -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 EPFL, with contributions from Lightbend. + 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 EPFL, with contributions from Lightbend. + 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 EPFL, with contributions from Lightbend. + 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 EPFL, with contributions from Lightbend. + 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 EPFL, with contributions from Typesafe. + HTML + html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_210' + end + end +end diff --git a/public/icons/docs/scala/16.png b/public/icons/docs/scala/16.png new file mode 100644 index 00000000..429ed7df Binary files /dev/null and b/public/icons/docs/scala/16.png differ diff --git a/public/icons/docs/scala/16@2x.png b/public/icons/docs/scala/16@2x.png new file mode 100644 index 00000000..bb92e2d3 Binary files /dev/null and b/public/icons/docs/scala/16@2x.png differ