History

Update Kotlin documentation (1.6.0)

Simon Legner committed 4 years ago

Commit 1378b381 parent 2fa27c33 files · +38 −22Browse files

Unified · Split

3 files
  1. lib/docs/filters/kotlin/clean_html.rb +7 −1
  2. lib/docs/filters/kotlin/entries.rb +8 −7
  3. lib/docs/scrapers/kotlin.rb +23 −14
lib/docs/filters/kotlin/clean_html.rb+7−1
@@ -2,7 +2,6 @@ module Docs · 1 unmodified line
2 class Kotlin2 class Kotlin
3 class CleanHtmlFilter < Filter3 class CleanHtmlFilter < Filter
4 def call4 def call
5 @doc = at_css('.page-content')
6 subpath.start_with?('api') ? api_page : doc_page5 subpath.start_with?('api') ? api_page : doc_page
7 doc6 doc
8 end7 end
@@ -14,6 +13,13 @@ module Docs · 5 unmodified lines
14 node.parent.before(node.parent.content).remove13 node.parent.before(node.parent.content).remove
15 end14 end
16 15
16 css('div.code-block').each do |node|
17 node.name = 'pre'
18 node['data-language'] = node['data-lang']
19 node.content = node.content
20 # FIXME: newlines in code-block are lost because of <div>? (on https://kotlinlang.org/docs/typecasts.html for instance)
21 end
22
17 css('pre').each do |node|23 css('pre').each do |node|
18 node['data-language'] = 'kotlin' if node.at_css('code.language-kotlin')24 node['data-language'] = 'kotlin' if node.at_css('code.language-kotlin')
19 node['data-language'] = 'groovy' if node.at_css('code.language-groovy')25 node['data-language'] = 'groovy' if node.at_css('code.language-groovy')
lib/docs/filters/kotlin/entries.rb+8−7
@@ -6,25 +6,26 @@ module Docs · 5 unmodified lines
6 breadcrumbs[1..-1].join('.')6 breadcrumbs[1..-1].join('.')
7 else7 else
8 node = (at_css('h1') || at_css('h2'))8 node = (at_css('h1') || at_css('h2'))
9 return node.content unless node.nil?9 return [breadcrumbs[1..], [node.content]].flatten.join(': ') unless node.nil?
10 subpath[/\/([a-z0-9_-]+)\./][1..-2].titleize.sub('Faq', 'FAQ')
11 end10 end
12 end11 end
13 12
14 def get_type13 def get_type
15 if subpath.start_with?('api')14 if subpath.start_with?('api')
16 breadcrumbs[1]15 breadcrumbs[1]
17 elsif subpath.start_with?('docs/tutorials')16 else
18 'Tutorials'17 breadcrumbs[0]
19 elsif subpath.start_with?('docs/reference')
20 'Reference'
21 end18 end
22 end19 end
23 20
24 private21 private
25 22
26 def breadcrumbs23 def breadcrumbs
27 @breadcrumbs ||= css('.api-docs-breadcrumbs a').map(&:content).map(&:strip)24 if subpath.start_with?('api')
25 @breadcrumbs ||= css('.api-docs-breadcrumbs a').map(&:content).map(&:strip)
26 else
27 @breadcrumbs ||= doc.document.at_css('body')['data-breadcrumbs'].split('///')
28 end
28 end29 end
29 end30 end
30 end31 end
lib/docs/scrapers/kotlin.rb+23−14
@@ -1,7 +1,6 @@
1module Docs1module Docs
2 class Kotlin < UrlScraper2 class Kotlin < UrlScraper
3 self.type = 'kotlin'3 self.type = 'kotlin'
4 self.release = '1.4.10'
5 self.base_url = 'https://kotlinlang.org/'4 self.base_url = 'https://kotlinlang.org/'
6 self.root_path = 'api/latest/jvm/stdlib/index.html'5 self.root_path = 'api/latest/jvm/stdlib/index.html'
7 self.links = {6 self.links = {
@@ -11,9 +10,8 @@ module Docs · 3 unmodified lines
11 10
12 html_filters.push 'kotlin/entries', 'kotlin/clean_html'11 html_filters.push 'kotlin/entries', 'kotlin/clean_html'
13 12
14 options[:container] = '.global-content'13 options[:container] = 'article'
15 14 options[:only_patterns] = [/\Adocs\//, /\Aapi\/latest\/jvm\/stdlib\//]
16 options[:only_patterns] = [/\Adocs\/tutorials\//, /\Adocs\/reference\//, /\Aapi\/latest\/jvm\/stdlib\//]
17 options[:skip_patterns] = [/stdlib\/org\./]15 options[:skip_patterns] = [/stdlib\/org\./]
18 options[:skip] = %w(16 options[:skip] = %w(
19 api/latest/jvm/stdlib/alltypes/index.html17 api/latest/jvm/stdlib/alltypes/index.html
@@ -22,23 +20,34 @@ module Docs · 2 unmodified lines
22 docs/events.html20 docs/events.html
23 docs/resources.html21 docs/resources.html
24 docs/reference/grammar.html)22 docs/reference/grammar.html)
25 options[:replace_paths] = {23
26 'api/latest/jvm/stdlib/' => 'api/latest/jvm/stdlib/index.html',24 options[:fix_urls] = ->(url) do
27 'docs/reference/coroutines.html' => 'docs/reference/coroutines-overview.html',25 url.sub! %r{/docs/reference/}, '/docs/'
28 'api/latest/jvm/stdlib/kotlin/fold.html' => 'api/latest/jvm/stdlib/kotlin.collections/fold.html',26 url
29 'api/latest/jvm/stdlib/kotlin/get-or-else.html' => 'api/latest/jvm/stdlib/kotlin.collections/get-or-else.html',27 end
30 'api/latest/jvm/stdlib/kotlin/map.html' => 'api/latest/jvm/stdlib/kotlin.collections/map.html',
31 'docs/tutorials/native/targeting-multiple-platforms.html' => 'docs/tutorials/native/basic-kotlin-native-app.html',
32 'api/latest/jvm/stdlib/kotlin/-throwable/print-stack-trace.html' => 'api/latest/jvm/stdlib/kotlin/print-stack-trace.html',
33 }
34 28
35 options[:attribution] = <<-HTML29 options[:attribution] = <<-HTML
36 &copy; 2010&ndash;2020 JetBrains s.r.o. and Kotlin Programming Language contributors<br>30 &copy; 2010&ndash;2021 JetBrains s.r.o. and Kotlin Programming Language contributors<br>
37 Licensed under the Apache License, Version 2.0.31 Licensed under the Apache License, Version 2.0.
38 HTML32 HTML
39 33
34 version '1.6' do
35 self.release = '1.6.0'
36 end
37
38 version '1.4' do
39 self.release = '1.4.10'
40 end
41
40 def get_latest_version(opts)42 def get_latest_version(opts)
41 get_latest_github_release('JetBrains', 'kotlin', opts)43 get_latest_github_release('JetBrains', 'kotlin', opts)
42 end44 end
45
46 private
47
48 def process_response?(response)
49 return false unless super
50 response.body !~ /http-equiv="refresh"/i
51 end
43 end52 end
44end53end