History

Adds scala documentation

Jamie Ly committed 9 years ago

Commit 2f960861 parent 8e2a91810 files · +316 −-2Browse files

Unified · Split

10 files
  1. assets/stylesheets/application-dark.css.scss +1 −0
  2. assets/stylesheets/application.css.scss +1 −0
  3. assets/stylesheets/pages/_scala.scss +4 −0
  4. lib/docs/filters/scala/clean_html.rb +99 −0
  5. lib/docs/filters/scala/clean_html_210.rb +32 −0
  6. lib/docs/filters/scala/clean_html_212.rb +36 −0
  7. lib/docs/filters/scala/entries.rb +65 −0
  8. lib/docs/scrapers/scala.rb +80 −0
  9. public/icons/docs/scala/16.png +0 −0
  10. public/icons/docs/scala/16@2x.png +0 −0
assets/stylesheets/application-dark.css.scss+1−0
@@ -85,6 +85,7 @@ · 84 unmodified lines
85 'pages/rfc',85 'pages/rfc',
86 'pages/rubydoc',86 'pages/rubydoc',
87 'pages/rust',87 'pages/rust',
88 'pages/scala',
88 'pages/sinon',89 'pages/sinon',
89 'pages/socketio',90 'pages/socketio',
90 'pages/sphinx',91 'pages/sphinx',
assets/stylesheets/application.css.scss+1−0
@@ -85,6 +85,7 @@ · 84 unmodified lines
85 'pages/rfc',85 'pages/rfc',
86 'pages/rubydoc',86 'pages/rubydoc',
87 'pages/rust',87 'pages/rust',
88 'pages/scala',
88 'pages/sinon',89 'pages/sinon',
89 'pages/socketio',90 'pages/socketio',
90 'pages/sphinx',91 'pages/sphinx',
assets/stylesheets/pages/_scala.scss+4−0
@@ -0,0 +1,4 @@
1._scala {
2 @extend %simple;
3 .deprecated { @extend %label-red; }
4}
lib/docs/filters/scala/clean_html.rb+99−0
@@ -0,0 +1,99 @@
1module Docs
2 class Scala
3 class CleanHtmlFilter < Filter
4 def call
5 always
6
7 if slug == 'index'
8 root
9 else
10 other
11 end
12 end
13
14 def always
15 # remove deprecated sections
16 css('.members').each do |members|
17 header = members.at_css('h3')
18 members.remove if header.text.downcase.include? 'deprecate'
19 end
20 # Some of this is just for 2.12
21 # These are things that provide interactive features, which are not supported yet.
22 css('#subpackage-spacer, #search, #mbrsel, .diagram-btn').remove
23 css('#footer').remove
24 css('.toggleContainer').remove
25
26 signature = at_css('#signature')
27 signature.replace %Q|
28 <h2 id="signature">#{signature.inner_html}</h2>
29 |
30
31 css('div.members > h3').each do |node|
32 change_tag! 'h2', node
33 end
34
35 css('div.members > ol').each do |list|
36 list.css('li').each do |li|
37 h3 = doc.document.create_element 'h3'
38 li.prepend_child h3
39 li.css('.shortcomment').remove
40 modifier = li.at_css('.modifier_kind')
41 modifier.parent = h3 if modifier
42 symbol = li.at_css('.symbol')
43 symbol.parent = h3 if symbol
44 li.swap li.children
45 end
46 list.swap list.children
47 end
48
49 pres = css('.fullcomment pre, .fullcommenttop pre')
50 pres.each do |pre|
51 pre['data-language'] = 'scala'
52 end
53 pres.add_class 'language-scala'
54
55
56
57 doc
58
59 end
60
61 def root
62 css('#filter').remove # these are filters to search through the types and packages
63 css('#library').remove # these are icons at the top
64 doc
65 end
66
67 def other
68 # these are sections of the documentation which do not seem useful
69 %w(#inheritedMembers #groupedMembers .permalink .hiddenContent .material-icons).each do |selector|
70 css(selector).remove
71 end
72
73 # This is the kind of thing we have, class, object, trait
74 kind = at_css('.modifier_kind .kind').content
75 # this image replacement doesn't do anything on 2.12 docs
76 img = at_css('img')
77 img.replace %Q|<span class="img_kind">#{kind}</span>| unless img.nil?
78 class_to_add = kind == 'object' ? 'value': 'type'
79
80 # for 2.10, 2.11, the kind class is associated to the body. we have to
81 # add it somewhere, so we do that with the #definition.
82 definition = css('#definition')
83 definition.css('.big_circle').remove
84 definition.add_class class_to_add
85
86 # this is something that is not shown on the site, such as deprecated members
87 css('li[visbl=prt]').remove
88
89 doc
90 end
91
92 private
93
94 def change_tag!(new_tag, node)
95 node.replace %Q|<#{new_tag}>#{node.inner_html}</#{new_tag}>|
96 end
97 end
98 end
99end
lib/docs/filters/scala/clean_html_210.rb+32−0
@@ -0,0 +1,32 @@
1module Docs
2 class Scala
3 class CleanHtml210Filter < Filter
4 def call
5 definition = at_css('#definition')
6 begin
7 type = definition.at_css('.img_kind').text
8 name = definition.at_css('h1').text.strip
9
10 package = definition.at_css('#owner').text rescue ''
11 package = package + '.' unless name.empty? || name.start_with?('root')
12
13 other = definition.at_css('.morelinks').dup
14 other_content = other ? "<h3>#{other.to_html}</h3>" : ''
15
16 definition.replace %Q|
17 <h1><small>#{type} #{package}</small>#{name}</h1>
18 #{other_content}
19 |
20 end if definition
21
22 doc
23 end
24
25 private
26
27 def change_tag!(new_tag, node)
28 node.replace %Q|<#{new_tag}>#{node.inner_html}</#{new_tag}>|
29 end
30 end
31 end
32end
lib/docs/filters/scala/clean_html_212.rb+36−0
@@ -0,0 +1,36 @@
1module Docs
2 class Scala
3 class CleanHtml212Filter < Filter
4 def call
5 css('.permalink').remove
6
7 definition = at_css('#definition')
8 begin
9 type_full_name = {c: 'class', t: 'trait', o: 'object', 'p': 'package'}
10 type = type_full_name[definition.at_css('.big-circle').text.to_sym]
11 name = definition.at_css('h1').text
12
13 package = definition.at_css('#owner').text rescue ''
14 package = package + '.' unless name.empty? || package.empty?
15
16 other = definition.at_css('.morelinks').dup
17 other_content = other ? "<h3>#{other.to_html}</h3>" : ''
18
19 definition.replace %Q|
20 <h1><small>#{type} #{package}</small>#{name}</h1>
21 #{other_content}
22 |
23
24 end if definition
25
26 doc
27 end
28
29 private
30
31 def change_tag!(new_tag, node)
32 node.replace %Q|<#{new_tag}>#{node.inner_html}</#{new_tag}>|
33 end
34 end
35 end
36end
lib/docs/filters/scala/entries.rb+65−0
@@ -0,0 +1,65 @@
1module Docs
2 class Scala
3 class EntriesFilter < Docs::EntriesFilter
4 def get_name
5 # this first condition is mainly for scala 212 docs, which
6 # have their package listing as index.html
7 if is_package?
8 symbol = at_css('#definition h1')
9 symbol ? symbol.text.gsub(/\W+/, '') : "package"
10 else
11 slug.split('/').last
12 end
13 end
14
15 def get_type
16 # if this entry is for a package, we group the package under the parent package
17 if is_package?
18 parent_package
19 # otherwise, group it under the regular package name
20 else
21 package_name
22 end
23 end
24
25 def include_default_entry?
26 true
27 end
28
29 private
30
31 # For the package name, we use the slug rather than parsing the package
32 # name from the HTML because companion object classes may be broken out into
33 # their own entries (by the source documentation). When that happens,
34 # we want to group these classes (like `scala.reflect.api.Annotations.Annotation`)
35 # under the package name, and not the fully-qualfied name which would
36 # include the companion object.
37 def package_name
38 name = package_drop_last(slug_parts)
39 name.empty? ? '_root_' : name
40 end
41
42 def parent_package
43 name = package_name
44 parent = package_drop_last(package_name.split('.'))
45 parent.empty? ? '_root_' : parent
46 end
47
48 def package_drop_last(parts)
49 parts[0...-1].join('.')
50 end
51
52 def slug_parts
53 slug.split('/')
54 end
55
56 def owner
57 at_css('#owner')
58 end
59
60 def is_package?
61 slug.ends_with?('index') || slug.ends_with?('package')
62 end
63 end
64 end
65end
lib/docs/scrapers/scala.rb+80−0
@@ -0,0 +1,80 @@
1module Docs
2 class Scala < FileScraper
3 include FixInternalUrlsBehavior
4
5 self.name = 'scala'
6 self.type = 'scala'
7 self.links = {
8 home: 'http://www.scala-lang.org/',
9 code: 'https://github.com/scala/scala'
10 }
11
12 version '2.12 Library' do
13 self.release = '2.12.3'
14 self.dir = '/Users/Thibaut/DevDocs/Docs/Scala212/api/scala-library' # https://downloads.lightbend.com/scala/2.12.3/scala-docs-2.12.3.zip
15 self.base_url = 'http://www.scala-lang.org/api/2.12.3/'
16 self.root_path = 'index.html'
17 options[:attribution] = <<-HTML
18 Scala programming documentation. Copyright (c) 2003-2017 <a
19 href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
20 href="http://www.lightbend.com" target="_blank">Lightbend</a>.
21 HTML
22 html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_212'
23 end
24
25 version '2.12 Reflection' do
26 self.release = '2.12.3'
27 self.dir = '/Users/Thibaut/DevDocs/Docs/Scala212/api/scala-reflect' # https://downloads.lightbend.com/scala/2.12.3/scala-docs-2.12.3.zip
28 self.base_url = 'http://www.scala-lang.org/api/2.12.3/scala-reflect/'
29 self.root_path = 'index.html'
30 options[:attribution] = <<-HTML
31 Scala programming documentation. Copyright (c) 2003-2017 <a
32 href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
33 href="http://www.lightbend.com" target="_blank">Lightbend</a>.
34 HTML
35 html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_212'
36 end
37
38 version '2.11 Library' do
39 self.release = '2.11.8'
40 self.dir = '/Users/Thibaut/DevDocs/Docs/Scala211/api/scala-library' # https://downloads.lightbend.com/scala/2.11.8/scala-docs-2.11.8.zip
41 self.base_url = 'http://www.scala-lang.org/api/2.11.8/'
42 self.root_path = 'package.html'
43 options[:skip_patterns] = [/^index.html/, /index\/index-/]
44 options[:attribution] = <<-HTML
45 Scala programming documentation. Copyright (c) 2003-2016 <a
46 href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
47 href="http://www.lightbend.com" target="_blank">Lightbend</a>.
48 HTML
49 html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_210'
50 end
51
52 version '2.11 Reflection' do
53 self.release = '2.11.8'
54 self.dir = '/Users/Thibaut/DevDocs/Docs/Scala211/api/scala-reflect' # https://downloads.lightbend.com/scala/2.11.8/scala-docs-2.11.8.zip
55 self.base_url = 'http://www.scala-lang.org/api/2.11.8/scala-reflect/'
56 self.root_path = 'package.html'
57 options[:skip_patterns] = [/^index.html/, /index\/index-/]
58 options[:attribution] = <<-HTML
59 Scala programming documentation. Copyright (c) 2003-2016 <a
60 href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
61 href="http://www.lightbend.com" target="_blank">Lightbend</a>.
62 HTML
63 html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_210'
64 end
65
66 version '2.10' do
67 self.release = '2.10.6'
68 self.dir = '/Users/Thibaut/DevDocs/Docs/Scala210' # https://downloads.lightbend.com/scala/2.10.6/scala-docs-2.10.6.zip
69 self.base_url = 'http://www.scala-lang.org/api/2.10.6/'
70 self.root_path = 'package.html'
71 options[:skip_patterns] = [/^index.html/, /index\/index-/]
72 options[:attribution] = <<-HTML
73 Scala programming documentation. Copyright (c) 2003-2013 <a
74 href="http://www.epfl.ch" target="_blank">EPFL</a>, with contributions from <a
75 href="http://typesafe.com" target="_blank">Typesafe</a>.
76 HTML
77 html_filters.push 'scala/entries', 'scala/clean_html', 'scala/clean_html_210'
78 end
79 end
80end
public/icons/docs/scala/16.png+0−0

Binary file not shown.

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

Binary file not shown.

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t